@@ -599,7 +599,7 @@ describe('Loader hooks', { concurrency: true }, () => {
599
599
`
600
600
import {MessageChannel} from 'node:worker_threads';
601
601
import {register} from 'node:module';
602
- import {setTimeout } from 'node:timers/promises ';
602
+ import {once } from 'node:events ';
603
603
const {port1, port2} = new MessageChannel();
604
604
port1.on('message', (msg) => {
605
605
console.log('message', msg);
@@ -610,8 +610,12 @@ describe('Loader hooks', { concurrency: true }, () => {
610
610
);
611
611
console.log('register', result);
612
612
613
- await import('node:os');
614
- await setTimeout(99); // delay to limit flakiness
613
+ const timeout = setTimeout(() => {}, 2**31 - 1); // to keep the process alive.
614
+ await Promise.all([
615
+ once(port1, 'message').then(() => once(port1, 'message')),
616
+ import('node:os'),
617
+ ]);
618
+ clearTimeout(timeout);
615
619
port1.close();
616
620
` ,
617
621
] ) ;
@@ -707,10 +711,10 @@ describe('Loader hooks', { concurrency: true }, () => {
707
711
] ) ;
708
712
709
713
assert . strictEqual ( stderr , '' ) ;
710
- assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'result 1' ,
711
- 'result 2' ,
712
- 'hooks initialize 1' ,
714
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'hooks initialize 1' ,
715
+ 'result 1' ,
713
716
'hooks initialize 2' ,
717
+ 'result 2' ,
714
718
'' ] ) ;
715
719
assert . strictEqual ( code , 0 ) ;
716
720
assert . strictEqual ( signal , null ) ;
0 commit comments