Skip to content

Commit

Permalink
forbid this.skip within afterAll hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jan 3, 2020
1 parent 24c22be commit c6303a9
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ var sQuote = utils.sQuote;
var stackFilter = utils.stackTraceFilter();
var stringify = utils.stringify;
var type = utils.type;
var createInvalidExceptionError = require('./errors')
.createInvalidExceptionError;
var errors = require('./errors');
var createInvalidExceptionError = errors.createInvalidExceptionError;
var createUnsupportedError = errors.createUnsupportedError;

/**
* Non-enumerable globals.
Expand Down Expand Up @@ -387,12 +388,6 @@ Runner.prototype.hook = function(name, fn) {
}
// conditional skip
if (hook.pending) {
if (name === HOOK_TYPE_AFTER_ALL) {
utils.deprecate(
'Skipping a test within an "after all" hook is DEPRECATED and will throw an exception in a future version of Mocha. ' +
'Use a return statement or other means to abort hook execution.'
);
}
if (name === HOOK_TYPE_AFTER_EACH) {
// TODO define and implement use case
if (self.test) {
Expand All @@ -405,14 +400,18 @@ Runner.prototype.hook = function(name, fn) {
self.emit(constants.EVENT_HOOK_END, hook);
hook.pending = false; // activates hook for next test
return fn(new Error('abort hookDown'));
} else {
// TODO throw error for afterAll
} else if (name === HOOK_TYPE_BEFORE_ALL) {
suite.tests.forEach(function(test) {
test.pending = true;
});
suite.suites.forEach(function(suite) {
suite.pending = true;
});
} else {
hook.pending = false;
var errForbid = createUnsupportedError('`this.skip` forbidden');
self.failHook(hook, errForbid);
return fn(errForbid);
}
} else if (err) {
self.failHook(hook, err);
Expand Down

0 comments on commit c6303a9

Please sign in to comment.