Describe the bug
Since 5.0.0, vitest list parses test files statically by default (#11088). When a file fails to parse, the only output is:
{ name: 'Error', message: undefined, stack: '', stacks: [] }
--no-static-parse prints the real error for the same file: the parse diagnostic with its code frame, then Plugin: vite:oxc and File: ....
serializeError in packages/vitest/src/node/ast-collect.ts reads e.text and e.location from each entry of a Vite transform error. Those are esbuild's field names, and the function was written that way in fdeb2f4, when esbuild was the transformer. Vite 8 uses oxc, whose entries carry message and loc instead, so both reads return undefined. printErrorMessage then sees no message and dumps the raw object.
The runtime path does not build these errors by hand. It wraps the transform in handleRollupError, which keeps plugin, id, loc and frame under __vitest_rollup_error__ for the printer. Static collection can reuse that.
Resolve errors are unaffected. They carry pluginCode but no errors array, so they never reach that branch.
I have a fix and tests for it, and will open a PR.
Reproduction
https://github.com/hamed-bavar/vitest-list-exit-code
broken.test.ts is missing its closing brace. After npm install:
npx vitest list # the raw object above
npx vitest list --no-static-parse # the real parse error
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). When a file fails to parse, the only output is:--no-static-parseprints the real error for the same file: the parse diagnostic with its code frame, thenPlugin: vite:oxcandFile: ....serializeErrorinpackages/vitest/src/node/ast-collect.tsreadse.textande.locationfrom each entry of a Vite transform error. Those are esbuild's field names, and the function was written that way in fdeb2f4, when esbuild was the transformer. Vite 8 uses oxc, whose entries carrymessageandlocinstead, so both reads return undefined.printErrorMessagethen sees no message and dumps the raw object.The runtime path does not build these errors by hand. It wraps the transform in
handleRollupError, which keepsplugin,id,locandframeunder__vitest_rollup_error__for the printer. Static collection can reuse that.Resolve errors are unaffected. They carry
pluginCodebut noerrorsarray, so they never reach that branch.I have a fix and tests for it, and will open a PR.
Reproduction
https://github.com/hamed-bavar/vitest-list-exit-code
broken.test.tsis missing its closing brace. Afternpm install: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