Describe the bug
Since 5.0.0, vitest list parses test files statically by default (#11088). On that path a file that fails to parse is reported as an error, but the command still exits 0.
With a test file that has a syntax error:
npx vitest list # error on stderr, no listing, exit 0
npx vitest list --json # error on stderr, no JSON, exit 0
npx vitest list --no-static-parse # parse error with code frame, exit 1
The --json case is the damaging one. A CI step reading that output gets empty stdout and a success exit code, so a file that does not compile looks like a project with no tests.
Vitest.collect() only sets process.exitCode in the branch that calls collectTests. The static branch returns without it. #11088 also moved the exit code assertion in test/e2e/test/list.test.ts onto --no-static-parse, so nothing covers the default path.
I have a fix and a test, and will open a PR.
Reproduction
https://github.com/hamed-bavar/vitest-list-exit-code
System Info
System:
OS: Windows 11 10.0.26200
CPU: (12) x64 AMD Ryzen 5 7535HS with Radeon Graphics
Memory: 12.66 GB / 31.24 GB
Binaries:
Node: 22.18.0
Yarn: 1.22.22
npm: 10.9.3
pnpm: 11.24.0
Browsers:
Chrome: 152.0.7977.65
Edge: Chromium (152.0.4191.53)
Firefox: 155.0
npmPackages:
vitest: 5.0.0 => 5.0.0
Used Package Manager
npm
Validations
Describe the bug
Since 5.0.0,
vitest listparses test files statically by default (#11088). On that path a file that fails to parse is reported as an error, but the command still exits 0.With a test file that has a syntax error:
The
--jsoncase is the damaging one. A CI step reading that output gets empty stdout and a success exit code, so a file that does not compile looks like a project with no tests.Vitest.collect()only setsprocess.exitCodein the branch that callscollectTests. The static branch returns without it. #11088 also moved the exit code assertion intest/e2e/test/list.test.tsonto--no-static-parse, so nothing covers the default path.I have a fix and a test, and will open a PR.
Reproduction
https://github.com/hamed-bavar/vitest-list-exit-code
System Info
System: OS: Windows 11 10.0.26200 CPU: (12) x64 AMD Ryzen 5 7535HS with Radeon Graphics Memory: 12.66 GB / 31.24 GB Binaries: Node: 22.18.0 Yarn: 1.22.22 npm: 10.9.3 pnpm: 11.24.0 Browsers: Chrome: 152.0.7977.65 Edge: Chromium (152.0.4191.53) Firefox: 155.0 npmPackages: vitest: 5.0.0 => 5.0.0Used Package Manager
npm
Validations