← 返回命令列表

Linux command

vitest 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run tests

vitest

Run tests once

vitest run

Run tests with coverage

vitest --coverage

Run specific test files

vitest [path/to/test.spec.ts]

Run tests matching a pattern

vitest -t "[pattern]"

Run tests in a specific directory

vitest [path/to/tests]

Run in UI mode

vitest --ui

Update snapshots

vitest -u

说明

Vitest is a next-generation JavaScript/TypeScript testing framework powered by Vite. It provides fast test execution through native ES module support, intelligent watch mode similar to HMR, and a Jest-compatible API for easy migration. The framework shares Vite's configuration, transformers, resolvers, and plugins, allowing tests to use the same setup as the application. It supports DOM mocking via JSDOM or happy-dom, component testing for Vue, React, Svelte, and other frameworks, and browser-based testing. Vitest automatically enters watch mode in development environments and run mode in CI. Configuration can be placed in vitest.config.ts or within the existing vite.config.ts under the test property. Built-in features include snapshot testing, mocking with Tinyspy, and code coverage via v8 or istanbul.

参数

run
Run tests once without watch mode.
watch
Run tests in watch mode, re-running on file changes.
bench
Run benchmark tests.
--coverage
Enable code coverage reporting (v8 or istanbul).
-t, --testNamePattern _pattern_
Run only tests with names matching the pattern.
--ui
Open the Vitest UI in a browser for interactive test viewing.
-u, --update
Update snapshot files.
--reporter _name_
Specify reporter: default, verbose, dot, json, junit.
--config _file_
Path to config file.
--root _dir_
Root directory for the project.
--environment _env_
Test environment: node, jsdom, happy-dom.
--threads
Enable multi-threading (default: true).
--browser
Run tests in browser mode.
--passWithNoTests
Exit successfully even if no tests are found.
--bail _n_
Stop after n test failures.

FAQ

What is the vitest command used for?

Vitest is a next-generation JavaScript/TypeScript testing framework powered by Vite. It provides fast test execution through native ES module support, intelligent watch mode similar to HMR, and a Jest-compatible API for easy migration. The framework shares Vite's configuration, transformers, resolvers, and plugins, allowing tests to use the same setup as the application. It supports DOM mocking via JSDOM or happy-dom, component testing for Vue, React, Svelte, and other frameworks, and browser-based testing. Vitest automatically enters watch mode in development environments and run mode in CI. Configuration can be placed in vitest.config.ts or within the existing vite.config.ts under the test property. Built-in features include snapshot testing, mocking with Tinyspy, and code coverage via v8 or istanbul.

How do I run a basic vitest example?

Run `vitest` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does run do in vitest?

Run tests once without watch mode.