Vitest
Vitest

Running Tests

Run all tests in watch mode

$vitest

Run all tests once without watch mode

$vitest run

Run all tests in explicit watch mode, re-running on file changes

$vitest watch

Alias for vitest watch — run tests in interactive watch mode

$vitest dev

Run tests matching a specific file path or pattern once

$vitest run src/utils

Run a single specific test file once

$vitest run src/utils/math.test.ts

Run all tests once with verbose output showing each test name

$vitest run --reporter=verbose

Run all tests once with minimal dot-style reporter output

$vitest run --reporter=dot

Run all tests once and output results as JSON to stdout

$vitest run --reporter=json

Run all tests and write JSON results to a file

$vitest run --reporter=json --outputFile=results.json

Run all tests and output results in JUnit XML format

$vitest run --reporter=junit

Run all tests and write JUnit XML results to a file

$vitest run --reporter=junit --outputFile=junit.xml

Run all tests and generate an HTML report

$vitest run --reporter=html

Run tests with multiple reporters simultaneously

$vitest run --reporter=verbose --reporter=json --outputFile=results.json

Run all tests suppressing console output from test files

$vitest run --silent

Stop running tests after the first test failure

$vitest run --bail=1

Stop running tests after 3 test failures

$vitest run --bail=3

Run tests without ANSI color codes in the output

$vitest run --no-color

Allow test.only and describe.only in CI without throwing an error

$vitest run --allowOnly

Exit with code 0 even when no test files are found

$vitest run --passWithNoTests

Run tests hiding skipped test entries from the output

$vitest run --hideSkippedTests

Run only tests whose names match a given regex pattern

$vitest --testNamePattern="should return"

Run once only tests whose names contain the word auth

$vitest run --testNamePattern="auth"

Run tests for a specific named project in a multi-project setup

$vitest run --project=frontend

Run tests for multiple specified projects in a multi-project setup

$vitest run --project=frontend --project=backend

Watch Mode

Run only tests related to files changed since the last git commit

$vitest --changed

Run only tests related to files changed in the last git commit

$vitest --changed HEAD~1

Run only tests related to files changed compared to origin/main

$vitest --changed origin/main

Force a full test rerun when files in a specific path change

$vitest --force-rerun-triggers src/utils

Run in watch mode with verbose output showing individual test names

$vitest --watch --reporter=verbose

Coverage

Run all tests once and collect code coverage using the default provider

$vitest run --coverage

Run tests in watch mode with code coverage enabled

$vitest --coverage

Run tests with coverage using the V8 native coverage provider

$vitest run --coverage --coverage.provider=v8

Run tests with coverage using the Istanbul coverage provider

$vitest run --coverage --coverage.provider=istanbul

Run tests and output a text coverage summary to the terminal

$vitest run --coverage --coverage.reporter=text

Run tests and generate an lcov coverage report

$vitest run --coverage --coverage.reporter=lcov

Run tests and generate an HTML coverage report

$vitest run --coverage --coverage.reporter=html

Run tests and generate a JSON coverage report

$vitest run --coverage --coverage.reporter=json

Run tests generating both text and HTML coverage reports

$vitest run --coverage --coverage.reporter=text --coverage.reporter=html

Collect coverage only for files matching the specified glob pattern

$vitest run --coverage --coverage.include="src/**"

Exclude specific files from coverage collection

$vitest run --coverage --coverage.exclude="src/**/*.d.ts"

Include all project files in coverage even if they have no tests

$vitest run --coverage --coverage.all

Fail the run if line coverage falls below 80 percent

$vitest run --coverage --coverage.thresholds.lines=80

Fail the run if function coverage falls below 80 percent

$vitest run --coverage --coverage.thresholds.functions=80

Fail the run if branch coverage falls below 80 percent

$vitest run --coverage --coverage.thresholds.branches=80

Fail the run if statement coverage falls below 80 percent

$vitest run --coverage --coverage.thresholds.statements=80

Write coverage reports to a specific output directory

$vitest run --coverage --coverage.reportsDirectory=./coverage

Configuration

Run tests using a specific Vitest configuration file

$vitest run --config vitest.config.ts

Run tests using a configuration file at a custom path

$vitest run --config ./config/vitest.config.ts

Set the root directory for test file discovery

$vitest run --root ./packages/core

Run tests only in files found within a specific directory

$vitest run --dir src

Run tests in a Node.js environment

$vitest run --environment node

Run tests in a jsdom browser-simulated environment

$vitest run --environment jsdom

Run tests in a happy-dom browser-simulated environment

$vitest run --environment happy-dom

Run tests in an edge runtime environment

$vitest run --environment edge-runtime

Run tests with Vitest globals like describe and expect injected without imports

$vitest run --globals

Run each test file in an isolated module environment

$vitest run --isolate

Disable module isolation, sharing module state across test files

$vitest run --no-isolate

Run tests using worker threads pool

$vitest run --pool=threads

Run tests using child process forks pool

$vitest run --pool=forks

Run tests in a VM context within worker threads

$vitest run --pool=vmThreads

Run tests in a VM context within child process forks

$vitest run --pool=vmForks

Set the maximum number of worker threads for the threads pool

$vitest run --poolOptions.threads.maxThreads=4

Set the minimum number of worker threads for the threads pool

$vitest run --poolOptions.threads.minThreads=1

Set the maximum number of child process forks

$vitest run --poolOptions.forks.maxForks=4

Run all tests in a single worker thread sequentially

$vitest run --singleThread

Run all tests in a single child process fork sequentially

$vitest run --singleFork

Limit the number of concurrent worker processes or threads

$vitest run --maxWorkers=4

Set the minimum number of concurrent worker processes or threads

$vitest run --minWorkers=1

Run test files and suites in a randomized order

$vitest run --sequence.shuffle

Run tests in a shuffled order seeded with a specific value for reproducibility

$vitest run --sequence.seed=42

Run tests within each file concurrently

$vitest run --sequence.concurrent

Disable worker threads, running tests in the main process

$vitest run --no-threads

Run tests with Node.js inspector enabled for debugging

$vitest run --inspect

Run tests with Node.js inspector enabled, pausing on the first line

$vitest run --inspect-brk

Log heap memory usage after each test for memory profiling

$vitest run --logHeapUsage

Disable interception and buffering of console output during tests

$vitest run --disable-console-intercept

Filtering & Targeting

Run all tests within the src/auth directory

$vitest run src/auth

Run tests whose file paths match both auth and login

$vitest run auth login

Exclude tests matching a path pattern from the run

$vitest run --exclude src/legacy

Run only test files matching a specific glob pattern

$vitest run --include="**/*.spec.ts"

Run test files matching multiple glob patterns

$vitest run --include="**/*.test.ts" --include="**/*.spec.ts"

Set the timeout in milliseconds for each individual test

$vitest run --testTimeout=10000

Set the timeout in milliseconds for before and after hooks

$vitest run --hookTimeout=10000

Set the timeout in milliseconds for teardown functions

$vitest run --teardownTimeout=5000

Retry failing tests up to 3 times before marking them as failed

$vitest run --retry=3

Repeat every test 5 times to detect flakiness

$vitest run --repeat=5

UI Mode

Open the Vitest browser UI for interactive test inspection

$vitest --ui

Start the Vitest UI server without auto-opening the browser

$vitest --ui --open=false

Open the Vitest UI with code coverage enabled

$vitest --ui --coverage

Start the Vitest UI server on a specific port

$vitest --ui --port=51205

Browser Mode

Run tests in a real browser environment using the default provider

$vitest run --browser

Run tests in a Chromium browser instance

$vitest run --browser=chromium

Run tests in a Firefox browser instance

$vitest run --browser=firefox

Run tests in a WebKit browser instance

$vitest run --browser=webkit

Run browser tests in headless mode without opening a visible window

$vitest run --browser --browser.headless

Run browser tests using Playwright as the browser provider

$vitest run --browser --browser.provider=playwright

Run browser tests using WebdriverIO as the browser provider

$vitest run --browser --browser.provider=webdriverio

Benchmark

Run all benchmark files in watch mode

$vitest bench

Run all benchmark files once without watch mode

$vitest bench --run

Run a specific benchmark file once

$vitest bench --run src/utils.bench.ts

Run benchmarks once with verbose output showing all results

$vitest bench --run --reporter=verbose

Run benchmarks once and write results to a JSON file

$vitest bench --run --outputFile=benchmark-results.json

Type Checking

Run type checking on test files using TypeScript without executing tests

$vitest typecheck

Run type checking on test files once without watch mode

$vitest typecheck --run

Run type checking only on test files matching a path pattern

$vitest typecheck src/auth

Run tests and type checking simultaneously

$vitest run --typecheck

Run only type checking, skipping actual test execution

$vitest run --typecheck.only

Run type checking using tsc as the type checker

$vitest run --typecheck --typecheck.checker=tsc

Run type checking using vue-tsc for Vue project test files

$vitest run --typecheck --typecheck.checker=vue-tsc

Miscellaneous

Display the currently installed version of Vitest

$vitest --version

Display help information and all available CLI options

$vitest --help

List all test files that would be collected without running them

$vitest list

List test files matching a path pattern without running them

$vitest list src/auth

List collected test files and output as JSON

$vitest list --json

Update all outdated snapshot files to match current output

$vitest run --update

Update snapshots only for test files matching a path pattern

$vitest run --update src/components

Run in watch mode updating snapshots automatically on change

$vitest run --watch --update

Clear the Vitest transform cache and exit

$vitest run --clearCache

Disable transform caching for this run

$vitest run --cache=false

Use a custom directory for the transform cache

$vitest run --cacheDir=.vitest-cache

Use a custom diff configuration file for test failure output

$vitest run --diff=vitest-diff-options.ts

Show the full diff in snapshot failure output without truncation

$vitest run --expand-snapshot-diff

Print a stack trace alongside each console.log call in tests

$vitest run --printConsoleTrace

Retry a test suite if it exits with a segfault up to 3 times

$vitest run --segfaultRetry=3