66 Promise,
77 PromiseResolve,
88 PromiseWithResolvers,
9- SafeMap,
109 SafePromiseAllReturnVoid,
1110} = primordials ;
1211const { getCallerLocation } = internalBinding ( 'util' ) ;
13- const {
14- createHook,
15- executionAsyncId,
16- } = require ( 'async_hooks' ) ;
1712const { relative } = require ( 'path' ) ;
1813const {
1914 codes : {
@@ -26,6 +21,7 @@ const {
2621 parseCommandLine,
2722 reporterScope,
2823 shouldColorizeTestFiles,
24+ testStorage,
2925 setupGlobalSetupTeardownFunctions,
3026 parsePreviousRuns,
3127} = require ( 'internal/test_runner/utils' ) ;
@@ -35,12 +31,9 @@ const { queueMicrotask } = require('internal/process/task_queues');
3531const { TIMEOUT_MAX } = require ( 'internal/timers' ) ;
3632const { clearInterval, setImmediate, setInterval } = require ( 'timers' ) ;
3733const { bigint : hrtime } = process . hrtime ;
38- const testResources = new SafeMap ( ) ;
3934let globalRoot ;
4035let globalSetupExecuted = false ;
4136
42- testResources . set ( reporterScope . asyncId ( ) , reporterScope ) ;
43-
4437function createTestTree ( rootTestOptions , globalOptions ) {
4538 const buildPhaseDeferred = PromiseWithResolvers ( ) ;
4639 const isFilteringByName = globalOptions . testNamePatterns ||
@@ -124,7 +117,7 @@ function createProcessEventHandler(eventName, rootTest) {
124117 throw err ;
125118 }
126119
127- const test = testResources . get ( executionAsyncId ( ) ) ;
120+ const test = testStorage . getStore ( ) ;
128121
129122 // Check if this error is coming from a reporter. If it is, throw it.
130123 if ( test === reporterScope ) {
@@ -230,27 +223,6 @@ function setupFailureStateFile(rootTest, globalOptions) {
230223}
231224
232225function setupProcessState ( root , globalOptions ) {
233- const hook = createHook ( {
234- __proto__ : null ,
235- init ( asyncId , type , triggerAsyncId , resource ) {
236- if ( resource instanceof Test ) {
237- testResources . set ( asyncId , resource ) ;
238- return ;
239- }
240-
241- const parent = testResources . get ( triggerAsyncId ) ;
242-
243- if ( parent !== undefined ) {
244- testResources . set ( asyncId , parent ) ;
245- }
246- } ,
247- destroy ( asyncId ) {
248- testResources . delete ( asyncId ) ;
249- } ,
250- } ) ;
251-
252- hook . enable ( ) ;
253-
254226 const exceptionHandler =
255227 createProcessEventHandler ( 'uncaughtException' , root ) ;
256228 const rejectionHandler =
@@ -282,7 +254,6 @@ function setupProcessState(root, globalOptions) {
282254 root . harness . globalTeardownFunction = null ;
283255 }
284256
285- hook . disable ( ) ;
286257 process . removeListener ( 'uncaughtException' , exceptionHandler ) ;
287258 process . removeListener ( 'unhandledRejection' , rejectionHandler ) ;
288259 process . removeListener ( 'beforeExit' , exitHandler ) ;
@@ -389,7 +360,7 @@ async function startSubtestAfterBootstrap(subtest) {
389360
390361function runInParentContext ( Factory ) {
391362 function run ( name , options , fn , overrides ) {
392- const parent = testResources . get ( executionAsyncId ( ) ) || lazyBootstrapRoot ( ) ;
363+ const parent = testStorage . getStore ( ) || lazyBootstrapRoot ( ) ;
393364 const subtest = parent . createSubtest ( Factory , name , options , fn , overrides ) ;
394365 if ( parent instanceof Suite ) {
395366 return PromiseResolve ( ) ;
@@ -422,7 +393,7 @@ function runInParentContext(Factory) {
422393
423394function hook ( hook ) {
424395 return ( fn , options ) => {
425- const parent = testResources . get ( executionAsyncId ( ) ) || lazyBootstrapRoot ( ) ;
396+ const parent = testStorage . getStore ( ) || lazyBootstrapRoot ( ) ;
426397 parent . createHook ( hook , fn , {
427398 __proto__ : null ,
428399 ...options ,
@@ -434,7 +405,7 @@ function hook(hook) {
434405}
435406
436407function getTestContext ( ) {
437- const test = testResources . get ( executionAsyncId ( ) ) ;
408+ const test = testStorage . getStore ( ) ;
438409 // Exclude the reporter sentinel
439410 if ( test === undefined || test === reporterScope ) {
440411 return undefined ;
0 commit comments