mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 14:18:44 +02:00

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: https://github.com/nodejs/node/issues/49120 PR-URL: https://github.com/nodejs/node/pull/56438 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
'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');
|
|
|
|
if (process.env.FAIL_FAST) {
|
|
yield `\nBailing on failed test: ${event.data.name}\n`;
|
|
process.exitCode = 1;
|
|
process.emit('SIGINT');
|
|
}
|
|
}
|
|
}
|
|
};
|