☕️ Classic, reliable, trusted test framework for Node.js and the browser
Fix #1417: Show actual error, not 'multiple calls to done()'
Frank Leon Rose2c52377da981
diff --git a/lib/runnable.js b/lib/runnable.jsindex 9ac45de3..82f3dfa4 100644--- a/lib/runnable.js+++ b/lib/runnable.js@@ -289,6 +289,7 @@ Runnable.prototype.run = function(fn) {try {callFnAsync(this.fn);} catch (err) {+ emitted = true;done(utils.getError(err));}return;@@ -308,6 +309,7 @@ Runnable.prototype.run = function(fn) {callFn(this.fn);}} catch (err) {+ emitted = true;done(utils.getError(err));}diff --git a/test/integration/fixtures/regression/issue-1417.js b/test/integration/fixtures/regression/issue-1417.jsnew file mode 100644index 00000000..fee75eaa--- /dev/null+++ b/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');+});diff --git a/test/integration/regression.js b/test/integration/regression.jsindex f20f601e..31ddd6ea 100644--- a/test/integration/regression.js+++ b/test/integration/regression.js@@ -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);@@ -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();+ });+ });});