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### `vitest --list-tags`7273List tags defined in config without running tests:7475```bash76vitest --list-tags # Human-readable list77vitest --list-tags=json # JSON output78```7980## Common Options8182```bash83# Configuration84--config <path> # Path to config file85--project <name> # Run specific project8687# Filtering88--testNamePattern, -t # Run tests matching pattern89--tagsFilter <expr> # Run tests by tag expression, e.g. "db && !flaky"90--changed # Run tests for changed files91--changed HEAD~1 # Tests for last commit changes92--dir <path> # Limit test discovery to a directory9394# Reporters95--reporter <name> # default, verbose, tree, dot, json, html, junit, minimal, blob96--reporter=json --outputFile=report.json9798# Coverage99--coverage # Enable coverage100--coverage.provider v8 # Use v8 provider101--coverage.reporter text,html102103# Execution104--shard <index>/<count> # Split tests across machines105--bail <n> # Stop after n failures106--retry <n> # Retry failed tests n times107--shuffle # Randomize test order108--no-file-parallelism # Run test files one at a time109110# Watch mode111--no-watch # Disable watch mode112--standalone # Start without running (v4: runs matched files if a filter is passed)113114# Environment115--environment <env> # jsdom, happy-dom, node116--globals # Enable global APIs117118# Debugging119--inspect # Enable Node inspector120--inspect-brk # Break on start121122# Output123--silent # Suppress console output124--no-color # Disable colors125```126127## Package.json Scripts128129```json130{131"scripts": {132"test": "vitest",133"test:run": "vitest run",134"test:ui": "vitest --ui",135"coverage": "vitest run --coverage"136}137}138```139140## Sharding for CI141142Split tests across multiple machines. The blob reporter writes to `.vitest/blob/` by default:143144```bash145# Machine 1146vitest run --shard=1/3 --reporter=blob --outputFile=reports/blob-1.json147148# Machine 2149vitest run --shard=2/3 --reporter=blob --outputFile=reports/blob-2.json150151# Merge all blobs into a final report152vitest --merge-reports=reports --reporter=junit --reporter=default153```154155## Watch Mode Keyboard Shortcuts156157In watch mode, press:158- `a` - Run all tests159- `f` - Run only failed tests160- `u` - Update snapshots161- `p` - Filter by filename pattern162- `t` - Filter by test name pattern163- `q` - Quit164165## Key Points166167- Watch mode is default in dev, run mode in CI (when `process.env.CI` is set)168- Use `--run` flag to ensure single run (important for lint-staged)169- Both camelCase (`--testTimeout`) and kebab-case (`--test-timeout`) work170- Boolean options can be negated with `--no-` prefix171- Filter tests by tag with `--tagsFilter` (tags must be declared in config) — see [features-test-tags](features-test-tags.md)172- `--merge-reports` and `--reporter=blob` do not work in watch mode173174<!--175Source references:176- https://vitest.dev/guide/cli.html177-->178