Skip to content

Commit

Permalink
test: fix test-runner-inspect
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#44620
Fixes: nodejs/node#44600
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
(cherry picked from commit 9825a7e01d35b9d49ebb58efed2c316012c19db6)
  • Loading branch information
MoLow committed Feb 2, 2023
1 parent c50f844 commit 1950b38
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
// https://github.com/nodejs/node/blob/a165193c5c8e4bcfbd12b2c3f6e55a81a251c258/lib/internal/test_runner/runner.js
// https://github.com/nodejs/node/blob/9825a7e01d35b9d49ebb58efed2c316012c19db6/lib/internal/test_runner/runner.js
'use strict'
const {
ArrayFrom,
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
ArrayPrototypeJoin,
ArrayPrototypePop,
ArrayPrototypePush,
ArrayPrototypeSlice,
ArrayPrototypeSort,
ObjectAssign,
PromisePrototypeThen,
RegExpPrototypeSymbolSplit,
SafePromiseAll,
SafeSet,
StringPrototypeEndsWith
SafeSet
} = require('#internal/per_context/primordials')

const { Buffer } = require('buffer')
const { spawn } = require('child_process')
const { readdirSync, statSync } = require('fs')
// TODO(aduh95): switch to internal/readline/interface when backporting to Node.js 16.x is no longer a concern.
const { createInterface } = require('readline')
const {
codes: {
ERR_TEST_FAILURE
Expand Down Expand Up @@ -116,29 +114,6 @@ function getRunArgs ({ path, inspectPort }) {
return argv
}

function makeStderrCallback (callback) {
if (!isUsingInspector()) {
return callback
}
let buffer = Buffer.alloc(0)
return (data) => {
callback(data)
const newData = Buffer.concat([buffer, data])
const str = newData.toString('utf8')
let lines = str
if (StringPrototypeEndsWith(lines, '\n')) {
buffer = Buffer.alloc(0)
} else {
lines = RegExpPrototypeSymbolSplit(/\r?\n/, str)
buffer = Buffer.from(ArrayPrototypePop(lines), 'utf8')
lines = ArrayPrototypeJoin(lines, '\n')
}
if (isInspectorMessage(lines)) {
process.stderr.write(lines)
}
}
}

function runTestFile (path, root, inspectPort) {
const subtest = root.createSubtest(Test, path, async (t) => {
const args = getRunArgs({ path, inspectPort })
Expand All @@ -153,9 +128,18 @@ function runTestFile (path, root, inspectPort) {
err = error
})

child.stderr.on('data', makeStderrCallback((data) => {
child.stderr.on('data', (data) => {
stderr += data
}))
})

if (isUsingInspector()) {
const rl = createInterface({ input: child.stderr })
rl.on('line', (line) => {
if (isInspectorMessage(line)) {
process.stderr.write(line + '\n')
}
})
}

const { 0: { 0: code, 1: signal }, 1: stdout } = await SafePromiseAll([
once(child, 'exit', { signal: t.signal }),
Expand Down

0 comments on commit 1950b38

Please sign in to comment.