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 Feb 11, 2019
1 parent 186ca36 commit 9d98ff8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var EventEmitter = require('events').EventEmitter;
var format = require('util').format;
var Pending = require('./pending');
var utils = require('./utils');
var inherits = utils.inherits;
Expand Down Expand Up @@ -355,9 +356,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 @@ -378,7 +379,15 @@ Runner.prototype.hook = function(name, fn) {
}
if (err) {
if (err instanceof Pending) {
if (name === HOOK_TYPE_BEFORE_EACH || name === HOOK_TYPE_AFTER_EACH) {
if (name === HOOK_TYPE_AFTER_EACH || name === HOOK_TYPE_AFTER_ALL) {
utils.deprecate(
format(
"skipping a test within an '%s' hook is DEPRECATED and will be removed from a future version of Mocha. " +
"Use 'return' instead to exit hook abortively.",
name
)
);
} else if (name === HOOK_TYPE_BEFORE_EACH) {
self.test.pending = true;
} else {
suite.tests.forEach(function(test) {
Expand Down

0 comments on commit 9d98ff8

Please sign in to comment.