Skip to content

Commit 26f0166

Browse files
aduh95targos
authored andcommitted
test: reduce flakiness of test-esm-loader-hooks
PR-URL: #49105 Backport-PR-URL: #50669 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 385f24c commit 26f0166

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -541,28 +541,25 @@ describe('Loader hooks', { concurrency: true }, () => {
541541
`
542542
import {MessageChannel} from 'node:worker_threads';
543543
import {register} from 'node:module';
544+
import {setTimeout} from 'node:timers/promises';
544545
const {port1, port2} = new MessageChannel();
545546
port1.on('message', (msg) => {
546547
console.log('message', msg);
547548
});
548549
const result = register(
549-
${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize-port.mjs'))},
550+
${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize-port.mjs'))},
550551
{data: port2, transferList: [port2]},
551552
);
552553
console.log('register', result);
553554
554555
await import('node:os');
556+
await setTimeout(99); // delay to limit flakiness
555557
port1.close();
556558
`,
557559
]);
558560

559-
const lines = stdout.split('\n');
560-
561-
assert.strictEqual(lines[0], 'register ok');
562-
assert.strictEqual(lines[1], 'message initialize');
563-
assert.strictEqual(lines[2], 'message resolve node:os');
564-
565561
assert.strictEqual(stderr, '');
562+
assert.deepStrictEqual(stdout.split('\n'), ['register ok', 'message initialize', 'message resolve node:os', '']);
566563

567564
assert.strictEqual(code, 0);
568565
assert.strictEqual(signal, null);
@@ -574,26 +571,23 @@ describe('Loader hooks', { concurrency: true }, () => {
574571
'--input-type=commonjs',
575572
'--eval',
576573
`
574+
'use strict';
577575
const {register} = require('node:module');
578576
register(
579-
${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize.mjs'))},
577+
${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize.mjs'))},
580578
);
581579
register(
582-
${JSON.stringify(fixtures.fileURL('/es-module-loaders/loader-load-foo-or-42.mjs'))},
580+
${JSON.stringify(fixtures.fileURL('es-module-loaders/loader-load-foo-or-42.mjs'))},
583581
);
584582
585583
import('node:os').then((result) => {
586-
console.log(result.default);
584+
console.log(JSON.stringify(result));
587585
});
588586
`,
589587
]);
590588

591-
const lines = stdout.split('\n');
592-
593-
assert.strictEqual(lines[0], 'hooks initialize 1');
594-
assert.strictEqual(lines[1], 'foo');
595-
596589
assert.strictEqual(stderr, '');
590+
assert.deepStrictEqual(stdout.split('\n').sort(), ['hooks initialize 1', '{"default":"foo"}', ''].sort());
597591

598592
assert.strictEqual(code, 0);
599593
assert.strictEqual(signal, null);

0 commit comments

Comments
 (0)