Skip to content

--changed flag is ignored when running vitest list --changed #8270

@haakonjackfloat

Description

@haakonjackfloat

Describe the bug

The vitest list --changed command ignores the --changed flag and shows all tests instead of only those affected by changed files. This is inconsistent with the behavior of the regular vitest --changed command, which correctly filters tests based on git changes.

I intend to submit a PR to fix this issue.

The fix appears to be trivial – adding changed to the collectCliOptionsConfig in node/cli/cli-config.

Reproduction

Since this relies on Github state I think it's easier to give steps for reproduction instead of trying to create a Stackblitz or Github repo.

Prerequisites

  • A Git repository with test files
  • Some source files that are imported by tests
  • Uncommitted changes in the repository

Steps to reproduce

  1. Set up a test project:

    mkdir test-project && cd test-project
    git init
    npm init -y
    npm install vitest
  2. Create source files:

    mkdir src
    echo 'export function add(a, b) { return a + b }' > src/calculator.js
  3. Create test files:

    echo 'import { describe, it, expect } from "vitest"
    import { add } from "./src/calculator.js"
    
    describe("calculator", () => {
      it("should add numbers", () => {
        expect(add(1, 2)).toBe(3)
      })
    })' > calculator.test.js
    
    echo 'import { describe, it, expect } from "vitest"
    
    describe("unrelated", () => {
      it("should pass", () => {
        expect(true).toBe(true)
      })
    })' > unrelated.test.js
  4. Commit initial files:

    git add .
    git commit -m "Initial commit"
  5. Make a change to the source file:

    echo 'export function add(a, b) { return a + b } // modified' > src/calculator.js
  6. Test the regular vitest command (works correctly):

    npx vitest --changed

    Expected: Only runs calculator.test.js
    Actual: Only runs calculator.test.js

  7. Test the list command (buggy):

    npx vitest list --changed

    Expected: Only shows tests from calculator.test.js
    Actual: Shows all tests from both files ❌

System Info

System:
    OS: macOS 15.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 73.56 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.19.0 - ~/.nvm/versions/node/v20.19.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.19.0/bin/npm
    pnpm: 10.12.2 - ~/.nvm/versions/node/v20.19.0/bin/pnpm
    Watchman: 2024.01.22.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 138.0.7204.93
    Safari: 18.5
  npmPackages:
    @vitest/browser: workspace:* => 4.0.0-beta.2 
    @vitest/coverage-istanbul: workspace:* => 4.0.0-beta.2 
    @vitest/coverage-v8: workspace:* => 4.0.0-beta.2 
    @vitest/ui: workspace:* => 4.0.0-beta.2 
    vite: ^6.3.5 => 6.3.5 
    vitest: workspace:* => 4.0.0-beta.2

Used Package Manager

pnpm

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