Vitest commands

Vite-native unit testing framework with Jest-compatible API

125 commands

Running Tests

  • vitest

    Run all tests in watch mode

  • vitest run

    Run all tests once without watch mode

  • vitest watch

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

  • vitest dev

    Alias for vitest watch — run tests in interactive watch mode

  • vitest run src/utils

    Run tests matching a specific file path or pattern once

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

    Run a single specific test file once

  • vitest run --reporter=verbose

    Run all tests once with verbose output showing each test name

  • vitest run --reporter=dot

    Run all tests once with minimal dot-style reporter output

  • vitest run --reporter=json

    Run all tests once and output results as JSON to stdout

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

    Run all tests and write JSON results to a file

  • vitest run --reporter=junit

    Run all tests and output results in JUnit XML format

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

    Run all tests and write JUnit XML results to a file

  • vitest run --reporter=html

    Run all tests and generate an HTML report

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

    Run tests with multiple reporters simultaneously

  • vitest run --silent

    Run all tests suppressing console output from test files

  • vitest run --bail=1

    Stop running tests after the first test failure

  • vitest run --bail=3

    Stop running tests after 3 test failures

  • vitest run --no-color

    Run tests without ANSI color codes in the output

  • vitest run --allowOnly

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

  • vitest run --passWithNoTests

    Exit with code 0 even when no test files are found

  • vitest run --hideSkippedTests

    Run tests hiding skipped test entries from the output

  • vitest --testNamePattern="should return"

    Run only tests whose names match a given regex pattern

  • vitest run --testNamePattern="auth"

    Run once only tests whose names contain the word auth

  • vitest run --project=frontend

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

  • vitest run --project=frontend --project=backend

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

Watch Mode

  • vitest --changed

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

  • vitest --changed HEAD~1

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

  • vitest --changed origin/main

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

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

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

  • vitest --watch --reporter=verbose

    Run in watch mode with verbose output showing individual test names

Coverage

  • vitest run --coverage

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

  • vitest --coverage

    Run tests in watch mode with code coverage enabled

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

    Run tests with coverage using the V8 native coverage provider

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

    Run tests with coverage using the Istanbul coverage provider

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

    Run tests and output a text coverage summary to the terminal

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

    Run tests and generate an lcov coverage report

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

    Run tests and generate an HTML coverage report

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

    Run tests and generate a JSON coverage report

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

    Run tests generating both text and HTML coverage reports

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

    Collect coverage only for files matching the specified glob pattern

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

    Exclude specific files from coverage collection

  • vitest run --coverage --coverage.all

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

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

    Fail the run if line coverage falls below 80 percent

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

    Fail the run if function coverage falls below 80 percent

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

    Fail the run if branch coverage falls below 80 percent

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

    Fail the run if statement coverage falls below 80 percent

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

    Write coverage reports to a specific output directory

Configuration

  • vitest run --config vitest.config.ts

    Run tests using a specific Vitest configuration file

  • vitest run --config ./config/vitest.config.ts

    Run tests using a configuration file at a custom path

  • vitest run --root ./packages/core

    Set the root directory for test file discovery

  • vitest run --dir src

    Run tests only in files found within a specific directory

  • vitest run --environment node

    Run tests in a Node.js environment

  • vitest run --environment jsdom

    Run tests in a jsdom browser-simulated environment

  • vitest run --environment happy-dom

    Run tests in a happy-dom browser-simulated environment

  • vitest run --environment edge-runtime

    Run tests in an edge runtime environment

  • vitest run --globals

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

  • vitest run --isolate

    Run each test file in an isolated module environment

  • vitest run --no-isolate

    Disable module isolation, sharing module state across test files

  • vitest run --pool=threads

    Run tests using worker threads pool

  • vitest run --pool=forks

    Run tests using child process forks pool

  • vitest run --pool=vmThreads

    Run tests in a VM context within worker threads

  • vitest run --pool=vmForks

    Run tests in a VM context within child process forks

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

    Set the maximum number of worker threads for the threads pool

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

    Set the minimum number of worker threads for the threads pool

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

    Set the maximum number of child process forks

  • vitest run --singleThread

    Run all tests in a single worker thread sequentially

  • vitest run --singleFork

    Run all tests in a single child process fork sequentially

  • vitest run --maxWorkers=4

    Limit the number of concurrent worker processes or threads

  • vitest run --minWorkers=1

    Set the minimum number of concurrent worker processes or threads

  • vitest run --sequence.shuffle

    Run test files and suites in a randomized order

  • vitest run --sequence.seed=42

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

  • vitest run --sequence.concurrent

    Run tests within each file concurrently

  • vitest run --no-threads

    Disable worker threads, running tests in the main process

  • vitest run --inspect

    Run tests with Node.js inspector enabled for debugging

  • vitest run --inspect-brk

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

  • vitest run --logHeapUsage

    Log heap memory usage after each test for memory profiling

  • vitest run --disable-console-intercept

    Disable interception and buffering of console output during tests

Filtering & Targeting

  • vitest run src/auth

    Run all tests within the src/auth directory

  • vitest run auth login

    Run tests whose file paths match both auth and login

  • vitest run --exclude src/legacy

    Exclude tests matching a path pattern from the run

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

    Run only test files matching a specific glob pattern

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

    Run test files matching multiple glob patterns

  • vitest run --testTimeout=10000

    Set the timeout in milliseconds for each individual test

  • vitest run --hookTimeout=10000

    Set the timeout in milliseconds for before and after hooks

  • vitest run --teardownTimeout=5000

    Set the timeout in milliseconds for teardown functions

  • vitest run --retry=3

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

  • vitest run --repeat=5

    Repeat every test 5 times to detect flakiness

UI Mode

  • vitest --ui

    Open the Vitest browser UI for interactive test inspection

  • vitest --ui --open=false

    Start the Vitest UI server without auto-opening the browser

  • vitest --ui --coverage

    Open the Vitest UI with code coverage enabled

  • vitest --ui --port=51205

    Start the Vitest UI server on a specific port

Browser Mode

  • vitest run --browser

    Run tests in a real browser environment using the default provider

  • vitest run --browser=chromium

    Run tests in a Chromium browser instance

  • vitest run --browser=firefox

    Run tests in a Firefox browser instance

  • vitest run --browser=webkit

    Run tests in a WebKit browser instance

  • vitest run --browser --browser.headless

    Run browser tests in headless mode without opening a visible window

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

    Run browser tests using Playwright as the browser provider

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

    Run browser tests using WebdriverIO as the browser provider

Benchmark

  • vitest bench

    Run all benchmark files in watch mode

  • vitest bench --run

    Run all benchmark files once without watch mode

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

    Run a specific benchmark file once

  • vitest bench --run --reporter=verbose

    Run benchmarks once with verbose output showing all results

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

    Run benchmarks once and write results to a JSON file

Type Checking

  • vitest typecheck

    Run type checking on test files using TypeScript without executing tests

  • vitest typecheck --run

    Run type checking on test files once without watch mode

  • vitest typecheck src/auth

    Run type checking only on test files matching a path pattern

  • vitest run --typecheck

    Run tests and type checking simultaneously

  • vitest run --typecheck.only

    Run only type checking, skipping actual test execution

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

    Run type checking using tsc as the type checker

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

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

Miscellaneous

  • vitest --version

    Display the currently installed version of Vitest

  • vitest --help

    Display help information and all available CLI options

  • vitest list

    List all test files that would be collected without running them

  • vitest list src/auth

    List test files matching a path pattern without running them

  • vitest list --json

    List collected test files and output as JSON

  • vitest run --update

    Update all outdated snapshot files to match current output

  • vitest run --update src/components

    Update snapshots only for test files matching a path pattern

  • vitest run --watch --update

    Run in watch mode updating snapshots automatically on change

  • vitest run --clearCache

    Clear the Vitest transform cache and exit

  • vitest run --cache=false

    Disable transform caching for this run

  • vitest run --cacheDir=.vitest-cache

    Use a custom directory for the transform cache

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

    Use a custom diff configuration file for test failure output

  • vitest run --expand-snapshot-diff

    Show the full diff in snapshot failure output without truncation

  • vitest run --printConsoleTrace

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

  • vitest run --segfaultRetry=3

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