All skills
antfu avatar

/vitest

@d02c484 official
by Anthony Fuantfu/skills5.9k stars
335

Vitest fast unit testing framework powered by Vite with Jest-compatible API. Use when writing tests, mocking, configuring coverage, or working with test filtering and fixtures.

Use this Skill: https://skilld.dev/gh/antfu/skills/vitest

This session only. Nothing lands on disk.

referencescore-cli.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Command Line Interface

Commands

vitest

Start Vitest in watch mode (dev) or run mode (CI):

vitest                    # Watch mode in dev, run mode in CI
vitest foobar             # Run tests containing "foobar" in path
vitest basic/foo.test.ts:10  # Run specific test by file and line number

vitest run

Run tests once without watch mode:

vitest run
vitest run --coverage

vitest watch

Explicitly start watch mode:

vitest watch

vitest related

Run tests that import specific files (useful with lint-staged):

vitest related src/index.ts src/utils.ts --run

vitest bench

Run only benchmark tests:

vitest bench

vitest list

List all matching tests without running them:

vitest list                    # List test names
vitest list --json             # Output as JSON
vitest list --filesOnly        # List only test files

v5: list parses test files statically instead of running them. Pass --no-static-parse to run them; tune with --static-parse-concurrency.

vitest doctor (v5)

Run the suite under alternative configs and recommend faster options (e.g. a different pool, isolate: false, fsModuleCache, lower maxWorkers). Needs a passing baseline; takes several times a normal run:

vitest doctor

vitest init

Initialize project setup:

vitest init browser            # Set up browser testing

vitest --list-tags

List tags defined in config without running tests:

vitest --list-tags             # Human-readable list
vitest --list-tags=json        # JSON output

Common Options

# Configuration
--config <path>           # Path to config file
--project, -p <name>      # Run specific project (v5 adds the -p shorthand)

# Filtering
--testNamePattern, -t     # Run tests matching pattern
--tagsFilter <expr>       # Run tests by tag expression, e.g. "db && !flaky"
--changed                 # Run tests for changed files
--changed HEAD~1          # Tests for last commit changes
--dir <path>              # Limit test discovery to a directory

# Reporters
--reporter <name>         # default, verbose, tree, dot, json, html, junit, minimal, blob
--reporter=json --outputFile=report.json

# Coverage
--coverage                # Enable coverage
--coverage.provider v8    # Use v8 provider
--coverage.reporter text,html

# Execution
--shard <index>/<count>   # Split tests across machines
--bail <n>                # Stop after n failures
--retry <n>               # Retry failed tests n times
--repeats <n>             # v5: repeat every test n times (hunt flaky tests)
--shuffle                 # Randomize test order
--no-file-parallelism     # Run test files one at a time

# Watch mode
--no-watch                # Disable watch mode
--standalone              # Start without running (v4: runs matched files if a filter is passed)

# Environment
--environment <env>       # jsdom, happy-dom, node
--globals                 # Enable global APIs

# Debugging
--inspect                 # Enable Node inspector
--inspect-brk             # Break on start

# Output
--silent                  # Suppress console output
--no-color                # Disable colors

Package.json Scripts

{
  "scripts": {
    "test": "vitest",
    "test:run": "vitest run",
    "test:ui": "vitest --ui",
    "coverage": "vitest run --coverage"
  }
}

Sharding for CI

Split tests across multiple machines. The blob reporter writes to .vitest/blob/ by default:

# Machine 1
vitest run --shard=1/3 --reporter=blob --outputFile=reports/blob-1.json

# Machine 2
vitest run --shard=2/3 --reporter=blob --outputFile=reports/blob-2.json

# Merge all blobs into a final report
vitest --merge-reports=reports --reporter=junit --reporter=default

Watch Mode Keyboard Shortcuts

In watch mode, press:

  • a - Run all tests
  • f - Run only failed tests
  • u - Update snapshots
  • p - Filter by filename pattern
  • t - Filter by test name pattern
  • q - Quit

Key Points

  • Watch mode is default in dev, run mode in CI (when process.env.CI is set)
  • Use --run flag to ensure single run (important for lint-staged)
  • Both camelCase (--testTimeout) and kebab-case (--test-timeout) work
  • Boolean options can be negated with --no- prefix
  • Filter tests by tag with --tagsFilter (tags must be declared in config) — see features-test-tags
  • --merge-reports and --reporter=blob do not work in watch mode (--merge-reports now handles non-sharded multi-environment runs)
  • v5: use -p as shorthand for --project; vitest doctor suggests faster config
<!-- Source references: - https://vitest.dev/guide/cli.html -->

Source: SKILL.md on GitHub

No alerts3d5 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    The skill provides comprehensive documentation and reference material for the Vitest testing framework. It covers configuration, CLI usage, mocking, coverage, and advanced features like type testing and benchmarking. No security issues were detected; the instructions follow standard development and testing practices.

  • Socket3d

    No alerts

  • Snyk3d

    Risk: LOW · No issues

  • Runlayer7mo

    1/18 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at d02c484. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 4 days ago
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.9.25",
  "source": "Generated from https://github.com/vitest-dev/vitest, scripts located at https://github.com/antfu/skills"
}

README badge

README badge for antfu/skills/vitest

Vitest is a Jest-compatible unit testing framework powered by Vite, with native ESM, TypeScript, and JSX support. Use it for writing tests with smart watch mode, mocking, fixtures, coverage reporting, and snapshot testing in projects already using Vite.

Generated from the current SKILL.md.

Is Vitest a drop-in replacement for Jest?
Mostly. Vitest provides a Jest-compatible API and can run most Jest test suites without modification, but it uses Vite's transformation pipeline instead of Jest's, so some edge cases may differ.
Does Vitest require configuration?
No. It natively supports ESM, TypeScript, and JSX out of the box and shares Vite's config, transformers, and resolvers, so many projects need minimal or no additional setup.
What coverage providers does Vitest support?
Vitest includes built-in coverage via V8 or Istanbul providers.
Can I run tests in parallel?
Yes. Vitest uses multi-threaded workers for parallel test execution and supports sharding across multiple processes.
What test environments are available?
Vitest supports node, jsdom, happy-dom, and custom environments.

Generated from the current SKILL.md. These answers refresh after source changes.