@@ -4,21 +4,19 @@ const {
4
4
ArrayPrototypeFilter,
5
5
ArrayPrototypeIncludes,
6
6
ArrayPrototypeJoin,
7
- ArrayPrototypePop,
8
7
ArrayPrototypePush,
9
8
ArrayPrototypeSlice,
10
9
ArrayPrototypeSort,
11
10
ObjectAssign,
12
11
PromisePrototypeThen,
13
- RegExpPrototypeSymbolSplit,
14
12
SafePromiseAll,
15
13
SafeSet,
16
- StringPrototypeEndsWith,
17
14
} = primordials ;
18
15
19
- const { Buffer } = require ( 'buffer' ) ;
20
16
const { spawn } = require ( 'child_process' ) ;
21
17
const { readdirSync, statSync } = require ( 'fs' ) ;
18
+ // TODO(aduh95): switch to internal/readline/interface when backporting to Node.js 16.x is no longer a concern.
19
+ const { createInterface } = require ( 'readline' ) ;
22
20
const console = require ( 'internal/console/global' ) ;
23
21
const {
24
22
codes : {
@@ -114,28 +112,6 @@ function getRunArgs({ path, inspectPort }) {
114
112
return argv ;
115
113
}
116
114
117
- function makeStderrCallback ( callback ) {
118
- if ( ! isUsingInspector ( ) ) {
119
- return callback ;
120
- }
121
- let buffer = Buffer . alloc ( 0 ) ;
122
- return ( data ) => {
123
- callback ( data ) ;
124
- const newData = Buffer . concat ( [ buffer , data ] ) ;
125
- const str = newData . toString ( 'utf8' ) ;
126
- let lines = str ;
127
- if ( StringPrototypeEndsWith ( lines , '\n' ) ) {
128
- buffer = Buffer . alloc ( 0 ) ;
129
- } else {
130
- lines = RegExpPrototypeSymbolSplit ( / \r ? \n / , str ) ;
131
- buffer = Buffer . from ( ArrayPrototypePop ( lines ) , 'utf8' ) ;
132
- lines = ArrayPrototypeJoin ( lines , '\n' ) ;
133
- }
134
- if ( isInspectorMessage ( lines ) ) {
135
- process . stderr . write ( lines ) ;
136
- }
137
- } ;
138
- }
139
115
140
116
function runTestFile ( path , root , inspectPort ) {
141
117
const subtest = root . createSubtest ( Test , path , async ( t ) => {
@@ -151,9 +127,18 @@ function runTestFile(path, root, inspectPort) {
151
127
err = error ;
152
128
} ) ;
153
129
154
- child . stderr . on ( 'data' , makeStderrCallback ( ( data ) => {
130
+ child . stderr . on ( 'data' , ( data ) => {
155
131
stderr += data ;
156
- } ) ) ;
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
+ }
157
142
158
143
const { 0 : { 0 : code , 1 : signal } , 1 : stdout } = await SafePromiseAll ( [
159
144
once ( child , 'exit' , { signal : t . signal } ) ,
0 commit comments