2014-03-11 03:10:55 -04:00
|
|
|
/*jshint devel:true, phantom:true */
|
2015-08-25 11:36:24 -04:00
|
|
|
/*globals QUnit ANSI */
|
|
|
|
|
2013-11-01 18:57:50 -04:00
|
|
|
// THIS FILE IS CALLED BY "qunit_runner.rb" IN AUTOSPEC
|
|
|
|
|
2015-08-25 11:36:24 -04:00
|
|
|
var system = require("system"),
|
|
|
|
args = phantom.args;
|
2015-08-25 04:42:19 -04:00
|
|
|
|
2015-08-25 11:36:24 -04:00
|
|
|
if (args === undefined) {
|
|
|
|
args = system.args;
|
|
|
|
args.shift();
|
|
|
|
}
|
2015-08-25 04:42:19 -04:00
|
|
|
|
|
|
|
if (args.length !== 1) {
|
2013-11-01 18:57:50 -04:00
|
|
|
console.log("Usage: " + phantom.scriptName + " <URL>");
|
|
|
|
phantom.exit(1);
|
|
|
|
}
|
|
|
|
|
2015-08-25 04:42:19 -04:00
|
|
|
var fs = require('fs'),
|
2013-11-01 18:57:50 -04:00
|
|
|
page = require('webpage').create(),
|
|
|
|
QUNIT_RESULT = "./tmp/qunit_result";
|
|
|
|
|
|
|
|
if (fs.exists(QUNIT_RESULT) && fs.isFile(QUNIT_RESULT)) { fs.remove(QUNIT_RESULT); }
|
|
|
|
|
|
|
|
page.onConsoleMessage = function (message) {
|
|
|
|
// filter out Ember's debug messages
|
|
|
|
if (message.slice(0, 8) === "WARNING:") { return; }
|
|
|
|
if (message.slice(0, 6) === "DEBUG:") { return; }
|
|
|
|
|
|
|
|
console.log(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
page.onCallback = function (message) {
|
|
|
|
// write to the result file
|
2017-04-30 19:45:19 -04:00
|
|
|
if (message.slice(0, 5) === "FAIL:") {
|
|
|
|
fs.write(QUNIT_RESULT, message.slice(6) + "\n", "a");
|
|
|
|
}
|
2013-11-01 18:57:50 -04:00
|
|
|
// forward the message to the standard output
|
|
|
|
if (message.slice(0, 6) === "PRINT:") { system.stdout.write(message.slice(7)); }
|
|
|
|
};
|
|
|
|
|
|
|
|
page.start = new Date();
|
|
|
|
|
|
|
|
// -----------------------------------WARNING --------------------------------------
|
|
|
|
// calling "console.log" BELOW this line will go through the "page.onConsoleMessage"
|
|
|
|
// -----------------------------------WARNING --------------------------------------
|
2015-08-25 04:42:19 -04:00
|
|
|
page.open(args[0], function (status) {
|
2013-11-01 18:57:50 -04:00
|
|
|
if (status !== "success") {
|
|
|
|
console.log("\nNO NETWORK :(\n");
|
|
|
|
phantom.exit(1);
|
|
|
|
} else {
|
|
|
|
console.log("QUnit loaded in " + (new Date() - page.start) + " ms");
|
|
|
|
|
|
|
|
page.evaluate(colorizer);
|
|
|
|
page.evaluate(logQUnit);
|
|
|
|
|
2017-05-02 16:02:00 -04:00
|
|
|
// wait up to 600 seconds for QUnit to finish
|
|
|
|
var timeout = 600 * 1000,
|
2013-11-01 18:57:50 -04:00
|
|
|
start = Date.now();
|
|
|
|
|
|
|
|
var interval = setInterval(function() {
|
|
|
|
if (Date.now() - start > timeout) {
|
|
|
|
console.error("\nTIME OUT :(\n");
|
|
|
|
phantom.exit(1);
|
|
|
|
} else {
|
|
|
|
var qunitResult = page.evaluate(function() { return window.qunitResult; });
|
|
|
|
if (qunitResult) {
|
|
|
|
clearInterval(interval);
|
|
|
|
if (qunitResult.failed > 0) {
|
|
|
|
phantom.exit(1);
|
|
|
|
} else {
|
|
|
|
phantom.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 250);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// https://github.com/jquery/qunit/pull/470
|
|
|
|
function colorizer() {
|
|
|
|
window.ANSI = {
|
|
|
|
colorMap: {
|
|
|
|
"red": "\u001b[31m",
|
|
|
|
"green": "\u001b[32m",
|
|
|
|
"blue": "\u001b[34m",
|
|
|
|
"end": "\u001b[0m"
|
|
|
|
},
|
|
|
|
highlightMap: {
|
|
|
|
"red": "\u001b[41m\u001b[37m", // change 37 to 30 for black text
|
|
|
|
"green": "\u001b[42m\u001b[30m",
|
|
|
|
"blue": "\u001b[44m\u001b[37m",
|
|
|
|
"end": "\u001b[0m"
|
|
|
|
},
|
|
|
|
|
|
|
|
highlight: function (text, color) {
|
|
|
|
var colorCode = this.highlightMap[color],
|
|
|
|
colorEnd = this.highlightMap.end;
|
|
|
|
|
|
|
|
return colorCode + text + colorEnd;
|
|
|
|
},
|
|
|
|
|
|
|
|
colorize: function (text, color) {
|
|
|
|
var colorCode = this.colorMap[color],
|
|
|
|
colorEnd = this.colorMap.end;
|
|
|
|
|
|
|
|
return colorCode + text + colorEnd;
|
|
|
|
}
|
|
|
|
};
|
2014-03-11 03:10:55 -04:00
|
|
|
}
|
2013-11-01 18:57:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
function logQUnit() {
|
|
|
|
// keep track of error messages
|
|
|
|
var errors = {};
|
|
|
|
|
|
|
|
QUnit.begin(function () {
|
|
|
|
console.log("BEGIN");
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.log(function (context) {
|
|
|
|
if (!context.result) {
|
|
|
|
var module = context.module,
|
|
|
|
test = context.name;
|
|
|
|
|
|
|
|
var assertion = {
|
|
|
|
message: context.message,
|
|
|
|
expected: context.expected,
|
|
|
|
actual: context.actual
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!errors[module]) { errors[module] = {}; }
|
|
|
|
if (!errors[module][test]) { errors[module][test] = []; }
|
|
|
|
errors[module][test].push(assertion);
|
|
|
|
|
2017-04-30 19:45:19 -04:00
|
|
|
window.callPhantom("FAIL: " + context.module + ":::" + context.testId + ":::" + context.name);
|
2013-11-01 18:57:50 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.testDone(function (context) {
|
|
|
|
if (context.failed > 0) {
|
|
|
|
window.callPhantom("PRINT: " + ANSI.colorize("F", "red"));
|
|
|
|
} else {
|
|
|
|
window.callPhantom("PRINT: " + ANSI.colorize(".", "green"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.done(function (context) {
|
|
|
|
console.log("\n");
|
|
|
|
|
|
|
|
// display failures
|
|
|
|
if (Object.keys(errors).length > 0) {
|
|
|
|
console.log("Failures:\n");
|
2014-03-11 03:10:55 -04:00
|
|
|
for (var m in errors) {
|
2013-11-01 18:57:50 -04:00
|
|
|
var module = errors[m];
|
|
|
|
console.log("Module Failed: " + ANSI.highlight(m, "red"));
|
2014-03-11 03:10:55 -04:00
|
|
|
for (var t in module) {
|
2013-11-01 18:57:50 -04:00
|
|
|
var test = module[t];
|
|
|
|
console.log(" Test Failed: " + t);
|
|
|
|
for (var a = 0; a < test.length; a++) {
|
|
|
|
var assertion = test[a];
|
|
|
|
console.log(" Assertion Failed: " + (assertion.message || ""));
|
|
|
|
if (assertion.expected) {
|
|
|
|
console.log(" Expected: " + assertion.expected);
|
|
|
|
console.log(" Actual: " + assertion.actual);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// display summary
|
|
|
|
console.log("\n");
|
|
|
|
console.log("Finished in " + (context.runtime / 1000) + " seconds");
|
|
|
|
var color = context.failed > 0 ? "red" : "green";
|
|
|
|
console.log(ANSI.colorize(context.total + " examples, " + context.failed + " failures", color));
|
|
|
|
|
|
|
|
// we're done
|
|
|
|
window.qunitResult = context;
|
|
|
|
});
|
|
|
|
|
2014-03-11 03:10:55 -04:00
|
|
|
}
|