Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Integrate with Travis CI via PhantomJS spec runner

  • Loading branch information...
commit 298d91a2cc1cf0185a942a3669b47b9fbc876ac5 1 parent 6cc09d4
@SteveSanderson SteveSanderson authored
Showing with 45 additions and 0 deletions.
  1. +8 −0 .travis.yml
  2. +37 −0 spec/runner.phantom.js
View
8 .travis.yml
@@ -0,0 +1,8 @@
+language: node_js
+before_script:
+ - "cd build; rm output/*.*"
+ - "./build-linux"
+ - "cd .."
+script:
+ - "phantomjs spec/runner.phantom.js"
+
View
37 spec/runner.phantom.js
@@ -0,0 +1,37 @@
+var fs = require('fs'),
+ system = require('system'),
+ page = require('webpage').create(),
+ specFilename = fs.absolute((system.args.length > 1 && system.args[1]) || 'spec/runner.html'),
+ specFailureLog = [];
+
+// Configure the JsSpec runner to test the minified KO build. Paths are relative to specFilename.
+page.onInitialized = function() {
+ page.evaluate(function() { window.koFilename = '../build/output/knockout-latest.js'; });
+};
+
+// Intercept JsSpec log messages and map them to PhantomJS output
+page.onConsoleMessage = function(msg) {
+ var isExampleCompleted = typeof msg === 'string' && /^Result\:/.test(msg),
+ isSuiteCompleted = typeof msg === 'string' && /^Finished\:/.test(msg);
+
+ if (isExampleCompleted) {
+ // Parse the JSON and log the example only if it failed
+ var exampleResult = JSON.parse(msg.substring(7));
+ if (!exampleResult.ok) {
+ console.log(msg);
+ specFailureLog.push(exampleResult);
+ }
+ } else if (isSuiteCompleted) {
+ console.log('JsSpec ' + msg);
+ phantom.exit(specFailureLog.length); // 0 means success
+ } else {
+ console.log(msg);
+ }
+};
+
+page.open('file://' + specFilename, function (status) {
+ if (status !== 'success') {
+ console.log('Error: Could not load the runner page at ' + specFilename);
+ phantom.exit(1);
+ }
+});
Please sign in to comment.
Something went wrong with that request. Please try again.