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
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
aduh95 authored and RafaelGSS committed Aug 17, 2023
1 parent f888a1d commit 2fcb855
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 @@ -593,28 +593,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 @@ -626,26 +623,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 2fcb855

Please sign in to comment.