@@ -547,7 +547,7 @@ describe('Loader hooks', { concurrency: true }, () => {
547
547
`
548
548
import {MessageChannel} from 'node:worker_threads';
549
549
import {register} from 'node:module';
550
- import {setTimeout } from 'node:timers/promises ';
550
+ import {once } from 'node:events ';
551
551
const {port1, port2} = new MessageChannel();
552
552
port1.on('message', (msg) => {
553
553
console.log('message', msg);
@@ -558,8 +558,12 @@ describe('Loader hooks', { concurrency: true }, () => {
558
558
);
559
559
console.log('register', result);
560
560
561
- await import('node:os');
562
- await setTimeout(99); // delay to limit flakiness
561
+ const timeout = setTimeout(() => {}, 2**31 - 1); // to keep the process alive.
562
+ await Promise.all([
563
+ once(port1, 'message').then(() => once(port1, 'message')),
564
+ import('node:os'),
565
+ ]);
566
+ clearTimeout(timeout);
563
567
port1.close();
564
568
` ,
565
569
] ) ;
@@ -655,10 +659,10 @@ describe('Loader hooks', { concurrency: true }, () => {
655
659
] ) ;
656
660
657
661
assert . strictEqual ( stderr , '' ) ;
658
- assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'result 1' ,
659
- 'result 2' ,
660
- 'hooks initialize 1' ,
662
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'hooks initialize 1' ,
663
+ 'result 1' ,
661
664
'hooks initialize 2' ,
665
+ 'result 2' ,
662
666
'' ] ) ;
663
667
assert . strictEqual ( code , 0 ) ;
664
668
assert . strictEqual ( signal , null ) ;
0 commit comments