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
@@ -115,29 +113,6 @@ function getRunArgs ({ path, inspectPort }) {
115
113
return argv
116
114
}
117
115
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
-
141
116
function runTestFile ( path , root , inspectPort ) {
142
117
const subtest = root . createSubtest ( Test , path , async ( t ) => {
143
118
const args = getRunArgs ( { path, inspectPort } )
@@ -152,9 +127,18 @@ function runTestFile (path, root, inspectPort) {
152
127
err = error
153
128
} )
154
129
155
- child . stderr . on ( 'data' , makeStderrCallback ( ( data ) => {
130
+ child . stderr . on ( 'data' , ( data ) => {
156
131
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
+ }
158
142
159
143
const { 0 : { 0 : code , 1 : signal } , 1 : stdout } = await SafePromiseAll ( [
160
144
once ( child , 'exit' , { signal : t . signal } ) ,
0 commit comments