Description
Version
20.5.1
Platform
Darwin [redacted] 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
Using the environment variable NODE_V8_COVERAGE
when running a Node.js script with the Node.js CLI option --test
can intermittently cause the process to never exit. On such occasions, (when using --test-reporter=spec
) the final report of modules that were run as tests, but didn't contain any tests, as well as the final summary of the test/suite/etc. counts, never prints in the console. Running the same script without setting NODE_V8_COVERAGE
always succeeds as expected.
I have tried for several months to figure out a minimal reproduction for a bug report, but was only encountering the issue in large private codebases at work. You can see discussion about it here:
https://node-js.slack.com/archives/C3910A78T/p1686119658586369
Finally I have encountered the issue in one of my public open source repos and can share it here. Clone this branch:
https://github.com/jaydenseric/graphql-upload/tree/jaydenseric/node-test-runner
Specifically this commit introduces the issue:
jaydenseric/graphql-upload@3b7f034
After cloning, run npm install
and then run the script npm run tests
.
How often does it reproduce? Is there a required condition?
It reproduces perhaps 80% of the time, but for reasons I can't determine this can vary wildly to as much as 100% of the time depending when you run it.
You can prevent the environment variable NODE_V8_COVERAGE
being set by changing the tests
script:
- "tests": "coverage-node --test-reporter=spec --test",
+ "tests": "node --test-reporter=spec --test",
After doing this the script should always succeed, although without a final code coverage report printing.
What is the expected behavior? Why is that the expected behavior?
When the script intermittently succeeds, it is supposed to look like this:

What do you see instead?
Notice that most of the time, the script permanently hangs at this point:

At this time the node
processes in macOS Activity Monitor look like this:

If you manually quit the node
process with a higher ID and high CPU utilisation, the Node.js script exits like this:

Additional information
Past discussion about this issue:
https://node-js.slack.com/archives/C3910A78T/p1686119658586369