2013-06-18 13:44:20 -04:00
|
|
|
// PhantomJS QUnit Test Runner
|
|
|
|
|
|
|
|
/*globals QUnit phantom*/
|
|
|
|
|
|
|
|
var args = phantom.args;
|
|
|
|
if (args.length < 1 || args.length > 2) {
|
|
|
|
console.log("Usage: " + phantom.scriptName + " <URL> <timeout>");
|
|
|
|
phantom.exit(1);
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:22:25 -04:00
|
|
|
var system = require("system"),
|
|
|
|
page = require('webpage').create();
|
2013-06-18 13:44:20 -04:00
|
|
|
|
|
|
|
page.onConsoleMessage = function(msg) {
|
|
|
|
if (msg.slice(0,8) === 'WARNING:') { return; }
|
|
|
|
if (msg.slice(0,6) === 'DEBUG:') { return; }
|
|
|
|
|
|
|
|
console.log(msg);
|
|
|
|
};
|
|
|
|
|
2013-11-01 18:57:50 -04:00
|
|
|
page.onCallback = function (message) {
|
|
|
|
// forward the message to the standard output
|
|
|
|
system.stdout.write(message);
|
|
|
|
};
|
|
|
|
|
2013-06-18 13:44:20 -04:00
|
|
|
page.open(args[0], function(status) {
|
|
|
|
if (status !== 'success') {
|
|
|
|
console.error("Unable to access network");
|
|
|
|
phantom.exit(1);
|
|
|
|
} else {
|
|
|
|
page.evaluate(logQUnit);
|
|
|
|
|
2014-03-05 04:45:57 -05:00
|
|
|
var timeout = parseInt(args[1] || 120000, 10);
|
2013-06-18 13:44:20 -04:00
|
|
|
var start = Date.now();
|
|
|
|
var interval = setInterval(function() {
|
|
|
|
if (Date.now() > start + timeout) {
|
|
|
|
console.error("Tests timed out");
|
|
|
|
phantom.exit(124);
|
|
|
|
} else {
|
|
|
|
var qunitDone = page.evaluate(function() {
|
|
|
|
return window.qunitDone;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (qunitDone) {
|
|
|
|
clearInterval(interval);
|
|
|
|
if (qunitDone.failed > 0) {
|
|
|
|
phantom.exit(1);
|
|
|
|
} else {
|
|
|
|
phantom.exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function logQUnit() {
|
|
|
|
var moduleErrors = [];
|
|
|
|
var testErrors = [];
|
|
|
|
var assertionErrors = [];
|
|
|
|
|
|
|
|
console.log("\nRunning: " + JSON.stringify(QUnit.urlParams) + "\n");
|
|
|
|
|
|
|
|
QUnit.moduleDone(function(context) {
|
|
|
|
if (context.failed) {
|
|
|
|
var msg = "Module Failed: " + context.name + "\n" + testErrors.join("\n");
|
|
|
|
moduleErrors.push(msg);
|
|
|
|
testErrors = [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.testDone(function(context) {
|
|
|
|
if (context.failed) {
|
|
|
|
var msg = " Test Failed: " + context.name + assertionErrors.join(" ");
|
|
|
|
testErrors.push(msg);
|
|
|
|
assertionErrors = [];
|
2013-11-01 18:57:50 -04:00
|
|
|
window.callPhantom('F');
|
2013-06-18 13:44:20 -04:00
|
|
|
} else {
|
2013-11-01 18:57:50 -04:00
|
|
|
window.callPhantom('.');
|
2013-06-18 13:44:20 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.log(function(context) {
|
|
|
|
if (context.result) { return; }
|
|
|
|
|
|
|
|
var msg = "\n Assertion Failed:";
|
|
|
|
if (context.message) {
|
|
|
|
msg += " " + context.message;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context.expected) {
|
|
|
|
msg += "\n Expected: " + context.expected + ", Actual: " + context.actual;
|
|
|
|
}
|
|
|
|
|
|
|
|
assertionErrors.push(msg);
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.done(function(context) {
|
|
|
|
console.log('\n');
|
|
|
|
|
|
|
|
if (moduleErrors.length > 0) {
|
|
|
|
for (var idx=0; idx<moduleErrors.length; idx++) {
|
|
|
|
console.error(moduleErrors[idx]+"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var stats = [
|
|
|
|
"Time: " + context.runtime + "ms",
|
|
|
|
"Total: " + context.total,
|
|
|
|
"Passed: " + context.passed,
|
|
|
|
"Failed: " + context.failed
|
|
|
|
];
|
|
|
|
console.log(stats.join(", "));
|
|
|
|
window.qunitDone = context;
|
|
|
|
});
|
|
|
|
}
|