Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding output of sourcefile and linenumber of failed assertions (exce…

…pt ok()). Only limited cross-browser support for now. Fixes #60
  • Loading branch information...
commit 60e9902dfb1e7a5aba74590635841943ea1134a9 1 parent 7317cf6
@jzaefferer jzaefferer authored
Showing with 23 additions and 0 deletions.
  1. +23 −0 qunit/qunit.js
View
23 qunit/qunit.js
@@ -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);
@@ -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' : '';
}
Please sign in to comment.
Something went wrong with that request. Please try again.