Run tests on Travis-CI.
authorDan Vanderkam <danvdk@gmail.com>
Fri, 23 Oct 2015 21:15:11 +0000 (17:15 -0400)
committerDan Vanderkam <danvdk@gmail.com>
Sun, 25 Oct 2015 02:44:15 +0000 (22:44 -0400)
.travis.yml
auto_tests/runner.html
auto_tests/tests/grid_per_axis.js
make-prod-combined.sh
make-tests.sh [new file with mode: 0755]
package.json
run-tests.sh [new file with mode: 0755]

index e33129b..f318f37 100644 (file)
@@ -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
index 1768c1f..7102a95 100644 (file)
@@ -9,12 +9,18 @@
   <div id="mocha"></div>
 
   <!-- Polyfills for PhantomJS -->
-  <script src="../node_modules/babel/node_modules/babel-core/browser-polyfill.js"></script>
+  <script src="../node_modules/babel-core/browser-polyfill.js"></script>
 
   <!-- Mocha -->
   <script src="../node_modules/mocha/mocha.js"></script>
   <script src="../node_modules/chai/chai.js"></script>
   <script>
+  if (window.initMochaPhantomJS) {
+    window.initMochaPhantomJS();
+  }
+  </script>
+
+  <script>
   var expect = chai.expect;
   var assert = chai.assert;
   function cleanupAfterEach() {
 
   <script>
     mocha.checkLeaks();
-    if (window.mochaPhantomJS) {
-      mochaPhantomJS.run();
-    } else {
-      mocha.run();
-    }
+    mocha.run();
   </script>
 </body>
 </html>
index 99cc6da..3a4c475 100644 (file)
@@ -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() {
     }
   }
 });
+}
 
 });
index a95c612..6e8f9aa 100755 (executable)
@@ -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 (executable)
index 0000000..3242266
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+browserify \
+  -v \
+  -t babelify \
+  -t [ envify --NODE_ENV development ] \
+  --debug \
+  -o dist/tests.js \
+  auto_tests/tests/*.js
index 7d136cc..27228be 100644 (file)
@@ -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 (executable)
index 0000000..4b1c77f
--- /dev/null
@@ -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