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
2
2
'use strict'
3
3
const {
4
4
ArrayFrom,
5
5
ArrayPrototypeFilter,
6
6
ArrayPrototypeIncludes,
7
7
ArrayPrototypeJoin,
8
- ArrayPrototypePop,
9
8
ArrayPrototypePush,
10
9
ArrayPrototypeSlice,
11
10
ArrayPrototypeSort,
12
11
ObjectAssign,
13
12
PromisePrototypeThen,
14
- RegExpPrototypeSymbolSplit,
15
13
SafePromiseAll,
16
- SafeSet,
17
- StringPrototypeEndsWith
14
+ SafeSet
18
15
} = require ( '#internal/per_context/primordials' )
19
16
20
- const { Buffer } = require ( 'buffer' )
21
17
const { spawn } = require ( 'child_process' )
22
18
const { 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' )
23
21
const {
24
22
codes : {
25
23
ERR_TEST_FAILURE
@@ -116,29 +114,6 @@ function getRunArgs ({ path, inspectPort }) {
116
114
return argv
117
115
}
118
116
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
-
142
117
function runTestFile ( path , root , inspectPort ) {
143
118
const subtest = root . createSubtest ( Test , path , async ( t ) => {
144
119
const args = getRunArgs ( { path, inspectPort } )
@@ -153,9 +128,18 @@ function runTestFile (path, root, inspectPort) {
153
128
err = error
154
129
} )
155
130
156
- child . stderr . on ( 'data' , makeStderrCallback ( ( data ) => {
131
+ child . stderr . on ( 'data' , ( data ) => {
157
132
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
+ }
159
143
160
144
const { 0 : { 0 : code , 1 : signal } , 1 : stdout } = await SafePromiseAll ( [
161
145
once ( child , 'exit' , { signal : t . signal } ) ,
0 commit comments