☕️ Classic, reliable, trusted test framework for Node.js and the browser
Ignore asynchronous errors after global failure
Mike Pennisi4067c0658e3e
diff --git a/Makefile b/Makefileindex f7542a11..451ba330 100644--- a/Makefile+++ b/Makefile@@ -60,11 +60,11 @@ test-outputs/issue1327/case-out.json: test/regression/issue1327/case.jstest-failing:./bin/mocha \--reporter $(REPORTER) \- test/acceptance/failing/timeout.js > /dev/null 2>&1 ; \+ test/acceptance/failing > /dev/null 2>&1 ; \failures="$$?" ; \- if [ "$$failures" != '2' ] ; then \+ if [ "$$failures" != '3' ] ; then \echo 'test-failing:' ; \- echo " expected 2 failing tests but saw $$failures" ; \+ echo " expected 3 failing tests but saw $$failures" ; \exit 1 ; \fidiff --git a/lib/runnable.js b/lib/runnable.jsindex 7ce2f5cf..6e4803fd 100644--- a/lib/runnable.js+++ b/lib/runnable.js@@ -211,6 +211,10 @@ Runnable.prototype.run = function(fn){var ms = self.timeout();if (self.timedOut) return;if (finished) return multiple(err || self._trace);++ // Discard the resolution if this test has already failed asynchronously+ if (self.state) return;+self.clearTimeout();self.duration = new Date - start;finished = true;diff --git a/test/acceptance/failing/uncaught-and-async.js b/test/acceptance/failing/uncaught-and-async.jsnew file mode 100644index 00000000..531e3dbe--- /dev/null+++ b/test/acceptance/failing/uncaught-and-async.js@@ -0,0 +1,15 @@+'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.+ */++it('fails exactly once', function(done) {+ setTimeout(function() {+ setTimeout(function() {+ done(new Error('test error'));+ }, 0);+ throw new Error('global error');+ }, 0);+});