Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide some colored output and detailed assertion logging for QUnit #47

Merged
merged 1 commit into from
Mar 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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