GeezerVison is showing github.com — test_runner: don't parse TAP from stderr · nodejs/node@ed9246f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js +20-13Lines changed: 20 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -240,22 +240,29 @@ function runTestFile(path, root, inspectPort, filesWatcher) { | 240 | 240 | err = error; | 241 | 241 | }); | 242 | 242 |
| 243 | | - if (isUsingInspector()) { | 244 | | - const rl = createInterface({ input: child.stderr }); | 245 | | - rl.on('line', (line) => { | 246 | | - if (isInspectorMessage(line)) { | 247 | | - process.stderr.write(line + '\n'); | 248 | | - } | 249 | | - }); | 250 | | - } | 251 | | - | 252 | | - const parser = new TapParser(); | 253 | | - child.stderr.pipe(parser).on('data', (ast) => { | 254 | | - if (ast.lexeme && isInspectorMessage(ast.lexeme)) { | 255 | | - process.stderr.write(ast.lexeme + '\n'); | | 243 | + const rl = createInterface({ input: child.stderr }); | | 244 | + rl.on('line', (line) => { | | 245 | + if (isInspectorMessage(line)) { | | 246 | + process.stderr.write(line + '\n'); | | 247 | + return; | 256 | 248 | } | | 249 | + | | 250 | + // stderr cannot be treated as TAP, per the spec. However, we want to | | 251 | + // surface stderr lines as TAP diagnostics to improve the DX. Inject | | 252 | + // each line into the test output as an unknown token as if it came | | 253 | + // from the TAP parser. | | 254 | + const node = { | | 255 | + kind: TokenKind.UNKNOWN, | | 256 | + node: { | | 257 | + value: line, | | 258 | + }, | | 259 | + }; | | 260 | + | | 261 | + subtest.addToReport(node); | 257 | 262 | }); | 258 | 263 |
| | 264 | + const parser = new TapParser(); | | 265 | + | 259 | 266 | child.stdout.pipe(parser).on('data', (ast) => { | 260 | 267 | subtest.addToReport(ast); | 261 | 268 | }); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/util/inspector.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,7 @@ const { validatePort } = require('internal/validators'); | 16 | 16 | const kMinPort = 1024; | 17 | 17 | const kMaxPort = 65535; | 18 | 18 | const kInspectArgRegex = /--inspect(?:-brk|-port)?|--debug-port/; | 19 | | -const kInspectMsgRegex = /Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\/|Debugger attached|Waiting for the debugger to disconnect\.\.\./; | | 19 | +const kInspectMsgRegex = /Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\/|For help, see: https:\/\/nodejs\.org\/en\/docs\/inspector|Debugger attached|Waiting for the debugger to disconnect\.\.\./; | 20 | 20 |
| 21 | 21 | const _isUsingInspector = new SafeWeakMap(); | 22 | 22 | function isUsingInspector(execArgv = process.execArgv) { | |
Collapse file Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const test = require('node:test'); | | 3 | + | | 4 | +console.error('stderr', 1); | | 5 | + | | 6 | +test('a test', async () => { | | 7 | + console.error('stderr', 2); | | 8 | + await new Promise((resolve) => { | | 9 | + console.log('stdout', 3); | | 10 | + setTimeout(() => { | | 11 | + // This should not be sent to the TAP parser. | | 12 | + console.error('not ok 1 - fake test'); | | 13 | + resolve(); | | 14 | + console.log('stdout', 4); | | 15 | + }, 2); | | 16 | + }); | | 17 | + console.error('stderr', 5); | | 18 | +}); | | 19 | + | | 20 | +console.error('stderr', 6); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-cli.js +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -168,3 +168,29 @@ const testFixtures = fixtures.path('test-runner'); | 168 | 168 | assert.match(stdout, /# pass 2/); | 169 | 169 | assert.match(stdout, /# fail 1/); | 170 | 170 | } | | 171 | + | | 172 | +{ | | 173 | + // Test user logging in tests. | | 174 | + const args = [ | | 175 | + '--test', | | 176 | + 'test/fixtures/test-runner/user-logs.js', | | 177 | + ]; | | 178 | + const child = spawnSync(process.execPath, args); | | 179 | + | | 180 | + assert.strictEqual(child.status, 0); | | 181 | + assert.strictEqual(child.signal, null); | | 182 | + assert.strictEqual(child.stderr.toString(), ''); | | 183 | + const stdout = child.stdout.toString(); | | 184 | + assert.match(stdout, /# Subtest: .+user-logs\.js/); | | 185 | + assert.match(stdout, / {4}# stderr 1/); | | 186 | + assert.match(stdout, / {4}# stderr 2/); | | 187 | + assert.match(stdout, / {4}# stdout 3/); | | 188 | + assert.match(stdout, / {4}# stderr 6/); | | 189 | + assert.match(stdout, / {4}# not ok 1 - fake test/); | | 190 | + assert.match(stdout, / {4}# stderr 5/); | | 191 | + assert.match(stdout, / {4}# stdout 4/); | | 192 | + assert.match(stdout, / {4}# Subtest: a test/); | | 193 | + assert.match(stdout, / {4}ok 1 - a test/); | | 194 | + assert.match(stdout, /# tests 1/); | | 195 | + assert.match(stdout, /# pass 1/); | | 196 | +} |
|