forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: nodejs#49120
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters