Skip to content

Commit

Permalink
Fix #1417: Show actual error, not 'multiple calls to done()'
Browse files Browse the repository at this point in the history
  • Loading branch information
frankleonrose committed Jan 20, 2016
1 parent b64d76c commit 2c52377
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/runnable.js
Expand Up @@ -289,6 +289,7 @@ Runnable.prototype.run = function(fn) {
try {
callFnAsync(this.fn);
} catch (err) {
emitted = true;
done(utils.getError(err));
}
return;
Expand All @@ -308,6 +309,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');
});
19 changes: 19 additions & 0 deletions test/integration/regression.js
Expand Up @@ -2,6 +2,7 @@ var assert = require('assert');
var fs = require('fs');
var path = require('path');
var run = require('./helpers').runMocha;
var runJSON = require('./helpers').runMochaJSON;

describe('regressions', function() {
this.timeout(1000);
Expand Down Expand Up @@ -50,4 +51,22 @@ describe('regressions', function() {
done();
});
})

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 2c52377

Please sign in to comment.