Skip to content

Commit

Permalink
Merge branch 'fix-1417-multiple-done-calls' of https://github.com/fra…
Browse files Browse the repository at this point in the history
…nkleonrose/mocha into pull/2059

* 'fix-1417-multiple-done-calls' of https://github.com/frankleonrose/mocha:
  Fix #1417: Show actual error, not 'multiple calls to done()'

# Conflicts:
#	test/integration/regression.js
  • Loading branch information
boneskull committed Oct 10, 2016
2 parents 9915dfb + 2c52377 commit a40f28d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/runnable.js
Expand Up @@ -313,6 +313,7 @@ Runnable.prototype.run = function(fn) {
try {
callFnAsync(this.fn);
} catch (err) {
emitted = true;
done(utils.getError(err));
}
return;
Expand All @@ -332,6 +333,7 @@ Runnable.prototype.run = function(fn) {
callFn(this.fn);
}
} catch (err) {
emitted = true;
done(utils.getError(err));
}

Expand Down
22 changes: 22 additions & 0 deletions test/integration/fixtures/regression/issue-1417.js
@@ -0,0 +1,22 @@
'use strict';

/**
* This file should generate only one failure per spec for the thrown error.
* It should not report misleading 'multiple calls to done()'.
*/

it('fails exactly once when a global error is thrown synchronously and done errors', function(done) {
setTimeout(function() {
done(new Error('test error'));
}, 1); // Not 0 - it will 'succeed', but won't test the breaking condition

throw new Error('sync error');
});

it('fails exactly once when a global error is thrown synchronously and done completes', function(done) {
setTimeout(function() {
done();
}, 1); // Not 0 - it will 'succeed', but won't test the breaking condition

throw new Error('sync error');
});
18 changes: 18 additions & 0 deletions test/integration/regression.spec.js
Expand Up @@ -94,4 +94,22 @@ describe('regressions', function() {
assert.equal(res.code, 0);
});
});

it('issue-1417 uncaught exceptions from async specs', function(done) {
runJSON('regression/issue-1417.js', [], function(err, res) {
assert(!err);
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.failures, 2);

assert.equal(res.failures[0].title,
'fails exactly once when a global error is thrown synchronously and done errors');
assert.equal(res.failures[0].err.message, 'sync error');
assert.equal(res.failures[1].title,
'fails exactly once when a global error is thrown synchronously and done completes');
assert.equal(res.failures[1].err.message, 'sync error');
assert.equal(res.code, 2);
done();
});
});
});

0 comments on commit a40f28d

Please sign in to comment.