From dae3428f8ed7f05ddd111021f6d4a8d53c601fd4 Mon Sep 17 00:00:00 2001 From: Laurence Rowe Date: Tue, 31 Jan 2017 19:26:05 -0800 Subject: [PATCH 1/3] Avoid calling done() twice. --- lib/runnable.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/runnable.js b/lib/runnable.js index e7b6aa12f0..ee8c4a3467 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -324,8 +324,11 @@ Runnable.prototype.run = function (fn) { } if (this.allowUncaught) { - callFn(this.fn); - done(); + if (this.isPending()) { + done(); + } else { + callFn(this.fn); + } return; } From f76afbc489ba38a9d3a415b75c921b121b4b3afe Mon Sep 17 00:00:00 2001 From: Laurence Rowe Date: Tue, 31 Jan 2017 19:26:25 -0800 Subject: [PATCH 2/3] Setup error handler when allowUncaught. --- lib/runner.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index 1d3dd959da..b024e0dcb5 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -432,15 +432,14 @@ Runner.prototype.runTest = function (fn) { if (this.asyncOnly) { test.asyncOnly = true; } - + test.on('error', function (err) { + self.fail(test, err); + }); if (this.allowUncaught) { test.allowUncaught = true; return test.run(fn); } try { - test.on('error', function (err) { - self.fail(test, err); - }); test.run(fn); } catch (err) { fn(err); From 0ab531049babe9e10291ddf1bb1b1856b45f4e87 Mon Sep 17 00:00:00 2001 From: Laurence Rowe Date: Tue, 31 Jan 2017 19:40:46 -0800 Subject: [PATCH 3/3] --allow-uncaught cli option --- bin/_mocha | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/_mocha b/bin/_mocha index 61aac40d3a..bfc189f912 100755 --- a/bin/_mocha +++ b/bin/_mocha @@ -107,7 +107,8 @@ program .option('--trace-deprecation', 'show stack traces on deprecations') .option('--use_strict', 'enforce strict mode') .option('--watch-extensions ,...', 'additional extensions to monitor with --watch', list, []) - .option('--delay', 'wait for async suite definition'); + .option('--delay', 'wait for async suite definition') + .option('--allow-uncaught', 'enable uncaught errors to propagate'); program._name = 'mocha'; @@ -313,6 +314,12 @@ if (program.delay) { mocha.delay(); } +// --allow-uncaught + +if (program.allowUncaught) { + mocha.allowUncaught(); +} + // --globals mocha.globals(globals);