1- // https://github.com/nodejs/node/blob/a165193c5c8e4bcfbd12b2c3f6e55a81a251c258 /lib/internal/test_runner/runner.js
1+ // https://github.com/nodejs/node/blob/9825a7e01d35b9d49ebb58efed2c316012c19db6 /lib/internal/test_runner/runner.js
22'use strict'
33const {
44 ArrayFrom,
55 ArrayPrototypeFilter,
66 ArrayPrototypeIncludes,
77 ArrayPrototypeJoin,
8- ArrayPrototypePop,
98 ArrayPrototypePush,
109 ArrayPrototypeSlice,
1110 ArrayPrototypeSort,
1211 ObjectAssign,
1312 PromisePrototypeThen,
14- RegExpPrototypeSymbolSplit,
1513 SafePromiseAll,
16- SafeSet,
17- StringPrototypeEndsWith
14+ SafeSet
1815} = require ( '#internal/per_context/primordials' )
1916
20- const { Buffer } = require ( 'buffer' )
2117const { spawn } = require ( 'child_process' )
2218const { readdirSync, statSync } = require ( 'fs' )
19+ // TODO(aduh95): switch to internal/readline/interface when backporting to Node.js 16.x is no longer a concern.
20+ const { createInterface } = require ( 'readline' )
2321const {
2422 codes : {
2523 ERR_TEST_FAILURE
@@ -115,29 +113,6 @@ function getRunArgs ({ path, inspectPort }) {
115113 return argv
116114}
117115
118- function makeStderrCallback ( callback ) {
119- if ( ! isUsingInspector ( ) ) {
120- return callback
121- }
122- let buffer = Buffer . alloc ( 0 )
123- return ( data ) => {
124- callback ( data )
125- const newData = Buffer . concat ( [ buffer , data ] )
126- const str = newData . toString ( 'utf8' )
127- let lines = str
128- if ( StringPrototypeEndsWith ( lines , '\n' ) ) {
129- buffer = Buffer . alloc ( 0 )
130- } else {
131- lines = RegExpPrototypeSymbolSplit ( / \r ? \n / , str )
132- buffer = Buffer . from ( ArrayPrototypePop ( lines ) , 'utf8' )
133- lines = ArrayPrototypeJoin ( lines , '\n' )
134- }
135- if ( isInspectorMessage ( lines ) ) {
136- process . stderr . write ( lines )
137- }
138- }
139- }
140-
141116function runTestFile ( path , root , inspectPort ) {
142117 const subtest = root . createSubtest ( Test , path , async ( t ) => {
143118 const args = getRunArgs ( { path, inspectPort } )
@@ -152,9 +127,18 @@ function runTestFile (path, root, inspectPort) {
152127 err = error
153128 } )
154129
155- child . stderr . on ( 'data' , makeStderrCallback ( ( data ) => {
130+ child . stderr . on ( 'data' , ( data ) => {
156131 stderr += data
157- } ) )
132+ } )
133+
134+ if ( isUsingInspector ( ) ) {
135+ const rl = createInterface ( { input : child . stderr } )
136+ rl . on ( 'line' , ( line ) => {
137+ if ( isInspectorMessage ( line ) ) {
138+ process . stderr . write ( line + '\n' )
139+ }
140+ } )
141+ }
158142
159143 const { 0 : { 0 : code , 1 : signal } , 1 : stdout } = await SafePromiseAll ( [
160144 once ( child , 'exit' , { signal : t . signal } ) ,
0 commit comments