@@ -96,6 +96,52 @@ exports.Suite = Suite;
9696exports . Hook = require ( './hook' ) ;
9797exports . Test = require ( './test' ) ;
9898
99+ let currentContext ;
100+ exports . afterEach = function ( ...args ) {
101+ ( currentContext . afterEach || currentContext . teardown ) . apply ( this , args ) ;
102+ } ;
103+ exports . after = function ( ...args ) {
104+ ( currentContext . after || currentContext . suiteTeardown ) . apply ( this , args ) ;
105+ } ;
106+ exports . beforeEach = function ( ...args ) {
107+ ( currentContext . beforeEach || currentContext . setup ) . apply ( this , args ) ;
108+ } ;
109+ exports . before = function ( ...args ) {
110+ ( currentContext . before || currentContext . suiteSetup ) . apply ( this , args ) ;
111+ } ;
112+ exports . describe = function ( ...args ) {
113+ ( currentContext . describe || currentContext . suite ) . apply ( this , args ) ;
114+ } ;
115+ exports . describe . only = function ( ...args ) {
116+ ( currentContext . describe || currentContext . suite ) . only . apply ( this , args ) ;
117+ } ;
118+ exports . describe . skip = function ( ...args ) {
119+ ( currentContext . describe || currentContext . suite ) . skip . apply ( this , args ) ;
120+ } ;
121+ exports . it = function ( ...args ) {
122+ ( currentContext . it || currentContext . test ) . apply ( this , args ) ;
123+ } ;
124+ exports . it . only = function ( ...args ) {
125+ ( currentContext . it || currentContext . test ) . only . apply ( this , args ) ;
126+ } ;
127+ exports . it . skip = function ( ...args ) {
128+ (
129+ currentContext . xit ||
130+ ( currentContext . test && currentContext . test . skip )
131+ ) . apply ( this , args ) ;
132+ } ;
133+ exports . xdescribe = exports . describe . skip ;
134+ exports . xit = exports . it . skip ;
135+ exports . setup = exports . beforeEach ;
136+ exports . suiteSetup = exports . before ;
137+ exports . suiteTeardown = exports . after ;
138+ exports . suite = exports . describe ;
139+ exports . teardown = exports . afterEach ;
140+ exports . test = exports . it ;
141+ exports . run = function ( ...args ) {
142+ currentContext . run . apply ( this , args ) ;
143+ } ;
144+
99145/**
100146 * Constructs a new Mocha instance with `options`.
101147 *
@@ -351,20 +397,7 @@ Mocha.prototype.ui = function(ui) {
351397 bindInterface ( this . suite ) ;
352398
353399 this . suite . on ( EVENT_FILE_PRE_REQUIRE , function ( context ) {
354- exports . afterEach = context . afterEach || context . teardown ;
355- exports . after = context . after || context . suiteTeardown ;
356- exports . beforeEach = context . beforeEach || context . setup ;
357- exports . before = context . before || context . suiteSetup ;
358- exports . describe = context . describe || context . suite ;
359- exports . it = context . it || context . test ;
360- exports . xit = context . xit || ( context . test && context . test . skip ) ;
361- exports . setup = context . setup || context . beforeEach ;
362- exports . suiteSetup = context . suiteSetup || context . before ;
363- exports . suiteTeardown = context . suiteTeardown || context . after ;
364- exports . suite = context . suite || context . describe ;
365- exports . teardown = context . teardown || context . afterEach ;
366- exports . test = context . test || context . it ;
367- exports . run = context . run ;
400+ currentContext = context ;
368401 } ) ;
369402
370403 return this ;
@@ -1299,7 +1332,7 @@ Mocha.prototype.hasGlobalTeardownFixtures = function hasGlobalTeardownFixtures()
12991332 * A (sync) function to assert a user-supplied plugin implementation is valid.
13001333 *
13011334 * Defined in a {@link PluginDefinition}.
1302-
1335+
13031336 * @callback PluginValidator
13041337 * @param {* } value - Value to check
13051338 * @this {PluginDefinition}
0 commit comments