Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node support for --allow-uncaught #2697

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion bin/_mocha
Expand Up @@ -107,7 +107,8 @@ program
.option('--trace-deprecation', 'show stack traces on deprecations')
.option('--use_strict', 'enforce strict mode')
.option('--watch-extensions <ext>,...', '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';

Expand Down Expand Up @@ -313,6 +314,12 @@ if (program.delay) {
mocha.delay();
}

// --allow-uncaught

if (program.allowUncaught) {
mocha.allowUncaught();
}

// --globals

mocha.globals(globals);
Expand Down
7 changes: 5 additions & 2 deletions lib/runnable.js
Expand Up @@ -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;
}

Expand Down
7 changes: 3 additions & 4 deletions lib/runner.js
Expand Up @@ -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);
Expand Down