Skip to content

Commit

Permalink
Adding output of sourcefile and linenumber of failed assertions (exce…
Browse files Browse the repository at this point in the history
…pt ok()). Only limited cross-browser support for now. Fixes qunitjs#60
  • Loading branch information
jzaefferer committed Nov 28, 2010
1 parent 7317cf6 commit 60e9902
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions qunit/qunit.js
Expand Up @@ -498,6 +498,13 @@ extend(QUnit, {
output += '<tr class="test-actual"><th>Result: </th><td><pre>' + actual + '</pre></td></tr>';
output += '<tr class="test-diff"><th>Diff: </th><td><pre>' + QUnit.diff(expected, actual) +'</pre></td></tr>';
}
if (!result) {
var source = sourceFromStacktrace();
if (source) {
details.source = source;
output += '<tr class="test-source"><th>Source: </th><td><pre>' + source +'</pre></td></tr>';
}
}
output += "</table>";

QUnit.log(result, message, details);
Expand Down Expand Up @@ -665,6 +672,22 @@ function validTest( name ) {
return run;
}

// so far supports only Firefox, Chrome and Opera (buggy)
// could be extended in the future to use something like https://github.com/csnover/TraceKit
function sourceFromStacktrace() {
try {
throw new Error();
} catch ( e ) {
if (e.stacktrace) {
// Opera
return e.stacktrace.split("\n")[6];
} else if (e.stack) {
// Firefox, Chrome
return e.stack.split("\n")[4];
}
}
}

function resultDisplayStyle(passed) {
return passed && id("qunit-filter-pass") && id("qunit-filter-pass").checked ? 'none' : '';
}
Expand Down

0 comments on commit 60e9902

Please sign in to comment.