From 2a1f00d810b5c4f04b72bc6a393380b858f70909 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 23 Oct 2015 17:15:11 -0400 Subject: [PATCH] Run tests on Travis-CI. --- .travis.yml | 4 +++- auto_tests/runner.html | 14 ++++++++------ auto_tests/tests/grid_per_axis.js | 5 +++++ make-prod-combined.sh | 17 ++++++++++++++++- make-tests.sh | 8 ++++++++ package.json | 3 +++ run-tests.sh | 21 +++++++++++++++++++++ 7 files changed, 64 insertions(+), 8 deletions(-) create mode 100755 make-tests.sh create mode 100755 run-tests.sh diff --git a/.travis.yml b/.travis.yml index e33129b..f318f37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ node_js: sudo: false # Use container-based architecture script: > - gulp travis && + ./make-prod-combined.sh && + ./make-tests.sh && + ./run-tests.sh && curl -O https://raw.githubusercontent.com/danvk/travis-weigh-in/master/weigh_in.py && python weigh_in.py dist/dygraph-combined.js diff --git a/auto_tests/runner.html b/auto_tests/runner.html index 1768c1f..7102a95 100644 --- a/auto_tests/runner.html +++ b/auto_tests/runner.html @@ -9,12 +9,18 @@
- + + + diff --git a/auto_tests/tests/grid_per_axis.js b/auto_tests/tests/grid_per_axis.js index 99cc6da..3a4c475 100644 --- a/auto_tests/tests/grid_per_axis.js +++ b/auto_tests/tests/grid_per_axis.js @@ -243,6 +243,10 @@ it('testPerAxisGridWidth', function() { } }); +// PhantomJS 1.9.x does not support setLineDash +// When Travis-CI updates to Phantom2, this can be re-enabled. +// See https://github.com/ariya/phantomjs/issues/12948 +if (!navigator.userAgent.match(/PhantomJS\/1.9/)) { it('testGridLinePattern', function() { var opts = { width : 480, @@ -314,5 +318,6 @@ it('testGridLinePattern', function() { } } }); +} }); diff --git a/make-prod-combined.sh b/make-prod-combined.sh index a95c612..6e8f9aa 100755 --- a/make-prod-combined.sh +++ b/make-prod-combined.sh @@ -1,4 +1,6 @@ #!/bin/bash +mkdir -p dist + browserify \ -v \ -t babelify \ @@ -6,5 +8,18 @@ browserify \ --debug \ --standalone Dygraph \ src/dygraph.js \ - | uglifyjs -c -m \ > dist/dygraph.js + +# Create dist/dygraph.js.map +cat dist/dygraph.js | exorcist --base . dist/dygraph.js.map > /dev/null + +# Create dist/dygraph.js.min{,.map} +uglifyjs --compress --mangle \ + --in-source-map dist/dygraph.js.map \ + --source-map-include-sources \ + --source-map dist/dygraph.min.js.map \ + -o dist/dygraph.min.js \ + dist/dygraph.js + +# Copy to the old location +cp dist/dygraph.min.js dist/dygraph-combined.js diff --git a/make-tests.sh b/make-tests.sh new file mode 100755 index 0000000..3242266 --- /dev/null +++ b/make-tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash +browserify \ + -v \ + -t babelify \ + -t [ envify --NODE_ENV development ] \ + --debug \ + -o dist/tests.js \ + auto_tests/tests/*.js diff --git a/package.json b/package.json index 7d136cc..27228be 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ }, "homepage": "https://github.com/danvk/dygraphs", "devDependencies": { + "babel-core": "^5.8.25", "babelify": "^6.3.0", "browserify": "^11.2.0", "chai": "^3.3.0", @@ -43,6 +44,7 @@ "gulp-shell": "^0.4.0", "gulp-sourcemaps": "^1.3.0", "gulp-uglify": "^1.0.2", + "http-server": "^0.8.5", "jshint": "^2.5.10", "karma": "^0.12.31", "karma-chai-plugins": "^0.2.4", @@ -55,6 +57,7 @@ "karma-spec-reporter": "0.0.16", "lcov-parse": "0.0.9", "mocha": "^2.1.0", + "mocha-phantomjs": "^4.0.1", "obvious-closure-library": "^20140401.0.2", "parse-data-uri": "^0.2.0", "phantomjs": "^1.9.7-8", diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..4b1c77f --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Starts the http-server and runs mocha-phantomjs-based tests +# Note that you must run `npm run build` or `npm run watch` before running this. +set -o errexit + +# Run http-server and save its PID +http-server -p 8081 > /dev/null & +SERVER_PID=$! +function finish() { + kill -TERM $SERVER_PID +} +trap finish EXIT + +# the following sleep step is not really necessary +# as http-server starts almost instantenously; +# but letting the server settle might help prevent +# possible racing conditions +sleep 1 + +# Start the tests +mocha-phantomjs http://localhost:8081/auto_tests/runner.html -- 2.7.4