Skip to content

Commit

Permalink
Ignore async global errors after spec resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstjules committed Mar 6, 2015
1 parent 4067c06 commit 210803c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ test-failing:
--reporter $(REPORTER) \
test/acceptance/failing > /dev/null 2>&1 ; \
failures="$$?" ; \
if [ "$$failures" != '3' ] ; then \
if [ "$$failures" != '4' ] ; then \
echo 'test-failing:' ; \
echo " expected 3 failing tests but saw $$failures" ; \
echo " expected 4 failing tests but saw $$failures" ; \
exit 1 ; \
fi

Expand Down
7 changes: 3 additions & 4 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,11 @@ Runner.prototype.uncaught = function(err){
var runnable = this.currentRunnable;
if (!runnable) return;

var wasAlreadyDone = runnable.state;
this.fail(runnable, err);

runnable.clearTimeout();

if (wasAlreadyDone) return;
// Ignore errors if complete
if (runnable.state) return;
this.fail(runnable, err);

// recover from test
if ('test' == runnable.type) {
Expand Down
17 changes: 14 additions & 3 deletions test/acceptance/failing/uncaught-and-async.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
'use strict';

/**
* This file should only generate one test error despite the fact that Mocha is
* capable of detecting two distinct exceptions during test execution.
* This file should only generate one failure per spec despite the fact that
* Mocha is capable of detecting two distinct exceptions during test execution.
*/

it('fails exactly once', function(done) {
it('fails exactly once when a global error is thrown first', function(done) {
setTimeout(function() {
throw new Error('global error');

setTimeout(function() {
done(new Error('test error'));
}, 0);
}, 0);
});

it('fails exactly once when a global error is thrown second', function(done) {
setTimeout(function() {
done(new Error('test error'));
}, 0);

setTimeout(function() {
throw new Error('global error');
}, 0);
});

0 comments on commit 210803c

Please sign in to comment.