Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Adds system tests w/ travis and appveyor ci intergration
Browse files Browse the repository at this point in the history
  • Loading branch information
justin taft committed Nov 15, 2016
1 parent 830a4a3 commit 8fb6fc3
Show file tree
Hide file tree
Showing 26 changed files with 568 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/deploy/core/node_modules/lighttable/bootstrap.js*
.lein-deps-sum
.lein-env
.lein-failures
.lein-plugins/
.nrepl-port
/builds/
24 changes: 20 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
language: clojure
env:
- TRAVIS=1
os:
- linux
- osx
lein: lein
script: "! lein cljsbuild once 2>&1 | grep WARNING:"
jdk:
- oraclejdk8
env:
global:
GITHUB_OAUTH_READONLY_TOKEN: 9c40494099f5c56573b6438ff96dfddfb223cbcb
script:
- ./script/build.sh
- ./script/run-tests.sh
language: java
before_script:
- if [[ "${TRAVIS_OS_NAME}" = "linux" ]] ; then export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; sudo apt-get -qq update; sudo apt-get install -y leiningen; fi
- if [[ "${TRAVIS_OS_NAME}" = "osx" ]] ; then brew update; brew install leiningen; fi
notifications:
irc: "chat.freenode.net#lighttable"
email:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
addons:
apt:
packages:
- chromium-browser
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ LightTable is primarily written in [ClojureScript](http://clojure.org/clojurescr

In order to develop for Light Table, you will need to [install a developer version of Light Table](doc/developer-install.md). For more information, read [CONTRIBUTING.md](https://github.com/LightTable/LightTable/blob/master/CONTRIBUTING.md#code-contributions) and [For Developers](https://github.com/LightTable/LightTable/wiki/For-Developers).

To execute tests, run ```script/run-tests.sh```. This should be done after running ```script/build.sh```.

## License

Expand Down
52 changes: 52 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
environment:
global:
CYG_ROOT: C:\cygwin
CYG_MIRROR: http://cygwin.mirror.constant.com
CYG_CACHE: C:\cygwin\var\cache\setup
CYG_BASH: C:\cygwin\bin\bash
GITHUB_OAUTH_READONLY_TOKEN: 9c40494099f5c56573b6438ff96dfddfb223cbcb
cache:
- '%CYG_CACHE%'

install:
- 'echo Setting up Cygwin dependencies'
- '%CYG_ROOT%\setup-x86.exe -qnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P autoconf -P automake -P bison -P gcc-core -P gcc-g++ -P mingw-runtime -P mingw-binutils -P mingw-gcc-core -P mingw-gcc-g++ -P mingw-pthreads -P mingw-w32api -P libtool -P make -P python -P gettext-devel -P gettext -P intltool -P libiconv -P pkg-config -P git -P wget -P curl -P unzip -P psmisc> NUL'

- 'echo Check Cygwin setup'
- '%CYG_ROOT%/bin/bash -lc "cygcheck -dc cygwin"'
- 'echo Done setting up Cygwin'

- 'echo installing lein'
- ps: |
$base = "https://raw.githubusercontent.com/technomancy/leiningen/"
$lein = $base + "stable/bin/lein.bat"
(new-object net.webclient).DownloadFile($lein, "c:/projects/lighttable/lein.bat")
- lein self-install
- 'echo Done installing lein'
#Add random location, this prevents qutation mark being added to
#the current directory's path
- cmd: 'set PATH="%PATH%;%cd%;c:\windows\system32"'
- cmd: 'echo %PATH%'

build_script:
- cmd: 'echo Cygwin root is: %CYG_ROOT%'
- cmd: 'echo Build folder is: %APPVEYOR_BUILD_FOLDER%'
- cmd: 'echo Repo build branch is: %APPVEYOR_REPO_BRANCH%'
- cmd: 'echo Repo build commit is: %APPVEYOR_REPO_COMMIT%'

- cmd: 'echo creating lein reference'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; echo \"#!/bin/bash\" > lein.sh"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; echo \"./lein.bat \$@\" >> lein.sh"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; chmod a+x lein.sh"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ln -s /cygdrive/c/projects/lighttable/lein.sh lein; ls -la"'

- cmd: 'echo Running build.sh'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ./script/build.sh"'

- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ./script/run-tests.sh"'
#DEBUG BEGIN, PAUSES BUILD PROCESS TO ALLOW FOR REMOTE DEBUGGING VIA RDP
#- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
#- ps: throw "Failing tests"
#DBEUG END


5 changes: 0 additions & 5 deletions deploy/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ function createWindow() {
evt.preventDefault();
});

// Emitted when the window is closed.
window.on('closed', function() {
windows[window.id] = null;
});

return window;
};

Expand Down
3 changes: 2 additions & 1 deletion deploy/electron/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = function(grunt) {
"download-electron": {
version: "0.36.7",
outputDir: "./electron",
rebuild: true
rebuild: true,
token: process.env.GITHUB_OAUTH_READONLY_TOKEN
}
});

Expand Down
28 changes: 28 additions & 0 deletions doc/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# TESTING

## Quick Guide
After running ```/script/build.sh``` once, run ```/script/run-tests.sh```.

##Continuous Testing Architecture Overview
When a PR is created or updated, the automated test suite will run on travis and appveyor.

During the build processes, dependencies must be downloaded from github. API
rate limits were being hit. To increase the limit, a read-only oauth token for
the account ```light-table-bot``` has been added to the repo.

Light Table is driven by Selenium for testing.

Note a "test" plugin has been added to Light Table, found in `test/lt/lt-test-plugin/`.
The plugin replaces the native "file dialog" so files can be selected and modified.
During testing, the plugin is copied into a temporary home directory for Light Table, forcing
it to load.


## Words Of Caution
Keep in mind the jvm is slow to boot, and the testing environments used may
be under heavy load. If you need to have a process spawn close to the launching
of Light Table, launch the program in the java tests to minimize delay.

Initially ```light.sh``` was used by test suite to start Light Table. Kill signals
were not propigating correctly and Light Table would not always close. Thus, Light Table
is spawned directly from the test suite.
12 changes: 8 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
:compiler {:optimizations :simple
:output-to "deploy/core/node_modules/clojurescript/cljsDeps.js"
:output-dir "deploy/core/node_modules/clojurescript/cljsDeps/"
:pretty-print true }}]}
:pretty-print true }} ]}

;; TODO: Remove separate :doc :dependencies after ClojureScript upgrade
:profiles {:doc {:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.145"
:exclusions [org.apache.ant/ant]]]}}
:exclusions [org.apache.ant/ant]] ]}
:dev {:dependencies [[clj-webdriver "0.7.2"]
[org.seleniumhq.selenium/selenium-java "2.47.0"]
[me.raynes/fs "1.4.6"]]
:plugins [[test2junit "1.1.2"]
[lein-cljsbuild "1.0.1"]]}}
:plugins [[lein-cljsbuild "1.0.1"]
[lein-codox "0.9.5"]]
:codox {:language :clojurescript
Expand All @@ -39,5 +44,4 @@
;; Be explicit that undocumented public fns should be documented
:metadata {:doc "TODO: Add docstring"
:doc/format :markdown}}
:source-paths ["src/"]
)
:source-paths ["src/"])
40 changes: 40 additions & 0 deletions script/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Installs test dependencies, sets up environment variables,
# calls lein test, and then parses test results to see if
# the tests succeeded.

# Ensure we start in project root
cd "$(dirname "${BASH_SOURCE[0]}")"; cd ..
DIR=$(pwd)

#Redirect LightTable STDOUT to a file to clean up test output
LT_STDOUT_FILE="/tmp/lt-stdout"
touch $LT_STDOUT_FILE
if [[ $(uname -s | grep -i CYGWIN) ]]; then
LT_STDOUT_FILE="$(cygpath -aw $LT_STDOUT_FILE)"
fi

echo "Killing all chromedrivers. New instance will be created by test suite."
killall "chromedriver" &> /dev/null
killall "chromedriver.exe" &> /dev/null

#Fetch chrome driver
cd ./deploy/electron/
node_modules/.bin/grunt download-electron-chromedriver
cd -

echo "Running tests"
LT_STDOUT_FILE="$LT_STDOUT_FILE" lein with-profile dev test | tee /tmp/testoutput

#Check test results
#lein.bat return code is 0 even if tests fails on windows
#we grep the lein test output to to make sure no tests fail or errors
#this gives us cross os compatibility
tail -n 4 /tmp/testoutput | grep "^0 failures, 0 errors" > /dev/null
RETURN_CODE=$?

echo "===LIGHT TABLE DEBUG==="
cat $LT_STDOUT_FILE

exit $RETURN_CODE
33 changes: 25 additions & 8 deletions src/lt/objs/dialogs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,33 @@
(def remote (js/require "remote"))
(def dialog (.require remote "dialog"))

(defn dir [obj event]
(let [files (.showOpenDialog dialog app/win #js {:properties #js ["openDirectory" "multiSelections"]})]
(defn set-show-file-dialog-fn! [f] (def show-file-dialog f))

(set-show-file-dialog-fn!
(fn [type options callback]
(if (= :open type)
(callback (.showOpenDialog dialog app/win options))
(callback [(.showSaveDialog dialog app/win options)]))))


(defn broadcast-file-selected [obj event files]
(doseq [file files]
(object/raise obj event file))))
(if file (object/raise obj event file))))

(defn dir [obj event]
(show-file-dialog
:open
#js {:properties #js ["openDirectory" "multiSelections"]}
(partial broadcast-file-selected obj event)))

(defn file [obj event]
(let [files (.showOpenDialog dialog app/win #js {:properties #js ["openFile" "multiSelections"]})]
(doseq [file files]
(object/raise obj event file))))
(show-file-dialog
:open
#js {:properties #js ["openFile" "multiSelections"]}
(partial broadcast-file-selected obj event)))

(defn save-as [obj event path]
(when-let [file (.showSaveDialog dialog app/win #js {:defaultPath path})]
(object/raise obj event file)))
(show-file-dialog
:save
#js {:defaultPath path}
(partial broadcast-file-selected obj event)))
13 changes: 13 additions & 0 deletions test/lt/lt-test-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Mocks LightTable components so application can be tested.

To compile and update plugin:

1. Create symbolic link in LightTable plugin directory to plugin source

~~~
ln -s ~/programming/LightTable/test/lt/lt-test-plugin ~/Library/Application\ Support/LightTable/plugins/lighttable-test-plugin
~~~
1. Open plugin sourcecode in light table , `src/lt/plugins/lighttable-test-plugin.cljs`.
1. Save cljs file. Light table should auto compile.
1. Remove symbolic link created in step one.
1. Run `lein test` to ensure tests still work.
28 changes: 28 additions & 0 deletions test/lt/lt-test-plugin/lighttable test plugin_compiled.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/lt/lt-test-plugin/lighttable test plugin_compiled.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/lt/lt-test-plugin/lighttable-test-plugin.behaviors
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:+ {:app [(:lt.objs.plugins/load-js ["lighttable test plugin_compiled.js"])]}}
6 changes: 6 additions & 0 deletions test/lt/lt-test-plugin/plugin.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{:name "LightTable Test Plugin"
:author "Justin Taft"
:source "https://github.com/LightTable/LightTable"
:desc "Mocks Light Table components so application can be tested."
:behaviors "lighttable-test-plugin.behaviors"}

8 changes: 8 additions & 0 deletions test/lt/lt-test-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "LightTable Test Plugin",
"author": "Justin Taft",
"version": "0.0.1",
"source": "https://github.com/LightTable/LightTable",
"desc": "Mocks LightTable components so they can be tested",
"behaviors": "lighttable-test-plugin.behaviors"
}
2 changes: 2 additions & 0 deletions test/lt/lt-test-plugin/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(defproject lighttable-test-plugin "0.0.1"
:dependencies [[org.clojure/clojure "1.5.1"]])
34 changes: 34 additions & 0 deletions test/lt/lt-test-plugin/src/lt/plugins/lighttable-test-plugin.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(ns lt.plugins.lighttable-test-plugin
"Mocks & extends light table components for auotmated testing."
(:require [clojure.string :as string]
[lt.objs/popup :as popup]
[lt.util.dom :as dom]
[lt.objs.command :as cmd]))

(def debug-file-path-input (atom ""))

(defn show-file-dialog-mock
"Mocks show-file-dialog so native file dialog does not show.
A popup dialog with a text field is shown instead. File paths
can be specified in the path fields, seperated by commas to donate
multiple files."
[type options callback]
(popup/popup! {:body [:div [:h1 "File Dialog Mock"] [:input {:type "text" :id "debug-file-path"}]]
:buttons
[
{
:label "Okay"
:action #(swap! debug-file-path-input (fn [_] (dom/val (dom/$ "#debug-file-path"))))
:post-action #(callback (string/split @debug-file-path-input #","))
}
]
}))

(cmd/command {:command :lt.testing.mock
:desc "Test Env: Mocks light table components for automated tests."
:exec #(
;TODO error is thrown when evaling this, but it works...
(lt.objs.dialogs/set-show-file-dialog-fn! show-file-dialog-mock)
)
})

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Leiningen
#Sat Nov 12 01:47:39 PST 2016
version=0.0.1
groupId=lighttable-test-plugin
artifactId=lighttable-test-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Leiningen
#Sat Nov 12 00:56:46 PST 2016
version=0.0.1
groupId=lt-test-file-dialog-mock
artifactId=lt-test-file-dialog-mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Leiningen
#Sat Nov 12 01:07:36 PST 2016
version=0.0.1
groupId=lt-test-plugin
artifactId=lt-test-plugin

0 comments on commit 8fb6fc3

Please sign in to comment.