@@ -96,6 +96,52 @@ exports.Suite = Suite;
96
96
exports . Hook = require ( './hook' ) ;
97
97
exports . Test = require ( './test' ) ;
98
98
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
+
99
145
/**
100
146
* Constructs a new Mocha instance with `options`.
101
147
*
@@ -351,20 +397,7 @@ Mocha.prototype.ui = function(ui) {
351
397
bindInterface ( this . suite ) ;
352
398
353
399
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 ;
368
401
} ) ;
369
402
370
403
return this ;
@@ -1299,7 +1332,7 @@ Mocha.prototype.hasGlobalTeardownFixtures = function hasGlobalTeardownFixtures()
1299
1332
* A (sync) function to assert a user-supplied plugin implementation is valid.
1300
1333
*
1301
1334
* Defined in a {@link PluginDefinition}.
1302
-
1335
+
1303
1336
* @callback PluginValidator
1304
1337
* @param {* } value - Value to check
1305
1338
* @this {PluginDefinition}
0 commit comments