GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: reduce flakiness of `test-esm-loader-hooks` · nodejs/node@2fcb855

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/es-module
    • test-esm-loader-hooks.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/es-module/test-esm-loader-hooks.mjs
+9-15Lines changed: 9 additions & 15 deletions
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 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.