Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vitest 3.x reference skill covering configuration, test/describe APIs, mocking, coverage, snapshots, and concurrency.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/core-cli.md
1---2name: vitest-cli3description: Command line interface commands and options4---56# Command Line Interface78## Commands910### `vitest`1112Start Vitest in watch mode (dev) or run mode (CI):1314```bash15vitest # Watch mode in dev, run mode in CI16vitest foobar # Run tests containing "foobar" in path17vitest basic/foo.test.ts:10 # Run specific test by file and line number18```1920### `vitest run`2122Run tests once without watch mode:2324```bash25vitest run26vitest run --coverage27```2829### `vitest watch`3031Explicitly start watch mode:3233```bash34vitest watch35```3637### `vitest related`3839Run tests that import specific files (useful with lint-staged):4041```bash42vitest related src/index.ts src/utils.ts --run43```4445### `vitest bench`4647Run only benchmark tests:4849```bash50vitest bench51```5253### `vitest list`5455List all matching tests without running them:5657```bash58vitest list # List test names59vitest list --json # Output as JSON60vitest list --filesOnly # List only test files61```6263### `vitest init`6465Initialize project setup:6667```bash68vitest init browser # Set up browser testing69```7071## Common Options7273```bash74# Configuration75--config <path> # Path to config file76--project <name> # Run specific project7778# Filtering79--testNamePattern, -t # Run tests matching pattern80--changed # Run tests for changed files81--changed HEAD~1 # Tests for last commit changes8283# Reporters84--reporter <name> # default, verbose, dot, json, html85--reporter=html --outputFile=report.html8687# Coverage88--coverage # Enable coverage89--coverage.provider v8 # Use v8 provider90--coverage.reporter text,html9192# Execution93--shard <index>/<count> # Split tests across machines94--bail <n> # Stop after n failures95--retry <n> # Retry failed tests n times96--sequence.shuffle # Randomize test order9798# Watch mode99--no-watch # Disable watch mode100--standalone # Start without running tests101102# Environment103--environment <env> # jsdom, happy-dom, node104--globals # Enable global APIs105106# Debugging107--inspect # Enable Node inspector108--inspect-brk # Break on start109110# Output111--silent # Suppress console output112--no-color # Disable colors113```114115## Package.json Scripts116117```json118{119"scripts": {120"test": "vitest",121"test:run": "vitest run",122"test:ui": "vitest --ui",123"coverage": "vitest run --coverage"124}125}126```127128## Sharding for CI129130Split tests across multiple machines:131132```bash133# Machine 1134vitest run --shard=1/3 --reporter=blob135136# Machine 2137vitest run --shard=2/3 --reporter=blob138139# Machine 3140vitest run --shard=3/3 --reporter=blob141142# Merge reports143vitest --merge-reports --reporter=junit144```145146## Watch Mode Keyboard Shortcuts147148In watch mode, press:149- `a` - Run all tests150- `f` - Run only failed tests151- `u` - Update snapshots152- `p` - Filter by filename pattern153- `t` - Filter by test name pattern154- `q` - Quit155156## Key Points157158- Watch mode is default in dev, run mode in CI (when `process.env.CI` is set)159- Use `--run` flag to ensure single run (important for lint-staged)160- Both camelCase (`--testTimeout`) and kebab-case (`--test-timeout`) work161- Boolean options can be negated with `--no-` prefix162163<!--164Source references:165- https://vitest.dev/guide/cli.html166-->167