@@ -311,23 +311,43 @@ class TestContext {
311
311
}
312
312
313
313
before ( fn , options ) {
314
- this . #test
315
- . createHook ( 'before' , fn , { __proto__ : null , ...options , hookType : 'before' , loc : getCallerLocation ( ) } ) ;
314
+ this . #test. createHook ( 'before' , fn , {
315
+ __proto__ : null ,
316
+ ...options ,
317
+ parent : this . #test,
318
+ hookType : 'before' ,
319
+ loc : getCallerLocation ( ) ,
320
+ } ) ;
316
321
}
317
322
318
323
after ( fn , options ) {
319
- this . #test
320
- . createHook ( 'after' , fn , { __proto__ : null , ...options , hookType : 'after' , loc : getCallerLocation ( ) } ) ;
324
+ this . #test. createHook ( 'after' , fn , {
325
+ __proto__ : null ,
326
+ ...options ,
327
+ parent : this . #test,
328
+ hookType : 'after' ,
329
+ loc : getCallerLocation ( ) ,
330
+ } ) ;
321
331
}
322
332
323
333
beforeEach ( fn , options ) {
324
- this . #test
325
- . createHook ( 'beforeEach' , fn , { __proto__ : null , ...options , hookType : 'beforeEach' , loc : getCallerLocation ( ) } ) ;
334
+ this . #test. createHook ( 'beforeEach' , fn , {
335
+ __proto__ : null ,
336
+ ...options ,
337
+ parent : this . #test,
338
+ hookType : 'beforeEach' ,
339
+ loc : getCallerLocation ( ) ,
340
+ } ) ;
326
341
}
327
342
328
343
afterEach ( fn , options ) {
329
- this . #test
330
- . createHook ( 'afterEach' , fn , { __proto__ : null , ...options , hookType : 'afterEach' , loc : getCallerLocation ( ) } ) ;
344
+ this . #test. createHook ( 'afterEach' , fn , {
345
+ __proto__ : null ,
346
+ ...options ,
347
+ parent : this . #test,
348
+ hookType : 'afterEach' ,
349
+ loc : getCallerLocation ( ) ,
350
+ } ) ;
331
351
}
332
352
}
333
353
@@ -1089,14 +1109,17 @@ class Test extends AsyncResource {
1089
1109
class TestHook extends Test {
1090
1110
#args;
1091
1111
constructor ( fn , options ) {
1092
- if ( options === null || typeof options !== 'object' ) {
1093
- options = kEmptyObject ;
1094
- }
1095
- const { loc, timeout, signal } = options ;
1096
- super ( { __proto__ : null , fn, loc, timeout, signal } ) ;
1097
-
1098
- this . parentTest = options . parent ?? null ;
1099
- this . hookType = options . hookType ;
1112
+ const { hookType, loc, parent, timeout, signal } = options ;
1113
+ super ( {
1114
+ __proto__ : null ,
1115
+ fn,
1116
+ loc,
1117
+ timeout,
1118
+ signal,
1119
+ harness : parent . root . harness ,
1120
+ } ) ;
1121
+ this . parentTest = parent ;
1122
+ this . hookType = hookType ;
1100
1123
}
1101
1124
run ( args ) {
1102
1125
if ( this . error && ! this . outerSignal ?. aborted ) {
@@ -1120,9 +1143,7 @@ class TestHook extends Test {
1120
1143
const { error, loc, parentTest : parent } = this ;
1121
1144
1122
1145
// Report failures in the root test's after() hook.
1123
- if ( error && parent !== null &&
1124
- parent === parent . root && this . hookType === 'after' ) {
1125
-
1146
+ if ( error && parent === parent . root && this . hookType === 'after' ) {
1126
1147
if ( isTestFailureError ( error ) ) {
1127
1148
error . failureType = kHookFailure ;
1128
1149
}
0 commit comments