@@ -359,17 +359,19 @@ type AfterEachInjectedSuite = {
359
359
} ;
360
360
361
361
/**
362
- * Registers an after (all or each) hook to kill test shells started during the hooks or tests
362
+ * Registers an after (all or each) hook to kill test shells started during the hooks or tests.
363
+ * You don't have to call this from tests, but you can if you want to register an after (each) hook
364
+ * which runs after the shells have been killed.
363
365
*/
364
- function ensureAfterHook (
366
+ export function ensureTestShellAfterHook (
365
367
hookName : 'afterEach' ,
366
368
suite : Mocha . Suite
367
369
) : asserts suite is AfterEachInjectedSuite & Mocha . Suite ;
368
- function ensureAfterHook (
370
+ export function ensureTestShellAfterHook (
369
371
hookName : 'afterAll' ,
370
372
suite : Mocha . Suite
371
373
) : asserts suite is AfterAllInjectedSuite & Mocha . Suite ;
372
- function ensureAfterHook (
374
+ export function ensureTestShellAfterHook (
373
375
hookName : 'afterEach' | 'afterAll' ,
374
376
suite : Partial < AfterAllInjectedSuite & AfterEachInjectedSuite > & Mocha . Suite
375
377
) : void {
@@ -409,19 +411,19 @@ Mocha.Context.prototype.startTestShell = function (
409
411
runnable . originalTitle === '"before each" hook' ||
410
412
runnable . originalTitle === '"after each" hook'
411
413
) {
412
- ensureAfterHook ( 'afterEach' , parent ) ;
414
+ ensureTestShellAfterHook ( 'afterEach' , parent ) ;
413
415
parent [ TEST_SHELLS_AFTER_EACH ] . add ( shell ) ;
414
416
} else if (
415
417
runnable . originalTitle === '"before all" hook' ||
416
418
runnable . originalTitle === '"after all" hook'
417
419
) {
418
- ensureAfterHook ( 'afterAll' , parent ) ;
420
+ ensureTestShellAfterHook ( 'afterAll' , parent ) ;
419
421
parent [ TEST_SHELLS_AFTER_ALL ] . add ( shell ) ;
420
422
} else {
421
423
throw new Error ( `Unexpected ${ runnable . originalTitle || runnable . title } ` ) ;
422
424
}
423
425
} else if ( runnable instanceof Mocha . Test ) {
424
- ensureAfterHook ( 'afterEach' , parent ) ;
426
+ ensureTestShellAfterHook ( 'afterEach' , parent ) ;
425
427
parent [ TEST_SHELLS_AFTER_EACH ] . add ( shell ) ;
426
428
} else {
427
429
throw new Error ( 'Unexpected Runnable: Expected a Hook or a Test' ) ;
0 commit comments