Description
Affected URL(s)
https://nodejs.org/api/test.html
Description of the problem
This might also include some buggy behavior, though that could be down to a bad/deprecated example in the docs.
When attempting to run a test with the given example:
run({ files: [path.resolve('./tests/test.js')] })
.pipe(process.stdout);
If there's any error in the calling file or the test, you get:
node:internal/streams/writable:315
throw new ERR_INVALID_ARG_TYPE(
^
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object
at new NodeError (node:internal/errors:399:5)
at _write (node:internal/streams/writable:315:13)
at Writable.write (node:internal/streams/writable:337:10)
at TestsStream.ondata (node:internal/streams/readable:766:22)
at TestsStream.emit (node:events:512:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at #tryPush (node:internal/test_runner/tests_stream:69:28)
at #emit (node:internal/test_runner/tests_stream:64:18) {
code: 'ERR_INVALID_ARG_TYPE'
}
If there's no errors, then it just hangs with no output.
The same test runs fine with node --test
.
Observing the returned TestsStream
for the listed events in the docs (['test:start', 'test:pass', 'test:fail', 'test:diagnostic', 'test:coverage']) and printing the resulting objects shows the test running fine.
Also, using a TransformStream and printing the objects also shows the test running fine.
The error that's shown only when there's an actual error in the file (eg. passing a non-existent file to files
for run
) hints that TestsStream
is now Object Mode which I guess can't be piped directly to stdout
without transformation of some sort.
However, this error doesn't appear when the tests would run in the other aforementioned cases and node
seems to just stop and sit there, it will print a console.log
message placed before and after the run
call and then just sit there indefinitely, even with a timeout
set, a timeout
verified working with the other methods.