Describe the bug
When Vitest catches an unhandled rejection or uncaught exception during a test run (via its worker process-level handler), the CLI prints an ⎯ Unhandled Errors ⎯ section, the run summary shows Errors 1 error, and the process exits with code 1. None of this is reflected in the JUnit XML report — <testsuites> and <testsuite> both still report failures="0" errors="0" and contain only the passing testcases.
CI systems that gate on the JUnit artifact (Jenkins JUnit plugin, GitLab MR test widget, Azure Pipelines test tab, CircleCI test insights, etc.) therefore report the build as green even though the run actually failed.
A real-world example where this bites: a worker process exiting unexpectedly surfaces as:
[vitest-pool]: Worker forks emitted error
Caused by: Error: Worker exited unexpectedly
…which lands in the same Unhandled Errors channel and is similarly absent from the JUnit XML.
Expected
The JUnit report should reflect the unhandled error that Vitest already counted in its Errors summary line — for example via a non-zero errors= count on the suite, an <error> element, or a synthetic <testcase> carrying the error.
Actual
vitest run stdout (truncated):
✓ src/repro.test.ts (1 test) 2ms
⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯
Vitest caught 1 unhandled error during the test run.
…
Test Files 1 passed (1)
Tests 1 passed (1)
Errors 1 error
Exit code: 1. junit-report.xml:
<testsuites name="vitest tests" tests="1" failures="0" errors="0" …>
<testsuite name="src/repro.test.ts" tests="1" failures="0" errors="0" skipped="0" …>
<testcase classname="src/repro.test.ts" name="passes …" time="…"/>
</testsuite>
</testsuites>
Related history
Reproduction
Repo: https://github.com/gbleu/vitest-junit-unhandled-repro
git clone https://github.com/gbleu/vitest-junit-unhandled-repro
cd vitest-junit-unhandled-repro
npm install
npm test; echo "exit=$?"
cat junit-report.xml
Observe Errors 1 error and exit=1 in stdout, while junit-report.xml reports failures="0" errors="0".
System Info
System:
OS: macOS 26.4.1
CPU: (10) arm64 Apple M4
Memory: 1.30 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.15.0
Yarn: 1.22.22
npm: 11.12.1
pnpm: 10.33.0
bun: 1.3.5
Browsers:
Chrome: 147.0.7727.138
Safari: 26.4
npmPackages:
vitest: 4.1.5 => 4.1.5
Used Package Manager
npm
Validations
Describe the bug
When Vitest catches an unhandled rejection or uncaught exception during a test run (via its worker process-level handler), the CLI prints an
⎯ Unhandled Errors ⎯section, the run summary showsErrors 1 error, and the process exits with code1. None of this is reflected in the JUnit XML report —<testsuites>and<testsuite>both still reportfailures="0" errors="0"and contain only the passing testcases.CI systems that gate on the JUnit artifact (Jenkins JUnit plugin, GitLab MR test widget, Azure Pipelines test tab, CircleCI test insights, etc.) therefore report the build as green even though the run actually failed.
A real-world example where this bites: a worker process exiting unexpectedly surfaces as:
…which lands in the same
Unhandled Errorschannel and is similarly absent from the JUnit XML.Expected
The JUnit report should reflect the unhandled error that Vitest already counted in its
Errorssummary line — for example via a non-zeroerrors=count on the suite, an<error>element, or a synthetic<testcase>carrying the error.Actual
vitest runstdout (truncated):Exit code:
1.junit-report.xml:Related history
beforeAll/afterAllfailed #4799 / fix(vitest): showbeforeAll/afterAllerrors in junit reporter #4819 (closing JUNIT reporter doesn't mark test as failed if thebeforeAllthrows error #4516) covered synchronous throws insidebeforeAll/afterAll. They do not cover errors that go through Vitest's process-level unhandled-error handler.Reproduction
Repo: https://github.com/gbleu/vitest-junit-unhandled-repro
Observe
Errors 1 errorandexit=1in stdout, whilejunit-report.xmlreportsfailures="0" errors="0".System Info
System: OS: macOS 26.4.1 CPU: (10) arm64 Apple M4 Memory: 1.30 GB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.15.0 Yarn: 1.22.22 npm: 11.12.1 pnpm: 10.33.0 bun: 1.3.5 Browsers: Chrome: 147.0.7727.138 Safari: 26.4 npmPackages: vitest: 4.1.5 => 4.1.5Used Package Manager
npm
Validations