2013-06-18 12:44:20 -05:00
|
|
|
// PhantomJS QUnit Test Runner
|
|
|
|
|
|
|
|
/*globals QUnit phantom*/
|
|
|
|
|
2015-08-25 03:42:19 -05:00
|
|
|
var system = require("system"),
|
2015-08-25 10:36:24 -05:00
|
|
|
args = phantom.args;
|
2015-08-25 03:42:19 -05:00
|
|
|
|
2015-08-25 10:36:24 -05:00
|
|
|
if (args === undefined) {
|
|
|
|
args = system.args;
|
|
|
|
args.shift();
|
|
|
|
}
|
2015-08-25 03:42:19 -05:00
|
|
|
|
2013-06-18 12:44:20 -05:00
|
|
|
if (args.length < 1 || args.length > 2) {
|
|
|
|
console.log("Usage: " + phantom.scriptName + " <URL> <timeout>");
|
|
|
|
phantom.exit(1);
|
|
|
|
}
|
|
|
|
|
2015-08-25 03:42:19 -05:00
|
|
|
var page = require("webpage").create();
|
2013-06-18 12:44:20 -05:00
|
|
|
|
|
|
|
page.onConsoleMessage = function(msg) {
|
2015-08-25 03:42:19 -05:00
|
|
|
if (msg.slice(0, 8) === "WARNING:") { return; }
|
|
|
|
if (msg.slice(0, 6) === "DEBUG:") { return; }
|
2013-06-18 12:44:20 -05:00
|
|
|
|
|
|
|
console.log(msg);
|
|
|
|
};
|
|
|
|
|
2013-11-01 17:57:50 -05:00
|
|
|
page.onCallback = function (message) {
|
|
|
|
// forward the message to the standard output
|
|
|
|
system.stdout.write(message);
|
|
|
|
};
|
|
|
|
|
2013-06-18 12:44:20 -05:00
|
|
|
page.open(args[0], function(status) {
|
2015-08-25 03:42:19 -05:00
|
|
|
if (status !== "success") {
|
2013-06-18 12:44:20 -05:00
|
|
|
console.error("Unable to access network");
|
|
|
|
phantom.exit(1);
|
|
|
|
} else {
|
|
|
|
page.evaluate(logQUnit);
|
|
|
|
|
2017-07-24 04:44:33 -05:00
|
|
|
var timeout = parseInt(args[1] || 300000, 10),
|
2015-08-25 03:42:19 -05:00
|
|
|
start = Date.now();
|
|
|
|
|
2013-06-18 12:44:20 -05:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-25 03:42:19 -05:00
|
|
|
}, 250);
|
2013-06-18 12:44:20 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function logQUnit() {
|
|
|
|
var moduleErrors = [];
|
|
|
|
var testErrors = [];
|
|
|
|
var assertionErrors = [];
|
|
|
|
|
|
|
|
console.log("\nRunning: " + JSON.stringify(QUnit.urlParams) + "\n");
|
|
|
|
|
2016-11-16 04:02:16 -06:00
|
|
|
QUnit.config.testTimeout = 10000;
|
|
|
|
|
2013-06-18 12:44:20 -05:00
|
|
|
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 = [];
|
2015-08-25 03:42:19 -05:00
|
|
|
window.callPhantom("F");
|
2013-06-18 12:44:20 -05:00
|
|
|
} else {
|
2015-08-25 03:42:19 -05:00
|
|
|
window.callPhantom(".");
|
2013-06-18 12:44:20 -05: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) {
|
2015-08-25 03:42:19 -05:00
|
|
|
console.log("\n");
|
2013-06-18 12:44:20 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|