Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
64ff7a5
docs(anchor): guide/index
NoiseFan Oct 28, 2025
93436bb
typo(anchor): guide/index
NoiseFan Oct 28, 2025
58b5285
docs(anchor): guide/why
NoiseFan Oct 29, 2025
4148f60
docs(anchor): guide/features
NoiseFan Oct 29, 2025
69690e4
docs(anchor): guide/cli
NoiseFan Oct 29, 2025
dd1b7ef
docs(anchor): guide/filtering
NoiseFan Oct 29, 2025
5d7285b
docs(anchor): guide/projects
NoiseFan Oct 29, 2025
86dd12c
docs(anchor): guide/projects typo
NoiseFan Oct 29, 2025
0aa8265
docs(anchor): guide/reporters
NoiseFan Oct 29, 2025
82a5ef9
docs(anchor): guide/coverage
NoiseFan Oct 29, 2025
6c929a2
docs(anchor): guide/snapshot
NoiseFan Oct 29, 2025
a98040a
docs(guide): Add some translate comments in index.md to Chinese
WuMingDao Oct 31, 2025
4e52e2e
docs(/guide/features) Add some translate comments to Chinese
WuMingDao Oct 31, 2025
e02637b
docs(/api/index): Add translate comments to Chinese
WuMingDao Oct 31, 2025
1b707a8
docs(sideBar): Translate sidebar menu and page config
NoiseFan Oct 28, 2025
da0fedf
docs(config): modify /guide/why
NoiseFan Nov 1, 2025
6659ee8
docs(anchor): guide/mocking/dates
NoiseFan Nov 1, 2025
08c2600
docs(anchor): guide/mocking
NoiseFan Nov 1, 2025
0171f6b
docs(anchor): guide/parallelism
NoiseFan Nov 1, 2025
afa3759
docs(anchor): guide/in-source
NoiseFan Nov 1, 2025
17af9b3
docs(anchor): /guide/test-context
NoiseFan Nov 1, 2025
48081d3
docs(anchor): /guide/environment
NoiseFan Nov 1, 2025
7d7ba3a
docs(anchor): /guide/extending-matchers
NoiseFan Nov 1, 2025
614ab19
docs(anchor): /guide/ide
NoiseFan Nov 1, 2025
c3cf7b1
docs(anchor): /guide/
NoiseFan Nov 1, 2025
25828ad
docs(/config/index): Add tranalse to chinese
WuMingDao Oct 31, 2025
f68ca0e
reporter translate to 报告器
WuMingDao Nov 1, 2025
9a00bdf
docs
WuMingDao Nov 1, 2025
3983015
docs(/advanced/api/index): Add some comments translate
WuMingDao Nov 1, 2025
9b28baa
Update advanced/api/index.md
thinkasany Nov 1, 2025
8a4972e
Update advanced/api/index.md
thinkasany Nov 1, 2025
0f4a2dd
docs(/advanced/runner): Add some comments translate
WuMingDao Nov 1, 2025
52a7557
docs(/advanced/api/test-project): Add translate
WuMingDao Nov 1, 2025
2aa3f31
docs(/advanced/api/plugin): Add comments translate
WuMingDao Nov 1, 2025
67b001f
docs(/advanced/api/test-case): Add comments translate
WuMingDao Nov 1, 2025
1d4de4b
docs(/advanced/api/test-suite): Add comments translate
WuMingDao Nov 1, 2025
76603ce
docs(/advanced/api/test-specification): Add translate
WuMingDao Nov 1, 2025
894070e
Update advanced/api/test-specification.md
thinkasany Nov 1, 2025
67ad520
fix: Optimize the multi-level title problem of the test context
984507092 Oct 30, 2025
dfae3e1
fix:Revise to be consistent with the English document
984507092 Nov 1, 2025
fcbbf15
Update guide/test-context.md
thinkasany Nov 1, 2025
45602e3
fix User defined id attribute default-fixture is not uniqu
thinkasany Nov 1, 2025
6a22bb8
rm vitepress-plugin-llms
thinkasany Nov 1, 2025
de319ba
lint fix
thinkasany Nov 1, 2025
cf3a853
Inspect the documentation using lint rules from the upstream repository.
thinkasany Nov 1, 2025
547e5b0
update lint
thinkasany Nov 1, 2025
04e2431
fix: Optimize the multi-level title problem of the test context
984507092 Oct 30, 2025
d7f1feb
fix:Revise to be consistent with the English document
984507092 Nov 1, 2025
d0dca39
Merge branch 'dev' into docs/anchor
NoiseFan Nov 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ title: 命令行界面 | 指南
outline: deep
---

# 命令行界面
# 命令行界面 {#command-line-interface}

## 命令
## 命令 {#commands}

### `vitest`
### `vitest` {#vitest}

在当前目录启动 Vitest。在开发环境中会自动进入监听模式,而在 CI 环境(或非交互式终端)中会自动运行测试模式。

Expand Down Expand Up @@ -122,7 +122,7 @@ tests/test1.test.ts
tests/test2.test.ts
```

## 选项
## 选项 {#options}

::: tip
Vitest 支持 CLI 参数的 both camel case 和 kebab case 。例如,`--passWithNoTests` 和 `--pass-with-no-tests` 都有效(`--no-color` 和 `--inspect-brk` 是例外)。
Expand Down
2 changes: 1 addition & 1 deletion guide/common-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: 常见错误 | 指南
---

# 常见错误
# 常见错误 {#common-errors}

## Cannot find module './relative-path'

Expand Down
24 changes: 12 additions & 12 deletions guide/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
title: 测试覆盖率 | 指南
---

# 测试覆盖率
# 测试覆盖率 {#coverage}

Vitest 通过 [`v8`](https://v8.dev/blog/javascript-code-coverage) 支持原生代码覆盖率,通过 [`istanbul`](https://istanbul.js.org/) 支持检测代码覆盖率。

## 测试覆盖率提供者
## 测试覆盖率提供者 {#coverage-providers}

`v8` 和 `istanbul` 的支持都是可选的。 默认情况下,启用 `v8`。

Expand Down Expand Up @@ -40,7 +40,7 @@ npm i -D @vitest/coverage-istanbul

:::

## V8 Provider
## V8 Provider {#v8-provider}

::: info
以下对 V8 覆盖率的说明仅适用于 Vitest,并不适用于其他测试工具。
Expand Down Expand Up @@ -77,7 +77,7 @@ Vitest 默认采用 'v8' 作为覆盖率提供器。
<Box>Coverage report</Box>
</div>

## Istanbul 覆盖率提供方案
## Istanbul 覆盖率提供方案 {#istanbul-provider}

[Istanbul 代码覆盖率工具](https://istanbul.js.org/) 自 2012 年发布以来,已在各种场景中得到了充分验证。
这种覆盖率提供器能在任何 JavaScript 运行环境中使用,因为它是通过在用户源码中插入额外的代码来跟踪执行情况。
Expand Down Expand Up @@ -133,7 +133,7 @@ globalThis.__VITEST_COVERAGE__[filename] = coverage // [!code ++]
<Box>Coverage report</Box>
</div>

## 覆盖率配置指南
## 覆盖率配置指南 {#coverage-setup}

::: tip
你可以在 [覆盖率配置参考](/config/#coverage) 中查看所有可用的覆盖率选项。
Expand Down Expand Up @@ -163,7 +163,7 @@ export default defineConfig({
```
:::

## 在覆盖率报告中设置需要统计或忽略的文件
## 在覆盖率报告中设置需要统计或忽略的文件 {#including-and-excluding-files-from-coverage-report}

你可以通过设置 [`coverage.include`](/config/#coverage-include) 和 [`coverage.exclude`](/config/#coverage-exclude) 来决定覆盖率报告中展示哪些文件。

Expand Down Expand Up @@ -236,7 +236,7 @@ export default defineConfig({
```
:::

## 自定义覆盖率的报告器
## 自定义覆盖率的报告器 {#custom-coverage-reporter}

我们可以通过在 `test.coverage.reporter` 中传递软件包名称或绝对路径来使用自定义覆盖报告器:

Expand Down Expand Up @@ -283,7 +283,7 @@ module.exports = class CustomReporter extends ReportBase {
}
```

## 自定义覆盖率的提供者
## 自定义覆盖率的提供者 {#custom-coverage-provider}

也可以通过将 `'custom'` 传递给 `test.coverage.provider` 来配置你的自定义覆盖率提供者:

Expand Down Expand Up @@ -334,7 +334,7 @@ export default CustomCoverageProviderModule

请参阅类型定义查看有关详细信息。

## 代码忽略
## 代码忽略 {#ignoring-code}

两个覆盖率提供商都有自己的方法来忽略覆盖率报告中的代码:

Expand All @@ -357,7 +357,7 @@ if (condition) {
if (condition) {
```

### Examples
### 示例

::: code-group

Expand Down Expand Up @@ -462,11 +462,11 @@ export function ignored() { // [!code error]
```
:::

## Coverage Performance
## Coverage Performance {#coverage-performance}

If code coverage generation is slow on your project, see [Profiling Test Performance | Code coverage](/guide/profiling-test-performance.html#code-coverage).

## Vitest UI
## Vitest UI {#vitest-ui}

我们可以在 [Vitest UI](/guide/ui) 中查看你的覆盖率报告。

Expand Down
8 changes: 4 additions & 4 deletions guide/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
title: 调试 | 指南
---

# 调试
# 调试 {#debugging}

## Terminal
## 终端 {#terminal}

在非集成开发环境下,为了调试一个测试文件,你可以使用 [`ndb`](https://github.com/GoogleChromeLabs/ndb)。仅仅在你的代码的任何位置添加一个 `debugger` 语句,然后运行 `ndb`:

Expand Down Expand Up @@ -56,7 +56,7 @@ ndb npm run test

然后在调试选项卡中确保选择 'Debug Current Test File',然后你可以打开要调试的测试文件并按 F5 开始调试。

### 浏览器模式
### 浏览器模式 {#browser-mode}

要调试 [Vitest 浏览器模式](/guide/browser/index.md),请在 CLI 中传递 `--inspect` 或 `--inspect-brk`,或在 Vitest 配置中定义它:

Expand All @@ -65,8 +65,8 @@ ndb npm run test
vitest --inspect-brk --browser --no-file-parallelism
```
```ts [vitest.config.js]
import { defineConfig } from 'vitest/config'
import { playwright } from '@vitest/browser-playwright'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
Expand Down
2 changes: 1 addition & 1 deletion guide/extending-matchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: 扩展断言 | 指南
---

# 扩展断言(Matchers)
# 扩展断言 {#extending-matchers}

由于 Vitest 兼容 Chai 和 Jest,所以可以根据个人喜好使用 `chai.use` API 或者 `expect.extend`。

Expand Down
34 changes: 19 additions & 15 deletions guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ title: 主要功能 | 指南
outline: deep
---

# 主要功能
# 主要功能 {#features}

<FeaturesList class="!gap-1 text-lg" />

## 一套配置可以运用在多种环境
## 一套配置可以运用在多种环境 {#shared-config-between-test-dev-and-build}

<div h-2 />
<CourseLink href="https://vueschool.io/lessons/your-first-test?friend=vueuse">通过视频了解如何编写你的第一个测试</CourseLink>
Expand All @@ -16,7 +16,7 @@ outline: deep

了解更多信息 [配置 Vitest](/guide/#配置-vitest)

## 监听模式(watch mode)
## 监听模式(watch mode) {#watch-mode}

```bash
$ vitest
Expand All @@ -28,11 +28,11 @@ $ vitest

使用 `--standalone` 标志启动 Vitest,使其在后台运行。它不会运行任何测试,直到测试发生变化。如果源代码发生变化,Vitest 不会运行测试,直到运行了导入源代码的测试为止

## 开箱即用的常见 Web 支持
## 开箱即用的常见 Web 支持 {#common-web-idioms-out-of-the-box}

开箱即用的 ES Module / TypeScript / JSX support / PostCSS

## 多线程
## 多线程 {#threads}

Vitest 默认会通过 [Tinypool](https://github.com/tinylibs/tinypool)(它是 [Piscina](https://github.com/piscinajs/piscina) 的轻量版分支),利用 [`node:child_process`](https://nodejs.org/api/child_process.html) 在 [多个进程](/guide/parallelism) 中并行执行测试文件,
从而提升测试执行效率。如果你想让测试套件跑得更快,可以尝试开启 `--pool=threads` 选项,让 Vitest 使用 [`node:worker_threads`](https://nodejs.org/api/worker_threads.html) 执行测试——不过要注意,有些依赖可能在该模式下无法正常工作。
Expand All @@ -41,13 +41,13 @@ Vitest 默认会通过 [Tinypool](https://github.com/tinylibs/tinypool)(它是

Vitest 还隔离了每个测试文件的运行环境,因此一个文件中的运行环境改变不会影响其他文件。可以通过将 `--no-isolate` 传递给 CLI 来禁用隔离(以正确性换取运行性能)。

## 测试可过滤
## 测试可过滤 {#test-filtering}

Vitest 提供了许多缩小测试范围的方法,以便在开发过程中加快速度并集中精力。

了解更多信息 [测试筛选](/guide/filtering)

## 同时运行多个测试
## 同时运行多个测试 {#running-tests-concurrently}

在连续的测试中使用 `.concurrent` 来并行运行它们。

Expand Down Expand Up @@ -95,12 +95,13 @@ describe.concurrent('suite', () => {
在异步并发测试中使用快照时,由于 JavaScript 的限制,你需要使用 [测试环境](/guide/test-context) 中的 `expect` 来确保检测到正确的测试。
:::

## 快照
## 快照 {#snapshot}

兼容 [Jest 快照测试](https://jestjs.io/zh-Hans/docs/snapshot-testing) 功能。

```ts
import { expect, it } from 'vitest'

it('renders correctly', () => {
const result = render()
expect(result).toMatchSnapshot()
Expand All @@ -109,18 +110,19 @@ it('renders correctly', () => {

了解更多信息 [快照](/guide/snapshot)

## Chai 和 Jest 的 `expect` 语法兼容
## Chai 和 Jest 的 `expect` 语法兼容 {#chai-and-jest-expect-compatibility}

内置 [Chai](https://www.chaijs.com/) 进行断言和与 [Jest expect](https://jestjs.io/docs/expect) 兼容的 APIs

注意,如果你正在使用添加匹配器的第三方库,将 [`test.globals`](/config/#globals) 设置为 `true` 将提供更好的兼容性。

## 对象模拟(Mocking)
## 对象模拟(Mocking) {#mocking}

内置 [Tinyspy](https://github.com/tinylibs/tinyspy) 用于在 `vi` 对象上使用 `jest` 兼容的 API 进行对象模拟。

```ts
import { expect, vi } from 'vitest'

const fn = vi.fn()
fn('hello', 1)
expect(vi.isMockFunction(fn)).toBe(true)
Expand All @@ -147,6 +149,7 @@ $ npm i -D jsdom

```ts [vitest.config.ts]
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
environment: 'happy-dom', // 或 'jsdom' 和 'node'
Expand All @@ -156,7 +159,7 @@ export default defineConfig({

了解更多信息 [模拟对象](/guide/mocking)

## 测试覆盖率
## 测试覆盖率 {#coverage}

Vitest 通过 [`v8`](https://v8.dev/blog/javascript-code-coverage) 支持原生代码覆盖率,通过 [`istanbul`](https://istanbul.js.org/) 支持检测代码覆盖率。

Expand All @@ -174,6 +177,7 @@ Vitest 通过 [`v8`](https://v8.dev/blog/javascript-code-coverage) 支持原生
```ts
// vite.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
coverage: {
Expand All @@ -185,7 +189,7 @@ export default defineConfig({

了解更多信息 [测试覆盖率](/guide/coverage)

## 源码内联测试
## 源码内联测试 {#in-source-testing}

Vitest 还提供了一种方式,可以运行与你的代码实现放在一起的测试,类似 [Rust's 模块测试](https://doc.rust-lang.org/book/ch11-03-test-organization.html#the-tests-module-and-cfgtest).

Expand Down Expand Up @@ -253,7 +257,7 @@ test('my types work properly', () => {
})
```

## 分片
## 分片 {#sharding}

使用 [`--shard`](/guide/cli#shard) 和 [`--reporter=blob`](/guide/reporters#blob-reporter)标志在不同的计算机上运行测试。可以使用 `--merge-reports` 命令在 CI 管道的末尾合并所有测试结果:

Expand All @@ -265,7 +269,7 @@ vitest --merge-reports --reporter=junit --coverage

了解更多信息 [`性能优化 | 分片`](/guide/improving-performance#sharding)

## 环境变量
## 环境变量 {#environment-variables}

Vitest 只从 `.env` 文件中自动加载以 `VITE_` 为前缀的环境变量,以保持与前端相关测试的兼容性,并遵守 [Vite 的既定惯例](https://vitejs.dev/guide/env-and-mode.html#env-files)。要从 `.env` 文件加载所有环境变量,可以使用从 `vite` 导入的 `loadEnv` 方法:

Expand All @@ -281,7 +285,7 @@ export default defineConfig(({ mode }) => ({
}))
```

## 未处理的错误
## 未处理的错误 {#unhandled-errors}

默认情况下,Vitest 会捕获并报告所有的 [未处理的拒绝(Promise)](https://developer.mozilla.org/en-US/docs/Web/API/Window/unhandledrejection_event)、[未捕获的异常](https://nodejs.org/api/process.html#event-uncaughtexception)(在 Node.js 中)以及 [错误事件](https://developer.mozilla.org/en-US/docs/Web/API/Window/error_event)(在 [浏览器](/guide/browser/) 中)。

Expand Down
12 changes: 6 additions & 6 deletions guide/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
title: 测试筛选 | 指南
---

# 测试筛选
# 测试筛选 {#test-filtering}

用于测试套件(suite)和测试的筛选(filtering)、超时(timeouts)、并发(concurrent)。

## CLI
## CLI {#cli}

你可以使用 CLI 按名称筛选测试文件:

Expand Down Expand Up @@ -49,7 +49,7 @@ $ vitest basic/foo.test.ts:10-25 # ❌
```
:::

## 指定超时阈值
## 指定超时阈值 {#specifying-a-timeout}

你可以选择将超时阈值(以毫秒为单位)作为第三个参数传递给测试。默认值为 [5 秒](/config/#testtimeout)。

Expand All @@ -71,7 +71,7 @@ beforeAll(async () => {
}, 1000)
```

## 跳过测试套件和测试
## 跳过测试套件和测试 {#skipping-suites-and-tests}

使用 `.skip` 以避免运行某些测试套件或测试

Expand All @@ -93,7 +93,7 @@ describe('suite', () => {
})
```

## 选择要运行的测试套件和测试
## 选择要运行的测试套件和测试 {#selecting-suites-and-tests-to-run}

使用 `.only` 仅运行某些测试套件或测试

Expand All @@ -120,7 +120,7 @@ describe('another suite', () => {
})
```

## 未实现的测试套件和测试
## 未实现的测试套件和测试 {#unimplemented-suites-and-tests}

使用 `.todo` 留存将要实施的测试套件和测试的待办事项

Expand Down
2 changes: 1 addition & 1 deletion guide/ide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: IDE 插件 | 指南
---

# IDE 插件
# IDE 插件 {#ide-integrations}

## VS Code <Badge>Official</Badge> {#vs-code}

Expand Down
Loading