-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
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
-
Set up a test project:
mkdir test-project && cd test-project git init npm init -y npm install vitest
-
Create source files:
mkdir src echo 'export function add(a, b) { return a + b }' > src/calculator.js
-
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
-
Commit initial files:
git add . git commit -m "Initial commit"
-
Make a change to the source file:
echo 'export function add(a, b) { return a + b } // modified' > src/calculator.js
-
Test the regular vitest command (works correctly):
npx vitest --changed
Expected: Only runs
calculator.test.js
Actual: Only runscalculator.test.js
✅ -
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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.