Skip to content

Commit

Permalink
test: add error only reporter for node:test
Browse files Browse the repository at this point in the history
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: nodejs#49120
  • Loading branch information
cjihrig committed Jun 19, 2024
1 parent fbfbb6a commit 3a8cf6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/common/test-error-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
const { relative } = require('node:path');
const { inspect } = require('node:util');
const cwd = process.cwd();

module.exports = async function* errorReporter(source) {
for await (const event of source) {
if (event.type === 'test:fail') {
const { name, details, line, column, file } = event.data;
let { error } = details;

if (error?.failureType === 'subtestsFailed') {
// In the interest of keeping things concise, skip failures that are
// only due to nested failures.
continue;
}

if (error?.code === 'ERR_TEST_FAILURE') {
error = error.cause;
}

const output = [
`Test failure: '${name}'`,
];

if (file) {
output.push(`Location: ${relative(cwd, file)}:${line}:${column}`);
}

output.push(inspect(error));
output.push('\n');
yield output.join('\n');
}
}
};
1 change: 1 addition & 0 deletions test/parallel/test-runner-cli-concurrency.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --test-reporter=./test/common/test-error-reporter.js
'use strict';
require('../common');
const fixtures = require('../common/fixtures');
Expand Down

0 comments on commit 3a8cf6c

Please sign in to comment.