Skip to content

Commit

Permalink
Merge pull request #47 from jzaefferer/color-qunit-output
Browse files Browse the repository at this point in the history
Provide some colored output and detailed assertion logging for QUnit
  • Loading branch information
rahulnwn committed Mar 14, 2014
2 parents 1d93f8b + f84f0f2 commit fc59b76
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/_patch/browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if (req.readyState==4)
cb(req.responseText);
};
var data = "data=" + JSON.stringify(json)
var data = "data=" + encodeURIComponent(JSON.stringify(json));
req.open("POST", url, true);
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
req.setRequestHeader('X-Browser-String', BrowserStack.browser_string);
Expand Down
6 changes: 3 additions & 3 deletions lib/_patch/qunit-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

var error = {
actual: details.actual,
expected: encodeURIComponent(details.expected),
message: encodeURIComponent(details.message),
source: encodeURIComponent(details.source),
expected: details.expected,
message: details.message,
source: details.source,
testName:( details.module + ": " + details.name)
};

Expand Down
36 changes: 29 additions & 7 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var http = require("http"),
qs = require("querystring"),
utils = require("./utils"),
config = require('../lib/config'),
exec = require('child_process').exec;
exec = require('child_process').exec,
chalk = require('chalk');

var mimeTypes = {
"html": "text/html",
Expand Down Expand Up @@ -111,6 +112,26 @@ exports.Server = function Server(bsClient, workers) {
return JSON.parse(qs.parse(body).data.escapeSpecialChars());
}

function formatTraceback(details) {
// looks like QUnit data
if (details.testName) {
var output = "'" + details.testName + "' failed";
if (details.message) {
output += ", " + details.message;
}
if (details.actual && details.expected) {
output += "\n" + chalk.blue("Expected: ") + details.expected +
"\n" + chalk.blue(" Actual: ") + details.actual;
}
if (details.source) {
output += "\n" + chalk.blue(" Source: ") + "";
output += details.source.split("\n").join("\n\t ");
}
return output;
}
return details;
}

handlers = {
"_progress": function progressHandler(uri, body, request, response) {
var uuid = request.headers['x-worker-uuid'];
Expand All @@ -119,13 +140,13 @@ exports.Server = function Server(bsClient, workers) {
try {
query = parseBody(body);
} catch(e) {
console.log("[%s] Exception in parsing QUnit log", worker.string)
console.log("[%s] Log: " + qs.parse(body).data, worker.string)
console.log("[%s] Exception in parsing log", worker.string);
console.log("[%s] Log: " + qs.parse(body).data, worker.string);
}

if (query.tracebacks) {
query.tracebacks.forEach(function(traceback) {
console.log("[%s] Error:", worker.string, traceback);
console.log(chalk.red("[%s] Error:"), worker.string, formatTraceback(traceback));
});
}
response.end();
Expand All @@ -148,8 +169,8 @@ exports.Server = function Server(bsClient, workers) {
console.log(traceback);
});
}

console.log("[%s] Completed in %d milliseconds. %d of %d passed, %d failed.", request.headers['x-browser-string'], query.runtime, query.passed, query.total, query.failed);
var color = query.failed ? "red" : "green";
console.log(chalk[color]("[%s] Completed in %d milliseconds. %d of %d passed, %d failed."), request.headers['x-browser-string'], query.runtime, query.passed, query.total, query.failed);
status += query.failed;
}

Expand All @@ -170,7 +191,8 @@ exports.Server = function Server(bsClient, workers) {
delete workers[uuid];

if (utils.objectSize(workers) === 0) {
console.log("All tests done, failures: %d.", status);
var color = status > 0 ? "red" : "green";
console.log(chalk[color]("All tests done, failures: %d."), status);

if (status > 0) {
status = 1;
Expand Down

0 comments on commit fc59b76

Please sign in to comment.