Skip to content

Commit 2fcb855

Browse files
aduh95RafaelGSS
authored andcommitted
test: reduce flakiness of test-esm-loader-hooks
PR-URL: #49105 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent f888a1d commit 2fcb855

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

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

+9-15
Original file line numberDiff line numberDiff line change
@@ -593,28 +593,25 @@ describe('Loader hooks', { concurrency: true }, () => {
593593
`
594594
import {MessageChannel} from 'node:worker_threads';
595595
import {register} from 'node:module';
596+
import {setTimeout} from 'node:timers/promises';
596597
const {port1, port2} = new MessageChannel();
597598
port1.on('message', (msg) => {
598599
console.log('message', msg);
599600
});
600601
const result = register(
601-
${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize-port.mjs'))},
602+
${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize-port.mjs'))},
602603
{data: port2, transferList: [port2]},
603604
);
604605
console.log('register', result);
605606
606607
await import('node:os');
608+
await setTimeout(99); // delay to limit flakiness
607609
port1.close();
608610
`,
609611
]);
610612

611-
const lines = stdout.split('\n');
612-
613-
assert.strictEqual(lines[0], 'register ok');
614-
assert.strictEqual(lines[1], 'message initialize');
615-
assert.strictEqual(lines[2], 'message resolve node:os');
616-
617613
assert.strictEqual(stderr, '');
614+
assert.deepStrictEqual(stdout.split('\n'), ['register ok', 'message initialize', 'message resolve node:os', '']);
618615

619616
assert.strictEqual(code, 0);
620617
assert.strictEqual(signal, null);
@@ -626,26 +623,23 @@ describe('Loader hooks', { concurrency: true }, () => {
626623
'--input-type=commonjs',
627624
'--eval',
628625
`
626+
'use strict';
629627
const {register} = require('node:module');
630628
register(
631-
${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize.mjs'))},
629+
${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize.mjs'))},
632630
);
633631
register(
634-
${JSON.stringify(fixtures.fileURL('/es-module-loaders/loader-load-foo-or-42.mjs'))},
632+
${JSON.stringify(fixtures.fileURL('es-module-loaders/loader-load-foo-or-42.mjs'))},
635633
);
636634
637635
import('node:os').then((result) => {
638-
console.log(result.default);
636+
console.log(JSON.stringify(result));
639637
});
640638
`,
641639
]);
642640

643-
const lines = stdout.split('\n');
644-
645-
assert.strictEqual(lines[0], 'hooks initialize 1');
646-
assert.strictEqual(lines[1], 'foo');
647-
648641
assert.strictEqual(stderr, '');
642+
assert.deepStrictEqual(stdout.split('\n').sort(), ['hooks initialize 1', '{"default":"foo"}', ''].sort());
649643

650644
assert.strictEqual(code, 0);
651645
assert.strictEqual(signal, null);

0 commit comments

Comments
 (0)