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
@@ -116,29 +114,6 @@ function getRunArgs ({ path, inspectPort }) {
116114 return argv
117115}
118116
119- function makeStderrCallback ( callback ) {
120- if ( ! isUsingInspector ( ) ) {
121- return callback
122- }
123- let buffer = Buffer . alloc ( 0 )
124- return ( data ) => {
125- callback ( data )
126- const newData = Buffer . concat ( [ buffer , data ] )
127- const str = newData . toString ( 'utf8' )
128- let lines = str
129- if ( StringPrototypeEndsWith ( lines , '\n' ) ) {
130- buffer = Buffer . alloc ( 0 )
131- } else {
132- lines = RegExpPrototypeSymbolSplit ( / \r ? \n / , str )
133- buffer = Buffer . from ( ArrayPrototypePop ( lines ) , 'utf8' )
134- lines = ArrayPrototypeJoin ( lines , '\n' )
135- }
136- if ( isInspectorMessage ( lines ) ) {
137- process . stderr . write ( lines )
138- }
139- }
140- }
141-
142117function runTestFile ( path , root , inspectPort ) {
143118 const subtest = root . createSubtest ( Test , path , async ( t ) => {
144119 const args = getRunArgs ( { path, inspectPort } )
@@ -153,9 +128,18 @@ function runTestFile (path, root, inspectPort) {
153128 err = error
154129 } )
155130
156- child . stderr . on ( 'data' , makeStderrCallback ( ( data ) => {
131+ child . stderr . on ( 'data' , ( data ) => {
157132 stderr += data
158- } ) )
133+ } )
134+
135+ if ( isUsingInspector ( ) ) {
136+ const rl = createInterface ( { input : child . stderr } )
137+ rl . on ( 'line' , ( line ) => {
138+ if ( isInspectorMessage ( line ) ) {
139+ process . stderr . write ( line + '\n' )
140+ }
141+ } )
142+ }
159143
160144 const { 0 : { 0 : code , 1 : signal } , 1 : stdout } = await SafePromiseAll ( [
161145 once ( child , 'exit' , { signal : t . signal } ) ,
0 commit comments