Skip to content

Commit

Permalink
always halt execution when async skip() called; closes #2465
Browse files Browse the repository at this point in the history
- also fixes lack of support for async `skip()` when `allowUncaught` option is used
- adds some debuggability into `this.skip()` calls
  • Loading branch information
boneskull committed Sep 14, 2016
1 parent 772e50f commit 2806dda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Runnable.prototype.enableTimeouts = function(enabled) {
* @api public
*/
Runnable.prototype.skip = function() {
throw new Pending();
throw new Pending('sync skip');
};

/**
Expand Down Expand Up @@ -298,14 +298,19 @@ Runnable.prototype.run = function(fn) {
if (this.async) {
this.resetTimeout();

// allows skip() to be used in an explicit async context
this.skip = function asyncSkip() {
done(new Pending('async skip call'));
// halt execution. the Runnable will be marked pending
// by the previous call, and the uncaught handler will ignore
// the failure.
throw new Pending('async skip; aborting execution');
};

if (this.allowUncaught) {
return callFnAsync(this.fn);
}
try {
// allows skip() to be used in an explicit async context
this.skip = function() {
done(new Pending());
};
callFnAsync(this.fn);
} catch (err) {
done(utils.getError(err));
Expand Down
6 changes: 4 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ Runner.prototype.hook = function(name, fn) {
suite.tests.forEach(function(test) {
test.pending = true;
});
// a pending hook won't be executed twice.
hook.pending = true;
}
} else {
self.failHook(hook, err);
Expand Down Expand Up @@ -695,8 +697,8 @@ Runner.prototype.uncaught = function(err) {

runnable.clearTimeout();

// Ignore errors if complete
if (runnable.state) {
// Ignore errors if complete or pending
if (runnable.state || runnable.isPending()) {
return;
}
this.fail(runnable, err);
Expand Down

0 comments on commit 2806dda

Please sign in to comment.