From e68e359aae4048404bfefda0817eff25bd48688a Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 12 Aug 2023 12:20:12 +0200 Subject: [PATCH] test: reduce flakiness of `test-esm-loader-hooks` PR-URL: https://github.com/nodejs/node/pull/49105 Reviewed-By: Moshe Atlow Reviewed-By: Jacob Smith Reviewed-By: Benjamin Gruenbaum --- test/es-module/test-esm-loader-hooks.mjs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/test/es-module/test-esm-loader-hooks.mjs b/test/es-module/test-esm-loader-hooks.mjs index 4d0f5a6bd91acf..ecb429d4593a3a 100644 --- a/test/es-module/test-esm-loader-hooks.mjs +++ b/test/es-module/test-esm-loader-hooks.mjs @@ -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); @@ -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);