From e51d8c6004a8aa542f44fe03b1a1e344b2c80610 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Fri, 8 Jul 2022 13:17:25 +0300 Subject: [PATCH] test_runner: wait for stderr and stdout to complete PR-URL: https://github.com/nodejs/node/pull/43666 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Antoine du Hamel --- lib/internal/main/test_runner.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/internal/main/test_runner.js b/lib/internal/main/test_runner.js index 0a47535fccfd51..ccd869d90968e2 100644 --- a/lib/internal/main/test_runner.js +++ b/lib/internal/main/test_runner.js @@ -7,6 +7,8 @@ const { ArrayPrototypeSlice, ArrayPrototypeSort, Promise, + PromiseAll, + SafeArrayIterator, SafeSet, } = primordials; const { @@ -14,6 +16,7 @@ const { } = require('internal/bootstrap/pre_execution'); const { spawn } = require('child_process'); const { readdirSync, statSync } = require('fs'); +const { finished } = require('internal/streams/end-of-stream'); const console = require('internal/console/global'); const { codes: { @@ -126,9 +129,10 @@ function runTestFile(path) { stderr += chunk; }); - child.once('exit', (code, signal) => { + child.once('exit', async (code, signal) => { if (code !== 0 || signal !== null) { if (!err) { + await PromiseAll(new SafeArrayIterator([finished(child.stderr), finished(child.stdout)])); err = new ERR_TEST_FAILURE('test failed', kSubtestsFailed); err.exitCode = code; err.signal = signal;