Skip to content

Commit 0daea96

Browse files
authored
test: reduce flakiness of test-esm-loader-hooks
PR-URL: #49248 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 5026293 commit 0daea96

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

test/es-module/test-esm-loader-hooks.mjs

+10-6
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ describe('Loader hooks', { concurrency: true }, () => {
599599
`
600600
import {MessageChannel} from 'node:worker_threads';
601601
import {register} from 'node:module';
602-
import {setTimeout} from 'node:timers/promises';
602+
import {once} from 'node:events';
603603
const {port1, port2} = new MessageChannel();
604604
port1.on('message', (msg) => {
605605
console.log('message', msg);
@@ -610,8 +610,12 @@ describe('Loader hooks', { concurrency: true }, () => {
610610
);
611611
console.log('register', result);
612612
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);
615619
port1.close();
616620
`,
617621
]);
@@ -707,10 +711,10 @@ describe('Loader hooks', { concurrency: true }, () => {
707711
]);
708712

709713
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',
713716
'hooks initialize 2',
717+
'result 2',
714718
'' ]);
715719
assert.strictEqual(code, 0);
716720
assert.strictEqual(signal, null);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { writeFileSync } from 'node:fs';
2+
13
let counter = 0;
24

35
export async function initialize() {
4-
counter += 1;
5-
console.log('hooks initialize', counter);
6+
writeFileSync(1, `hooks initialize ${++counter}\n`);
67
return counter;
78
}

0 commit comments

Comments
 (0)