Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit c3bdb56

Browse files
committed
Merge branch 'fix-1417-multiple-done-calls' of https://github.com/frankleonrose/mocha into pull/2059
* 'fix-1417-multiple-done-calls' of https://github.com/frankleonrose/mocha: Fix mochajs#1417: Show actual error, not 'multiple calls to done()' # Conflicts: # test/integration/regression.js
2 parents 5797eca + 2c52377 commit c3bdb56

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

lib/runnable.js

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ Runnable.prototype.run = function(fn) {
313313
try {
314314
callFnAsync(this.fn);
315315
} catch (err) {
316+
emitted = true;
316317
done(utils.getError(err));
317318
}
318319
return;
@@ -332,6 +333,7 @@ Runnable.prototype.run = function(fn) {
332333
callFn(this.fn);
333334
}
334335
} catch (err) {
336+
emitted = true;
335337
done(utils.getError(err));
336338
}
337339

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
/**
4+
* This file should generate only one failure per spec for the thrown error.
5+
* It should not report misleading 'multiple calls to done()'.
6+
*/
7+
8+
it('fails exactly once when a global error is thrown synchronously and done errors', function(done) {
9+
setTimeout(function() {
10+
done(new Error('test error'));
11+
}, 1); // Not 0 - it will 'succeed', but won't test the breaking condition
12+
13+
throw new Error('sync error');
14+
});
15+
16+
it('fails exactly once when a global error is thrown synchronously and done completes', function(done) {
17+
setTimeout(function() {
18+
done();
19+
}, 1); // Not 0 - it will 'succeed', but won't test the breaking condition
20+
21+
throw new Error('sync error');
22+
});

test/integration/regression.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,22 @@ describe('regressions', function() {
9494
assert.equal(res.code, 0);
9595
});
9696
});
97+
98+
it('issue-1417 uncaught exceptions from async specs', function(done) {
99+
runJSON('regression/issue-1417.js', [], function(err, res) {
100+
assert(!err);
101+
assert.equal(res.stats.pending, 0);
102+
assert.equal(res.stats.passes, 0);
103+
assert.equal(res.stats.failures, 2);
104+
105+
assert.equal(res.failures[0].title,
106+
'fails exactly once when a global error is thrown synchronously and done errors');
107+
assert.equal(res.failures[0].err.message, 'sync error');
108+
assert.equal(res.failures[1].title,
109+
'fails exactly once when a global error is thrown synchronously and done completes');
110+
assert.equal(res.failures[1].err.message, 'sync error');
111+
assert.equal(res.code, 2);
112+
done();
113+
});
114+
});
97115
});

0 commit comments

Comments
 (0)