Skip to content

Commit d2b18ac

Browse files
committed
test: add error only reporter for node:test
This commit introduces a node:test reporter to the common utils. This reporter can be used to silence output other than errors from node:test. This is useful because in Node's own test suite, the output of node:test is included in the output of the Python test runner. Refs: #49120
1 parent d1d5da2 commit d2b18ac

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

test/common/test-error-reporter.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
const { relative } = require('node:path');
3+
const { inspect } = require('node:util');
4+
const cwd = process.cwd();
5+
6+
module.exports = async function* errorReporter(source) {
7+
for await (const event of source) {
8+
if (event.type === 'test:fail') {
9+
const { name, details, line, column, file } = event.data;
10+
let { error } = details;
11+
12+
if (error?.failureType === 'subtestsFailed') {
13+
// In the interest of keeping things concise, skip failures that are
14+
// only due to nested failures.
15+
continue;
16+
}
17+
18+
if (error?.code === 'ERR_TEST_FAILURE') {
19+
error = error.cause;
20+
}
21+
22+
const output = [
23+
`Test failure: '${name}'`,
24+
];
25+
26+
if (file) {
27+
output.push(`Location: ${relative(cwd, file)}:${line}:${column}`);
28+
}
29+
30+
output.push(inspect(error));
31+
output.push('\n');
32+
yield output.join('\n');
33+
}
34+
}
35+
};

test/parallel/test-runner-cli-concurrency.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --test-reporter=./test/common/test-error-reporter.js
12
'use strict';
23
require('../common');
34
const fixtures = require('../common/fixtures');

0 commit comments

Comments
 (0)