@@ -177,84 +177,102 @@ export default function(j$) {
177
177
return j$ . testPath ;
178
178
} ,
179
179
} ) ;
180
- defaultResourcesForRunnable ( topSuite . id ) ;
180
+
181
181
currentDeclarationSuite = topSuite ;
182
182
183
183
this . topSuite = function ( ) {
184
184
return topSuite ;
185
185
} ;
186
186
187
- this . execute = async function ( runnablesToRun ) {
188
- if ( ! runnablesToRun ) {
189
- if ( focusedRunnables . length ) {
190
- runnablesToRun = focusedRunnables ;
191
- } else {
192
- runnablesToRun = [ topSuite . id ] ;
193
- }
187
+ const uncaught = err => {
188
+ if ( currentSpec ) {
189
+ currentSpec . onException ( err ) ;
190
+ currentSpec . cancel ( ) ;
191
+ } else {
192
+ console . error ( 'Unhandled error' ) ;
193
+ console . error ( err . stack ) ;
194
194
}
195
+ } ;
195
196
196
- const uncaught = err => {
197
- if ( currentSpec ) {
198
- currentSpec . onException ( err ) ;
199
- currentSpec . cancel ( ) ;
200
- } else {
201
- console . error ( 'Unhandled error' ) ;
202
- console . error ( err . stack ) ;
203
- }
204
- } ;
205
-
197
+ let oldListenersException ;
198
+ let oldListenersRejection ;
199
+ const executionSetup = function ( ) {
206
200
// Need to ensure we are the only ones handling these exceptions.
207
- const oldListenersException = process
208
- . listeners ( 'uncaughtException' )
209
- . slice ( ) ;
210
- const oldListenersRejection = process
211
- . listeners ( 'unhandledRejection' )
212
- . slice ( ) ;
201
+ oldListenersException = process . listeners ( 'uncaughtException' ) . slice ( ) ;
202
+ oldListenersRejection = process . listeners ( 'unhandledRejection' ) . slice ( ) ;
213
203
214
204
j$ . process . removeAllListeners ( 'uncaughtException' ) ;
215
205
j$ . process . removeAllListeners ( 'unhandledRejection' ) ;
216
206
217
207
j$ . process . on ( 'uncaughtException' , uncaught ) ;
218
208
j$ . process . on ( 'unhandledRejection' , uncaught ) ;
209
+ } ;
210
+
211
+ const executionTeardown = function ( ) {
212
+ j$ . process . removeListener ( 'uncaughtException' , uncaught ) ;
213
+ j$ . process . removeListener ( 'unhandledRejection' , uncaught ) ;
214
+
215
+ // restore previous exception handlers
216
+ oldListenersException . forEach ( listener => {
217
+ j$ . process . on ( 'uncaughtException' , listener ) ;
218
+ } ) ;
219
+
220
+ oldListenersRejection . forEach ( listener => {
221
+ j$ . process . on ( 'unhandledRejection' , listener ) ;
222
+ } ) ;
223
+ } ;
224
+
225
+ this . execute = async function ( runnablesToRun , suiteTree = topSuite ) {
226
+ if ( ! runnablesToRun ) {
227
+ if ( focusedRunnables . length ) {
228
+ runnablesToRun = focusedRunnables ;
229
+ } else {
230
+ runnablesToRun = [ suiteTree . id ] ;
231
+ }
232
+ }
219
233
220
- reporter . jasmineStarted ( { totalSpecsDefined} ) ;
234
+ if ( currentlyExecutingSuites . length === 0 ) {
235
+ executionSetup ( ) ;
236
+ }
221
237
222
- currentlyExecutingSuites . push ( topSuite ) ;
238
+ const lastDeclarationSuite = currentDeclarationSuite ;
223
239
224
240
await treeProcessor ( {
225
241
nodeComplete ( suite ) {
226
242
if ( ! suite . disabled ) {
227
243
clearResourcesForRunnable ( suite . id ) ;
228
244
}
229
245
currentlyExecutingSuites . pop ( ) ;
230
- reporter . suiteDone ( suite . getResult ( ) ) ;
246
+ if ( suite === topSuite ) {
247
+ reporter . jasmineDone ( {
248
+ failedExpectations : topSuite . result . failedExpectations ,
249
+ } ) ;
250
+ } else {
251
+ reporter . suiteDone ( suite . getResult ( ) ) ;
252
+ }
231
253
} ,
232
254
nodeStart ( suite ) {
233
255
currentlyExecutingSuites . push ( suite ) ;
234
- defaultResourcesForRunnable ( suite . id , suite . parentSuite . id ) ;
235
- reporter . suiteStarted ( suite . result ) ;
256
+ defaultResourcesForRunnable (
257
+ suite . id ,
258
+ suite . parentSuite && suite . parentSuite . id ,
259
+ ) ;
260
+ if ( suite === topSuite ) {
261
+ reporter . jasmineStarted ( { totalSpecsDefined} ) ;
262
+ } else {
263
+ reporter . suiteStarted ( suite . result ) ;
264
+ }
236
265
} ,
237
266
queueRunnerFactory,
238
267
runnableIds : runnablesToRun ,
239
- tree : topSuite ,
268
+ tree : suiteTree ,
240
269
} ) ;
241
- clearResourcesForRunnable ( topSuite . id ) ;
242
- currentlyExecutingSuites . pop ( ) ;
243
- reporter . jasmineDone ( {
244
- failedExpectations : topSuite . result . failedExpectations ,
245
- } ) ;
246
-
247
- j$ . process . removeListener ( 'uncaughtException' , uncaught ) ;
248
- j$ . process . removeListener ( 'unhandledRejection' , uncaught ) ;
249
270
250
- // restore previous exception handlers
251
- oldListenersException . forEach ( listener => {
252
- j$ . process . on ( 'uncaughtException' , listener ) ;
253
- } ) ;
271
+ currentDeclarationSuite = lastDeclarationSuite ;
254
272
255
- oldListenersRejection . forEach ( listener => {
256
- j$ . process . on ( 'unhandledRejection' , listener ) ;
257
- } ) ;
273
+ if ( currentlyExecutingSuites . length === 0 ) {
274
+ executionTeardown ( ) ;
275
+ }
258
276
} ;
259
277
260
278
this . addReporter = function ( reporterToAdd ) {
0 commit comments