Skip to content

Instantly share code, notes, and snippets.

@patrickdlogan
Forked from lukaszkorecki/example output
Created January 31, 2011 05:10
Show Gist options
  • Save patrickdlogan/803661 to your computer and use it in GitHub Desktop.
Save patrickdlogan/803661 to your computer and use it in GitHub Desktop.
phantomjs testrunner for qunit

A simple test runner for QUnit

Usage: phantomjs testrunner.js URL_TO_YOUR_TESTFILE accepts http:// and file:// uris

Returns 0 when tests pass and 1 when something didn't go as expected (useful for use with continuous integration systems like CruiseControl).

Console output only occurs on failures. Each failed assertion's message is logged. Passes are silent.

[10:44][~/dev/Mikrob.chrome master]: phantomjs testrunner.js file://`pwd`/test.html
Running tests
file:///Users/optimor/dev/Mikrob.chrome/test/collection_store_test.js:71 Clearing localStorage
Passed: 14, Failed: 1 Total: 15
[10:44][~/dev/Mikrob.chrome master]: echo $?
1
if (phantom.state.length === 0) {
if(phantom.args.length === 0 || phantom.args.length > 2) {
console.log("Simple QUnit test runner for phantom.js");
console.log('Usage: testrunner.js url_to_test_file.html');
console.log('Accepts: http://example.com/file.html and file:///dirs/test.html');
phantom.exit();
} else {
phantom.state = "run-qunit";
phantom.open(phantom.args[0]);
}
} else {
setInterval(function() {
var result_el = document.getElementById('qunit-testresult');
if(typeof result_el !== 'undefined') {
try {
var passed = result_el.getElementsByClassName('passed')[0].innerHTML;
var total = result_el.getElementsByClassName('total')[0].innerHTML;
var failed = result_el.getElementsByClassName('failed')[0].innerHTML;
} catch(e) {
// SHHHHHH
}
if(parseInt(failed,10) > 0) {
$('li .fail .test-message').each(function(i, e) {
console.log(e.innerHTML);
});
console.log('Passed: ' + passed + ', Failed: ' + failed + ' Total: ' + total);
phantom.exit(1);
} else {
phantom.exit(0);
}
}
}, 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment