@@ -118,19 +118,25 @@ Test.prototype = {
118
118
119
119
// ensure the callbacks are executed serially for each module
120
120
var callbackPromises = notStartedModules . reduce ( ( promiseChain , startModule ) => {
121
- return promiseChain . then ( ( ) => {
121
+ const moduleStartCallback = ( ) => {
122
122
startModule . stats = { all : 0 , bad : 0 , started : now ( ) } ;
123
123
emit ( "suiteStart" , startModule . suiteReport . start ( true ) ) ;
124
124
return runLoggingCallbacks ( "moduleStart" , {
125
125
name : startModule . name ,
126
126
tests : startModule . tests
127
127
} ) ;
128
- } ) ;
128
+ } ;
129
+
130
+ return promiseChain . then ( moduleStartCallback , moduleStartCallback ) ;
129
131
} , Promise . resolve ( [ ] ) ) ;
130
132
131
- return callbackPromises . then ( ( ) => {
133
+ const testStartHandler = ( ) => {
132
134
config . current = this ;
133
-
135
+ const testStartResolvedHandler = ( ) => {
136
+ if ( ! config . pollution ) {
137
+ saveGlobal ( ) ;
138
+ }
139
+ } ;
134
140
this . testEnvironment = extend ( { } , module . testEnvironment ) ;
135
141
136
142
this . started = now ( ) ;
@@ -140,10 +146,16 @@ Test.prototype = {
140
146
module : module . name ,
141
147
testId : this . testId ,
142
148
previousFailure : this . previousFailure
143
- } ) . then ( ( ) => {
144
- if ( ! config . pollution ) {
145
- saveGlobal ( ) ;
146
- }
149
+ } ) . then ( testStartResolvedHandler , function ( err ) {
150
+ setTimeout ( testStartResolvedHandler ) ;
151
+ throw err ;
152
+ } ) ;
153
+ } ;
154
+
155
+ return callbackPromises . then ( testStartHandler , ( err ) => {
156
+ return Promise . reject ( err ) . catch ( ( err ) => {
157
+ setTimeout ( testStartHandler ) ;
158
+ throw err ;
147
159
} ) ;
148
160
} ) ;
149
161
} ,
@@ -319,23 +331,7 @@ Test.prototype = {
319
331
emit ( "testEnd" , this . testReport . end ( true ) ) ;
320
332
this . testReport . slimAssertions ( ) ;
321
333
322
- return runLoggingCallbacks ( "testDone" , {
323
- name : testName ,
324
- module : moduleName ,
325
- skipped : skipped ,
326
- todo : todo ,
327
- failed : bad ,
328
- passed : this . assertions . length - bad ,
329
- total : this . assertions . length ,
330
- runtime : skipped ? 0 : this . runtime ,
331
-
332
- // HTML Reporter use
333
- assertions : this . assertions ,
334
- testId : this . testId ,
335
-
336
- // Source of Test
337
- source : this . stack
338
- } ) . then ( function ( ) {
334
+ const testDoneResolvedHandler = function ( ) {
339
335
if ( module . testsRun === numberOfTests ( module ) ) {
340
336
const completedModules = [ module ] ;
341
337
@@ -353,8 +349,35 @@ Test.prototype = {
353
349
} ) ;
354
350
} , Promise . resolve ( [ ] ) ) ;
355
351
}
356
- } ) . then ( function ( ) {
352
+ } ;
353
+
354
+ return runLoggingCallbacks ( "testDone" , {
355
+ name : testName ,
356
+ module : moduleName ,
357
+ skipped : skipped ,
358
+ todo : todo ,
359
+ failed : bad ,
360
+ passed : this . assertions . length - bad ,
361
+ total : this . assertions . length ,
362
+ runtime : skipped ? 0 : this . runtime ,
363
+
364
+ // HTML Reporter use
365
+ assertions : this . assertions ,
366
+ testId : this . testId ,
367
+
368
+ // Source of Test
369
+ source : this . stack
370
+ } ) . then (
371
+ testDoneResolvedHandler ,
372
+ function ( err ) {
373
+ setTimeout ( testDoneResolvedHandler ) ;
374
+ throw err ;
375
+ }
376
+ ) . then ( function ( ) {
377
+ config . current = undefined ;
378
+ } , function ( err ) {
357
379
config . current = undefined ;
380
+ throw err ;
358
381
} ) ;
359
382
360
383
function logSuiteEnd ( module ) {
@@ -660,7 +683,6 @@ function checkPollution() {
660
683
if ( newGlobals . length > 0 ) {
661
684
pushFailure ( "Introduced global variable(s): " + newGlobals . join ( ", " ) ) ;
662
685
}
663
-
664
686
deletedGlobals = diff ( old , config . pollution ) ;
665
687
if ( deletedGlobals . length > 0 ) {
666
688
pushFailure ( "Deleted global variable(s): " + deletedGlobals . join ( ", " ) ) ;
0 commit comments