Skip to content

Commit

Permalink
deprecate this.skip for after/-Each hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Mar 5, 2019
1 parent 02ca696 commit 75a5651
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ Runner.prototype.hook = function(name, fn) {
}
self.currentRunnable = hook;

if (name === 'beforeAll') {
if (name === HOOK_TYPE_BEFORE_ALL) {
hook.ctx.currentTest = hook.parent.tests[0];
} else if (name === 'afterAll') {
} else if (name === HOOK_TYPE_AFTER_ALL) {
hook.ctx.currentTest = hook.parent.tests[hook.parent.tests.length - 1];
} else {
hook.ctx.currentTest = self.test;
Expand All @@ -386,6 +386,15 @@ Runner.prototype.hook = function(name, fn) {
}
if (err) {
if (err instanceof Pending) {
if (name === HOOK_TYPE_AFTER_EACH || name === HOOK_TYPE_AFTER_ALL) {
utils.deprecate(
util.format(
'skipping a test within an "%s" 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.',
name === HOOK_TYPE_AFTER_EACH ? 'after each' : 'after all'
)
);
}
if (name === HOOK_TYPE_BEFORE_EACH || name === HOOK_TYPE_AFTER_EACH) {
self.test.pending = true;
} else {
Expand Down

0 comments on commit 75a5651

Please sign in to comment.