Skip to content

Commit

Permalink
always halt execution when async skip() called; closes #2465 (#2479)
Browse files Browse the repository at this point in the history
- always halt execution when async skip() called; closes #2465
- also fixes lack of support for async `skip()` when `allowUncaught` option is used
- adds some debuggability into `this.skip()` calls
- avoid double-failure conditions when using this.skip()
- fix bad Runner tests; lint & add test/runner.js to check
  • Loading branch information
boneskull authored Sep 16, 2016
1 parent 539255c commit 5e1cd44
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 157 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
lib/to-iso-string/
test/**/*
!test/runner.js
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ clean:

lint:
@printf "==> [Test :: Lint]\n"
$(ESLINT) browser-entry.js index.js karma.conf.js bin/mocha bin/_mocha "lib/**/*.js" "scripts/**/*.js"
$(ESLINT) browser-entry.js index.js karma.conf.js bin/mocha bin/_mocha "lib/**/*.js" "scripts/**/*.js" test

test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-glob test-requires test-reporters test-only test-global-only

Expand Down
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
10 changes: 8 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ Runner.prototype.checkGlobals = function(test) {
* @param {Error} err
*/
Runner.prototype.fail = function(test, err) {
if (test.isPending()) {
return;
}

++this.failures;
test.state = 'failed';

Expand Down Expand Up @@ -309,6 +313,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 +701,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
Loading

0 comments on commit 5e1cd44

Please sign in to comment.