Skip to content

vitest list exits with code 0 when a test file fails to parse #11145

Description

@hamed-bavar

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

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