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

Fix 2067: HTML/DOC reporter regression with async failures #2068

Merged
merged 1 commit into from
Jan 26, 2016
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
4 changes: 2 additions & 2 deletions lib/reporters/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ function Doc(runner) {

runner.on('pass', function(test) {
console.log('%s <dt>%s</dt>', 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 <dd><pre><code>%s</code></pre></dd>', indent(), code);
});

runner.on('fail', function(test, err) {
console.log('%s <dt class="error">%s</dt>', 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 <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
});
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function HTML(runner) {
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
});

var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.fn.toString()));
var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.body));
el.appendChild(pre);
pre.style.display = 'none';
}
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function Test(title, fn) {
Runnable.call(this, title, fn);
this.pending = !fn;
this.type = 'test';
this.body = (fn || '').toString();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Test#clone copy this one as well?

cc @longlho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - when the new test is created via Test#clone, it'll get the exact same string body https://github.com/danielstjules/mocha/blob/d59cc6c166d0d112a62016909b33e04ed08d2274/lib/test.js#L34

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason why Test#clone doesn't apply this.type = 'test';. It's already handled in the constructor :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right 👍

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the initialization of this.body belong to Runnable's constructor rather than Test?

Right now, if you get an error in a hook, Mocha will bomb, because the Hook object that it tries to process here does not have a body field. Moving the creation of body to Runnable would make both Hook and Test get a body field.

The issue I'm talking about here is fully reproducible with the code provided in this comment. I also am able to reproduce it independently in a test suite of mine (which is why I found the comment and am commenting here).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be resolved by #2115 Thanks! :)

}

/**
Expand Down