From d59cc6c166d0d112a62016909b33e04ed08d2274 Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Mon, 25 Jan 2016 23:59:57 -0800 Subject: [PATCH] Fix #2067: HTML/DOC reporter regression with async failures --- lib/reporters/doc.js | 4 ++-- lib/reporters/html.js | 2 +- lib/reporters/markdown.js | 2 +- lib/test.js | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/reporters/doc.js b/lib/reporters/doc.js index 8c1fd3adf7..01f3fdc9d9 100644 --- a/lib/reporters/doc.js +++ b/lib/reporters/doc.js @@ -49,13 +49,13 @@ function Doc(runner) { runner.on('pass', function(test) { console.log('%s
%s
', indent(), utils.escape(test.title)); - var code = utils.escape(utils.clean(test.fn.toString())); + var code = utils.escape(utils.clean(test.body)); console.log('%s
%s
', indent(), code); }); runner.on('fail', function(test, err) { console.log('%s
%s
', indent(), utils.escape(test.title)); - var code = utils.escape(utils.clean(test.fn.toString())); + var code = utils.escape(utils.clean(test.fn.body)); console.log('%s
%s
', indent(), code); console.log('%s
%s
', indent(), utils.escape(err)); }); diff --git a/lib/reporters/html.js b/lib/reporters/html.js index 277075985d..7da2508e40 100644 --- a/lib/reporters/html.js +++ b/lib/reporters/html.js @@ -200,7 +200,7 @@ function HTML(runner) { pre.style.display = pre.style.display === 'none' ? 'block' : 'none'; }); - var pre = fragment('
%e
', utils.clean(test.fn.toString())); + var pre = fragment('
%e
', utils.clean(test.body)); el.appendChild(pre); pre.style.display = 'none'; } diff --git a/lib/reporters/markdown.js b/lib/reporters/markdown.js index 88b1f4db09..680c55d709 100644 --- a/lib/reporters/markdown.js +++ b/lib/reporters/markdown.js @@ -82,7 +82,7 @@ function Markdown(runner) { }); runner.on('pass', function(test) { - var code = utils.clean(test.fn.toString()); + var code = utils.clean(test.body); buf += test.title + '.\n'; buf += '\n```js\n'; buf += code + '\n'; diff --git a/lib/test.js b/lib/test.js index a95cd31a48..b39ce42cad 100644 --- a/lib/test.js +++ b/lib/test.js @@ -22,6 +22,7 @@ function Test(title, fn) { Runnable.call(this, title, fn); this.pending = !fn; this.type = 'test'; + this.body = (fn || '').toString(); } /**