Skip to content

Commit

Permalink
Fix HTML reporting display to show errors if done is called multiple …
Browse files Browse the repository at this point in the history
…times, or if an exception is thrown after done is called.
  • Loading branch information
Standard8 committed Dec 16, 2015
1 parent 67d0fac commit ae4fbca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ function HTML(runner) {
});

runner.on('fail', function(test) {
if (test.type === 'hook') {
// For type = 'test' its possible that the test failed due to multiple
// done() calls. So report the issue here.
if (test.type === 'hook'
|| test.type === 'test') {
runner.emit('test end', test);
}
});
Expand Down
1 change: 1 addition & 0 deletions test/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<script src="array.js"></script>
<script src="../acceptance/duration.js"></script>
<script src="../acceptance/timeout.js"></script>
<script src="multiple-done.js"></script>
<script>
onload = function(){
mocha.checkLeaks();
Expand Down
16 changes: 16 additions & 0 deletions test/browser/multiple-done.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('Multiple Done calls', function(){
it('should report an error if done was called more than once', function(done){
done();
done();
})

it('should report an error if an exception happened async after done was called', function (done) {
done();
setTimeout(done, 50);
})

it('should report an error if an exception happened after done was called', function(done){
done();
throw new Error("thrown error");
})
})

1 comment on commit ae4fbca

@mckoss
Copy link

@mckoss mckoss commented on ae4fbca Feb 12, 2016

Choose a reason for hiding this comment

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

The extra emit('test end') is causing all errors to be double-reported.

Please sign in to comment.