Skip to content

Commit

Permalink
test: reduce flakiness of test-esm-loader-hooks
Browse files Browse the repository at this point in the history
PR-URL: #49105
Backport-PR-URL: #50669
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
aduh95 authored and targos committed Nov 23, 2023
1 parent 385f24c commit 26f0166
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions test/es-module/test-esm-loader-hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -541,28 +541,25 @@ describe('Loader hooks', { concurrency: true }, () => {
`
import {MessageChannel} from 'node:worker_threads';
import {register} from 'node:module';
import {setTimeout} from 'node:timers/promises';
const {port1, port2} = new MessageChannel();
port1.on('message', (msg) => {
console.log('message', msg);
});
const result = register(
${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize-port.mjs'))},
${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize-port.mjs'))},
{data: port2, transferList: [port2]},
);
console.log('register', result);
await import('node:os');
await setTimeout(99); // delay to limit flakiness
port1.close();
`,
]);

const lines = stdout.split('\n');

assert.strictEqual(lines[0], 'register ok');
assert.strictEqual(lines[1], 'message initialize');
assert.strictEqual(lines[2], 'message resolve node:os');

assert.strictEqual(stderr, '');
assert.deepStrictEqual(stdout.split('\n'), ['register ok', 'message initialize', 'message resolve node:os', '']);

assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand All @@ -574,26 +571,23 @@ describe('Loader hooks', { concurrency: true }, () => {
'--input-type=commonjs',
'--eval',
`
'use strict';
const {register} = require('node:module');
register(
${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize.mjs'))},
${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize.mjs'))},
);
register(
${JSON.stringify(fixtures.fileURL('/es-module-loaders/loader-load-foo-or-42.mjs'))},
${JSON.stringify(fixtures.fileURL('es-module-loaders/loader-load-foo-or-42.mjs'))},
);
import('node:os').then((result) => {
console.log(result.default);
console.log(JSON.stringify(result));
});
`,
]);

const lines = stdout.split('\n');

assert.strictEqual(lines[0], 'hooks initialize 1');
assert.strictEqual(lines[1], 'foo');

assert.strictEqual(stderr, '');
assert.deepStrictEqual(stdout.split('\n').sort(), ['hooks initialize 1', '{"default":"foo"}', ''].sort());

assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down

0 comments on commit 26f0166

Please sign in to comment.