Skip to content

Commit 1950b38

Browse files
committed
test: fix test-runner-inspect
PR-URL: nodejs/node#44620 Fixes: nodejs/node#44600 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> (cherry picked from commit 9825a7e01d35b9d49ebb58efed2c316012c19db6)
1 parent c50f844 commit 1950b38

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

lib/internal/test_runner/runner.js

+15-31
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
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'
33
const {
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')
2117
const { spawn } = require('child_process')
2218
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')
2321
const {
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-
142117
function 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

Comments
 (0)