Skip to content

Commit 7f7cea4

Browse files
apply proposed solution that doesn't rely on setTiemout
Co-authored-by: Luigi Pinca <[email protected]>
1 parent a35b1a6 commit 7f7cea4

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

test/parallel/test-repl-import-referrer.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,25 @@ const args = ['--interactive'];
88
const opts = { cwd: fixtures.path('es-modules') };
99
const child = cp.spawn(process.execPath, args, opts);
1010

11-
const outputs = [];
11+
let output = '';
1212
child.stdout.setEncoding('utf8');
1313
child.stdout.on('data', (data) => {
14-
outputs.push(data);
15-
if (outputs.length === 3) {
14+
output += data;
15+
16+
if (
17+
!child.stdin.writableEnded &&
18+
output.includes('[Module: null prototype] { message: \'A message\' }')
19+
) {
1620
// All the expected outputs have been received
1721
// so we can close the child process's stdin
1822
child.stdin.end();
1923
}
2024
});
2125

22-
child.on('exit', common.mustCall(() => {
23-
const results = outputs[2].split('\n')[0];
24-
assert.strictEqual(
25-
results,
26-
'[Module: null prototype] { message: \'A message\' }'
27-
);
26+
child.on('exit', common.mustCall((code, signal) => {
27+
assert.strictEqual(code, 0);
28+
assert.strictEqual(signal, null);
2829
}));
2930

30-
// Note: write the commands on stdin with a slight delay to make sure
31-
// that the child process is ready to receive and process them
32-
setTimeout(() => {
33-
child.stdin.write('await import(\'./message.mjs\');\n');
34-
child.stdin.write('.exit');
35-
}, common.platformTimeout(250));
31+
child.stdin.write('await import(\'./message.mjs\');\n');
32+
child.stdin.write('.exit');

0 commit comments

Comments
 (0)