Skip to content

Unhandled errors caught during a run are missing from the JUnit XML report #10242

@gbleu

Description

@gbleu

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions