Skip to content

Command Line Interface

Commands

vitest

Start Vitest in the current directory. Will enter the watch mode in development environment and run mode in CI automatically.

You can pass an additional argument as the filter of the test files to run. For example:

bash
vitest foobar

Will run only the test file that contains foobar in their paths. This filter only checks inclusion and doesn't support regexp or glob patterns (unless your terminal processes it before Vitest receives the filter).

vitest run

Perform a single run without watch mode.

vitest watch

Run all test suites but watch for changes and rerun tests when they change. Same as calling vitest without an argument. Will fallback to vitest run in CI.

vitest dev

Alias to vitest watch.

Run only tests that cover a list of source files. Works with static imports (e.g., import('./index.js') or import index from './index.js), but not the dynamic ones (e.g., import(filepath)). All files should be relative to root folder.

Useful to run with lint-staged or with your CI setup.

bash
vitest related /src/index.ts /src/hello-world.js

TIP

Don't forget that Vitest runs with enabled watch mode by default. If you are using tools like lint-staged, you should also pass --run option, so that command can exit normally.

js
// .lintstagedrc.js
export default {
  '*.{js,ts}': 'vitest related --run',
}

vitest bench

Run only benchmark tests, which compare performance results.

Options

Options
-r, --root <path>Root path
-c, --config <path>Path to config file
-u, --updateUpdate snapshot
-w, --watchEnable watch mode
-t, --testNamePattern <pattern>Run tests with full names matching the specified regexp pattern
--dir <path>Base directory to scan for the test files
--uiEnable UI
--openOpen UI automatically (default: !process.env.CI)
--api.port [port]Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. If true will be set to 51204
--api.host [host]Specify which IP addresses the server should listen on. Set this to 0.0.0.0 or true to listen on all addresses, including LAN and public addresses
--api.strictPortSet to true to exit if port is already in use, instead of automatically trying the next available port
--silentSilent console output from tests
--hideSkippedTestsHide logs for skipped tests
--reporter <name>Specify reporters
--outputFile <filename/-s>Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters (example: --outputFile.tap=./tap.txt)
--coverage.allWhether to include all files, including the untested ones into report
--coverage.provider <name>Select the tool for coverage collection, available values are: "v8", "istanbul" and "custom"
--coverage.enabledEnables coverage collection. Can be overridden using the --coverage CLI option (default: false)
--coverage.include <pattern>Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: **)
--coverage.exclude <pattern>Files to be excluded in coverage. May be specified more than once when using multiple extensions (default: Visit coverage.exclude)
--coverage.extension <extension>Extension to be included in coverage. May be specified more than once when using multiple extensions (default: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"])
--coverage.cleanClean coverage results before running tests (default: true)
--coverage.cleanOnRerunClean coverage report on watch rerun (default: true)
--coverage.reportsDirectory <path>Directory to write coverage report to (default: ./coverage)
--coverage.reporter <name>Coverage reporters to use. Visit coverage.reporter for more information (default: ["text", "html", "clover", "json"])
--coverage.reportOnFailureGenerate coverage report even when tests fail (default: false)
--coverage.allowExternalCollect coverage of files outside the project root (default: false)
--coverage.skipFullDo not show files with 100% statement, branch, and function coverage (default: false)
--coverage.thresholds.100Shortcut to set all coverage thresholds to 100 (default: false)
--coverage.thresholds.perFileCheck thresholds per file. See --coverage.thresholds.lines, --coverage.thresholds.functions, --coverage.thresholds.branches and --coverage.thresholds.statements for the actual thresholds (default: false)
--coverage.thresholds.autoUpdateUpdate threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: false)
--coverage.thresholds.lines <number>Threshold for lines. Visit istanbuljs for more information. This option is not available for custom providers
--coverage.thresholds.functions <number>Threshold for functions. Visit istanbuljs for more information. This option is not available for custom providers
--coverage.thresholds.branches <number>Threshold for branches. Visit istanbuljs for more information. This option is not available for custom providers
--coverage.thresholds.statements <number>Threshold for statements. Visit istanbuljs for more information. This option is not available for custom providers
--coverage.ignoreClassMethods <name>Array of class method names to ignore for coverage. Visit istanbuljs for more information. This option is only available for the istanbul providers (default: [])
--coverage.processingConcurrency <number>Concurrency limit used when processing the coverage results. (default min between 20 and the number of CPUs)
--coverage.customProviderModule <path>Specifies the module name or path for the custom coverage provider module. Visit Custom Coverage Provider for more information. This option is only available for custom providers
--coverage.watermarks.statements <watermarks>High and low watermarks for statements in the format of <high>,<low>
--coverage.watermarks.lines <watermarks>High and low watermarks for lines in the format of <high>,<low>
--coverage.watermarks.branches <watermarks>High and low watermarks for branches in the format of <high>,<low>
--coverage.watermarks.functions <watermarks>High and low watermarks for functions in the format of <high>,<low>
--mode <name>Override Vite mode (default: test or benchmark)
--workspace <path>Path to a workspace configuration file
--isolateRun every test file in isolation. To disable isolation, use --no-isolate (default: true)
--globalsInject apis globally
--domMock browser API with happy-dom
--browser.enabledRun tests in the browser. Equivalent to --browser.enabled (default: false)
--browser.name <name>Run all tests in a specific browser. Some browsers are only available for specific providers (see --browser.provider). Visit browser.name for more information
--browser.headlessRun the browser in headless mode (i.e. without opening the GUI (Graphical User Interface)). If you are running Vitest in CI, it will be enabled by default (default: process.env.CI)
--browser.api.port [port]Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. If true will be set to 63315
--browser.api.host [host]Specify which IP addresses the server should listen on. Set this to 0.0.0.0 or true to listen on all addresses, including LAN and public addresses
--browser.api.strictPortSet to true to exit if port is already in use, instead of automatically trying the next available port
--browser.provider <name>Provider used to run browser tests. Some browsers are only available for specific providers. Can be "webdriverio", "playwright", or the path to a custom provider. Visit browser.provider for more information (default: "webdriverio")
--browser.providerOptions <options>Options that are passed down to a browser provider. Visit browser.providerOptions for more information
--browser.slowHijackESMLet Vitest use its own module resolution on the browser to enable APIs such as vi.mock and vi.spyOn. Visit browser.slowHijackESM for more information (default: false)
--browser.isolateRun every browser test file in isolation. To disable isolation, use --browser.isolate=false (default: true)
--browser.fileParallelismShould all test files run in parallel. Use --browser.file-parallelism=false to disable (default: same as --file-parallelism)
--pool <pool>Specify pool, if not running in the browser (default: threads)
--poolOptions.threads.isolateIsolate tests in threads pool (default: true)
--poolOptions.threads.singleThreadRun tests inside a single thread (default: false)
--poolOptions.threads.maxThreads <workers>Maximum number of threads to run tests in
--poolOptions.threads.minThreads <workers>Minimum number of threads to run tests in
--poolOptions.threads.useAtomicsUse Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: false)
--poolOptions.vmThreads.isolateIsolate tests in threads pool (default: true)
--poolOptions.vmThreads.singleThreadRun tests inside a single thread (default: false)
--poolOptions.vmThreads.maxThreads <workers>Maximum number of threads to run tests in
--poolOptions.vmThreads.minThreads <workers>Minimum number of threads to run tests in
--poolOptions.vmThreads.useAtomicsUse Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: false)
--poolOptions.vmThreads.memoryLimit <limit>Memory limit for VM threads pool. If you see memory leaks, try to tinker this value.
--poolOptions.forks.isolateIsolate tests in forks pool (default: true)
--poolOptions.forks.singleForkRun tests inside a single child_process (default: false)
--poolOptions.forks.maxForks <workers>Maximum number of processes to run tests in
--poolOptions.forks.minForks <workers>Minimum number of processes to run tests in
--poolOptions.vmForks.isolateIsolate tests in forks pool (default: true)
--poolOptions.vmForks.singleForkRun tests inside a single child_process (default: false)
--poolOptions.vmForks.maxForks <workers>Maximum number of processes to run tests in
--poolOptions.vmForks.minForks <workers>Minimum number of processes to run tests in
--poolOptions.vmForks.memoryLimit <limit>Memory limit for VM forks pool. If you see memory leaks, try to tinker this value.
--fileParallelismShould all test files run in parallel. Use --no-file-parallelism to disable (default: true)
--maxWorkers <workers>Maximum number of workers to run tests in
--minWorkers <workers>Minimum number of workers to run tests in
--environment <name>Specify runner environment, if not running in the browser (default: node)
--passWithNoTestsPass when no tests are found
--logHeapUsageShow the size of heap for each test when running in node
--allowOnlyAllow tests and suites that are marked as only (default: !process.env.CI)
--dangerouslyIgnoreUnhandledErrorsIgnore any unhandled errors that occur
--shard <shards>Test suite shard to execute in a format of <index>/<count>
--changed [since]Run tests that are affected by the changed files (default: false)
--sequence.shuffle.filesRun files in a random order. Long running tests will not start earlier if you enable this option. (default: false)
--sequence.shuffle.testsRun tests in a random oder (default: false)
--sequence.concurrentMake tests run in parallel (default: false)
--sequence.seed <seed>Set the randomization seed. This option will have no effect if --sequence.shuffle is falsy. Visit "Random Seed" page for more information
--sequence.hooks <order>Changes the order in which hooks are executed. Accepted values are: "stack", "list" and "parallel". Visit sequence.hooks for more information (default: "parallel")
--sequence.setupFiles <order>Changes the order in which setup files are executed. Accepted values are: "list" and "parallel". If set to "list", will run setup files in the order they are defined. If set to "parallel", will run setup files in parallel (default: "parallel")
--inspect [[host:]port]Enable Node.js inspector (default: 127.0.0.1:9229)
--inspectBrk [[host:]port]Enable Node.js inspector and break before the test starts
--testTimeout <timeout>Default timeout of a test in milliseconds (default: 5000)
--hookTimeout <timeout>Default hook timeout in milliseconds (default: 10000)
--bail <number>Stop test execution when given number of tests have failed (default: 0)
--retry <times>Retry the test specific number of times if it fails (default: 0)
--diff <path>Path to a diff config that will be used to generate diff interface
--exclude <glob>Additional file globs to be excluded from test
--expandSnapshotDiffShow full diff when snapshot fails
--disableConsoleInterceptDisable automatic interception of console logging (default: false)
--typecheck.enabledEnable typechecking alongside tests (default: false)
--typecheck.onlyRun only typecheck tests. This automatically enables typecheck (default: false)
--typecheck.checker <name>Specify the typechecker to use. Available values are: "tcs" and "vue-tsc" and a path to an executable (default: "tsc")
--typecheck.allowJsAllow JavaScript files to be typechecked. By default takes the value from tsconfig.json
--typecheck.ignoreSourceErrorsIgnore type errors from source files
--typecheck.tsconfig <path>Path to a custom tsconfig file
--project <name>The name of the project to run if you are using Vitest workspace feature. This can be repeated for multiple projects: --project=1 --project=2. You can also filter projects using wildcards like --project=packages*
--slowTestThreshold <threshold>Threshold in milliseconds for a test to be considered slow (default: 300)
--teardownTimeout <timeout>Default timeout of a teardown function in milliseconds (default: 10000)
--maxConcurrency <number>Maximum number of concurrent tests in a suite (default: 5)
--runDisable watch mode
--segfaultRetry <times>Retry the test suite if it crashes due to a segfault (default: true)
--no-colorRemoves colors from the console output
--clearScreenClear terminal screen when re-running tests during watch mode (default: true)

TIP

Vitest supports both camel case and kebab case for CLI arguments. For example, --passWithNoTests and --pass-with-no-tests will both work (--no-color and --inspect-brk are the exceptions).

Vitest also supports different ways of specifying the value: --reporter dot and --reporter=dot are both valid.

If option supports an array of values, you need to pass the option multiple times:

vitest --reporter=dot --reporter=default

Boolean options can be negated with no- prefix. Specifying the value as false also works:

vitest --no-api
vitest --api=false

changed

  • Type: boolean | string

  • Default: false

    Run tests only against changed files. If no value is provided, it will run tests against uncommitted changes (including staged and unstaged).

    To run tests against changes made in the last commit, you can use --changed HEAD~1. You can also pass commit hash (e.g. --changed 09a9920) or branch name (e.g. --changed origin/develop).

    When used with code coverage the report will contain only the files that were related to the changes.

    If paired with the forceRerunTriggers config option it will run the whole test suite if at least one of the files listed in the forceRerunTriggers list changes. By default, changes to the Vitest config file and package.json will always rerun the whole suite.

shard

  • Type: string

  • Default: disabled

    Test suite shard to execute in a format of <index>/<count>, where

    • count is a positive integer, count of divided parts
    • index is a positive integer, index of divided part

    This command will divide all tests into count equal parts, and will run only those that happen to be in an index part. For example, to split your tests suite into three parts, use this:

    sh
    vitest run --shard=1/3
    vitest run --shard=2/3
    vitest run --shard=3/3

WARNING

You cannot use this option with --watch enabled (enabled in dev by default).

Released under the MIT License.