From a35b1a6f892efeb4d42f189b1b577a5625c3ac3a Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 25 Apr 2025 00:53:54 +0200 Subject: [PATCH 1/5] test: fix test-repl-import-referrer flakiness --- test/parallel/test-repl-import-referrer.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js index 9c3e961e5e1585..1b65c516554e7b 100644 --- a/test/parallel/test-repl-import-referrer.js +++ b/test/parallel/test-repl-import-referrer.js @@ -27,5 +27,9 @@ child.on('exit', common.mustCall(() => { ); })); -child.stdin.write('await import(\'./message.mjs\');\n'); -child.stdin.write('.exit'); +// Note: write the commands on stdin with a slight delay to make sure +// that the child process is ready to receive and process them +setTimeout(() => { + child.stdin.write('await import(\'./message.mjs\');\n'); + child.stdin.write('.exit'); +}, common.platformTimeout(250)); From 7f7cea476a4607e3e2e54cc87e7a7d15f76ffbec Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 25 Apr 2025 10:29:45 +0200 Subject: [PATCH 2/5] apply proposed solution that doesn't rely on `setTiemout` Co-authored-by: Luigi Pinca --- test/parallel/test-repl-import-referrer.js | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js index 1b65c516554e7b..57aae7858abf47 100644 --- a/test/parallel/test-repl-import-referrer.js +++ b/test/parallel/test-repl-import-referrer.js @@ -8,28 +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\' }') + ) { // 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); })); -// Note: write the commands on stdin with a slight delay to make sure -// that the child process is ready to receive and process them -setTimeout(() => { - child.stdin.write('await import(\'./message.mjs\');\n'); - child.stdin.write('.exit'); -}, common.platformTimeout(250)); +child.stdin.write('await import(\'./message.mjs\');\n'); +child.stdin.write('.exit'); From a1e4a2bf279f06d04b7b347e53355adeaa52976e Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 25 Apr 2025 10:55:47 +0200 Subject: [PATCH 3/5] Update test/parallel/test-repl-import-referrer.js Co-authored-by: Luigi Pinca --- test/parallel/test-repl-import-referrer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js index 57aae7858abf47..fac65d239f5bdb 100644 --- a/test/parallel/test-repl-import-referrer.js +++ b/test/parallel/test-repl-import-referrer.js @@ -15,7 +15,7 @@ child.stdout.on('data', (data) => { if ( !child.stdin.writableEnded && - output.includes('[Module: null prototype] { message: \'A message\' }') + 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 From 88f9b437e7b3dd64c3be68168e2d8f70d13067d9 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 25 Apr 2025 17:41:41 +0200 Subject: [PATCH 4/5] Update test/parallel/test-repl-import-referrer.js Co-authored-by: Luigi Pinca --- test/parallel/test-repl-import-referrer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js index fac65d239f5bdb..6c22b92eae33b6 100644 --- a/test/parallel/test-repl-import-referrer.js +++ b/test/parallel/test-repl-import-referrer.js @@ -15,7 +15,7 @@ child.stdout.on('data', (data) => { if ( !child.stdin.writableEnded && - output.includes('[Module: null prototype] { message: \'A message\' }\n') + 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 From 01e3f9dbdf2640efd05e9fa9e85e71ba3ddff6bd Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 25 Apr 2025 17:54:00 +0200 Subject: [PATCH 5/5] Update test/parallel/test-repl-import-referrer.js Co-authored-by: Luigi Pinca --- test/parallel/test-repl-import-referrer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js index 6c22b92eae33b6..ffa68e70d2599b 100644 --- a/test/parallel/test-repl-import-referrer.js +++ b/test/parallel/test-repl-import-referrer.js @@ -26,6 +26,7 @@ child.stdout.on('data', (data) => { 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');