Skip to content

vitest list loses the error details when a test file fails to parse #11150

Description

@hamed-bavar

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions