diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js index 9c3e961e5e1585..ffa68e70d2599b 100644 --- a/test/parallel/test-repl-import-referrer.js +++ b/test/parallel/test-repl-import-referrer.js @@ -8,23 +8,25 @@ const args = ['--interactive']; const opts = { cwd: fixtures.path('es-modules') }; const child = cp.spawn(process.execPath, args, opts); -const outputs = []; +let output = ''; child.stdout.setEncoding('utf8'); child.stdout.on('data', (data) => { - outputs.push(data); - if (outputs.length === 3) { + output += data; + + if ( + !child.stdin.writableEnded && + output.includes('[Module: null prototype] { message: \'A message\' }\n> ') + ) { // All the expected outputs have been received // so we can close the child process's stdin child.stdin.end(); } }); -child.on('exit', common.mustCall(() => { - const results = outputs[2].split('\n')[0]; - assert.strictEqual( - results, - '[Module: null prototype] { message: \'A message\' }' - ); +child.on('exit', common.mustCall((code, signal) => { + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); + assert.strictEqual(child.stdin.writableEnded, true); })); child.stdin.write('await import(\'./message.mjs\');\n');