Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
12e6c10
docs(cn): batch replace text
NoiseFan Mar 19, 2026
c654cf8
docs(cn): config/exclude
NoiseFan Mar 19, 2026
265f281
docs(cn): update /config/include-source
NoiseFan Mar 19, 2026
80a51b6
docs(cn): update config/name.md
NoiseFan Mar 22, 2026
97491fc
docs(cn): update config/server.md
NoiseFan Mar 23, 2026
7485694
docs(cn): update config/dep
NoiseFan Mar 23, 2026
5b62bda
docs(cn): update config/alias
NoiseFan Mar 23, 2026
9079919
docs(cn): update config/globals.md
NoiseFan Mar 23, 2026
c0127ac
docs(cn): update config/environment.md
NoiseFan Mar 23, 2026
7c7ccac
docs(cn): update config/alias
NoiseFan Mar 26, 2026
1ccdf71
docs(cn): update config/environmentoptions.md
NoiseFan Mar 26, 2026
a27730f
docs(cn): update config/watchtriggerpatterns.md
NoiseFan Mar 26, 2026
6947e5a
docs(cn): update config/reporters.md
NoiseFan Mar 26, 2026
7cef5ab
docs(cn): update config/outputfile.md
NoiseFan Mar 26, 2026
483b1d0
docs(cn): update config/pool.md
NoiseFan Mar 26, 2026
70b4041
docs(cn): update config/vmmemorylimit.md
NoiseFan Mar 26, 2026
44d5a8b
docs(cn): update config/maxworkers.md
NoiseFan Mar 26, 2026
a08cf82
typo
NoiseFan Mar 26, 2026
aeecc32
Merge branch 'dev' into docs/config
NoiseFan Mar 27, 2026
61e808e
docs(cn): update config/silent.md
NoiseFan Mar 27, 2026
97279f3
docs(cn): update config/setupfiles.md
NoiseFan Mar 27, 2026
55dd0b2
docs(cn): update config/provide.md
NoiseFan Mar 27, 2026
ec05c21
docs(cn): update config/globalsetup.md
NoiseFan Mar 27, 2026
fa2a148
docs(cn): update config/forcereruntriggers.md
NoiseFan Mar 27, 2026
8193e92
docs(cn): update config/coverage.md
NoiseFan Mar 29, 2026
dcb338c
docs(cn): update config/testnamepattern.md
NoiseFan Mar 29, 2026
3fe63df
docs(cn): update config/ui.md
NoiseFan Mar 29, 2026
82be990
docs(cn): update config/open.md
NoiseFan Mar 29, 2026
598e752
docs(cn): update config/clearmocks.md
NoiseFan Mar 29, 2026
681bd6b
docs(cn): update config/mockreset.md
NoiseFan Mar 29, 2026
8aec7cc
docs(cn): update config/restoremocks.md
NoiseFan Mar 29, 2026
df53da4
docs(cn): update config/unstubenvs.md
NoiseFan Mar 29, 2026
8c29ecf
docs(cn): update config/snapshotformat.md
NoiseFan Mar 29, 2026
e0d6e75
docs(cn): update config/snapshotserializers.md
NoiseFan Mar 29, 2026
c117993
docs(cn): update config/resolvesnapshotpath.md
NoiseFan Mar 29, 2026
1a9274e
docs(cn): update config/allowonly.md
NoiseFan Mar 29, 2026
e34ff51
docs(cn): update config/logheapusage.md
NoiseFan Mar 29, 2026
8855fb8
docs(cn): update config/css.md
NoiseFan Mar 29, 2026
2c5cca2
docs(cn): update config/maxconcurrency.md
NoiseFan Mar 29, 2026
1b8468e
docs(cn): update config/cache.md
NoiseFan Mar 29, 2026
e32ce86
docs(cn): update config/sequence.md
NoiseFan Mar 29, 2026
7bce8e9
docs(cn): update config/tags.md
NoiseFan Mar 30, 2026
41a8208
docs(cn): update config/stricttags.md
NoiseFan Mar 30, 2026
aa873e9
docs(cn): update config/typecheck.md
NoiseFan Mar 30, 2026
868de08
docs(cn): update config/chaiconfig.md
NoiseFan Mar 30, 2026
a89b8e1
docs(cn): update config/bail.md
NoiseFan Mar 30, 2026
9aef45f
docs(cn): update config/retry.md
NoiseFan Mar 30, 2026
28fbd5f
docs(cn): update config/onconsolelog.md
NoiseFan Mar 30, 2026
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
4 changes: 2 additions & 2 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ export default ({ mode }: { mode: string }) => {
sidebar: {
'/config': [
{
text: 'Config Reference',
text: '配置索引',
collapsed: false,
items: [
{
text: '配置文件',
text: '配置 Vitest',
link: '/config/',
},
{
Expand Down
14 changes: 7 additions & 7 deletions config/alias.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: alias | Config
title: alias | 配置
outline: deep
---

# alias

- **Type:** `Record<string, string> | Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>`
- **类型:** `Record<string, string> | Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>`

Define custom aliases when running inside tests. They will be merged with aliases from `resolve.alias`.
在测试环境中定义自定义别名。这些别名将与 `resolve.alias` 中的配置合并使用。

::: warning
Vitest uses Vite SSR primitives to run tests which has [certain pitfalls](https://vitejs.dev/guide/ssr.html#ssr-externals).
Vitest 基于 Vite SSR 底层机制运行测试,可能存在 [潜在的缺陷](https://cn.vitejs.dev/guide/ssr.html#ssr-externals)

1. Aliases affect only modules imported directly with an `import` keyword by an [inlined](/config/server#server-deps-inline) module (all source code is inlined by default).
2. Vitest does not support aliasing `require` calls.
3. If you are aliasing an external dependency (e.g., `react` -> `preact`), you may want to alias the actual `node_modules` packages instead to make it work for externalized dependencies. Both [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) and [pnpm](https://pnpm.io/aliases/) support aliasing via the `npm:` prefix.
1. 别名仅影响由 [内联模块](/config/server#server-deps-inline) 通过 `import` 关键字直接导入的模块 (默认情况下所有源代码均被内联)。
2. Vitest 不支持对 `require` 调用进行别名配置。
3. 如果我们要为外部依赖项设置别名(例如,`react` -> `preact`),建议直接对 `node_modules` 中的实际包进行别名配置,以确保该方案在外部化依赖场景下同样生效。[Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) [pnpm](https://pnpm.io/aliases/) 均支持通过 `npm:` 前缀实现别名功能。
:::
20 changes: 9 additions & 11 deletions config/allowonly.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
---
title: allowOnly | Config
title: allowOnly | 配置
outline: deep
---

<!-- TODO: translation -->

# allowOnly

- **Type**: `boolean`
- **Default**: `!process.env.CI`
- **CLI:** `--allowOnly`, `--allowOnly=false`
- **类型:**: `boolean`
- **默认值:**: `!process.env.CI`
- **命令行终端:** `--allowOnly`, `--allowOnly=false`

By default, Vitest does not permit tests marked with the [`only`](/api/test#test-only) flag in Continuous Integration (CI) environments. Conversely, in local development environments, Vitest allows these tests to run.
默认情况下,Vitest 不允许在持续集成(CI)环境中运行带有 [`only`](/api/test#test-only) 标记的测试。相反,在本地开发环境中,Vitest 允许运行这些测试。

::: info
Vitest uses [`std-env`](https://npmx.dev/package/std-env) package to detect the environment.
Vitest 使用 [`std-env`](https://npmx.dev/package/std-env) 包来检测环境。
:::

You can customize this behavior by explicitly setting the `allowOnly` option to either `true` or `false`.
你可以通过显式设置 `allowOnly` 选项为 `true` `false` 来自定义此行为。

::: code-group
```js [vitest.config.js]
Expand All @@ -34,6 +32,6 @@ vitest --allowOnly
```
:::

When enabled, Vitest will not fail the test suite if tests marked with [`only`](/api/test#test-only) are detected, including in CI environments.
启用时,即使检测到带有 [`only`](/api/test#test-only) 标记的测试,Vitest 也不会导致测试套件失败,包括在 CI 环境中。

When disabled, Vitest will fail the test suite if tests marked with [`only`](/api/test#test-only) are detected, including in local development environments.
禁用时时,如果检测到带有 [`only`](/api/test#test-only) 标记的测试,Vitest 将导致测试套件失败,包括在本地开发环境中。
30 changes: 14 additions & 16 deletions config/api.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
---
title: api | Config
title: api | 配置
outline: deep
---

<!-- TODO: translation -->

# api

- **Type:** `boolean | number | object`
- **Default:** `false`
- **CLI:** `--api`, `--api.port`, `--api.host`, `--api.strictPort`
- **类型:** `boolean | number | object`
- **默认值:** `false`
- **命令行终端:** `--api`, `--api.port`, `--api.host`, `--api.strictPort`

Listen to port and serve API for [the UI](/guide/ui) or [browser server](/guide/browser/). When set to `true`, the default port is `51204`.
监听端口并提供 API 服务,用于 [UI 模式](/guide/ui) 或 [浏览器服务](/guide/browser/)。设为 `true` 时,默认端口为 `51204`

## api.allowWrite <Version>4.1.0</Version> {#api-allowwrite}

- **Type:** `boolean`
- **Default:** `true` if not exposed to the network, `false` otherwise
- **类型:** `boolean`
- **默认值:** `true` 表示未暴露在公共网络中,`false` 则表示已暴露

Vitest server can save test files or snapshot files via the API. This allows anyone who can connect to the API the ability to run any arbitrary code on your machine.
Vitest 服务器可以通过 API 保存测试文件或快照文件。这意味着任何能连接到 API 的人都可以在你的机器上运行任意代码。

::: danger SECURITY ADVICE
Vitest does not expose the API to the internet by default and only listens on `localhost`. However if `host` is manually exposed to the network, anyone who connects to it can run arbitrary code on your machine, unless `api.allowWrite` and `api.allowExec` are set to `false`.
::: danger 安全警告
Vitest 默认不会将 API 暴露到互联网,仅在 `localhost` 上监听。但如果 `host` 被手动暴露到网络,任何连接到它的人都可以在你的机器上运行任意代码,除非将 `api.allowWrite` `api.allowExec` 设置为`false`

If the host is set to anything other than `localhost` or `127.0.0.1`, Vitest will set `api.allowWrite` and `api.allowExec` to `false` by default. This means that any write operations (like changing the code in the UI) will not work. However, if you understand the security implications, you can override them.
如果 host 设置为 `localhost` `127.0.0.1` 以外的任何值,Vitest 会默认将 `api.allowWrite` `api.allowExec` 设置为 `false`。这意味着任何写入操作(例如 在 UI 模式中修改代码)将不起作用。如果你了解安全风险,可以覆盖这些设置。
:::

## api.allowExec <Version>4.1.0</Version> {#api-allowexec}

- **Type:** `boolean`
- **Default:** `true` if not exposed to the network, `false` otherwise
- **类型:** `boolean`
- **默认值:** `true` 表示未暴露在公共网络中,`false` 则表示已暴露

Allows running any test file via the API. See the security advice in [`api.allowWrite`](#api-allowwrite).
允许通过 API 运行任何测试文件。详细安全建议请参阅 [`api.allowWrite`](#api-allowwrite)
6 changes: 3 additions & 3 deletions config/attachmentsdir.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: attachmentsDir | Config
title: attachmentsDir | 配置
outline: deep
---

# attachmentsDir

- **Type:** `string`
- **Default:** `'.vitest-attachments'`
- **类型:** `string`
- **默认值:** `'.vitest-attachments'`

Directory path for storing attachments created by [`context.annotate`](/guide/test-context#annotate) relative to the project root.
12 changes: 6 additions & 6 deletions config/bail.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: bail | Config
title: bail | 配置
outline: deep
---

# bail

- **Type:** `number`
- **Default:** `0`
- **CLI**: `--bail=<value>`
- **类型:** `number`
- **默认值:** `0`
- **命令行终端:** `--bail=<value>`

Stop test execution when given number of tests have failed.
当指定数量的测试用例失败时立即终止测试执行。

By default Vitest will run all of your test cases even if some of them fail. This may not be desired for CI builds where you are only interested in 100% successful builds and would like to stop test execution as early as possible when test failures occur. The `bail` option can be used to speed up CI runs by preventing it from running more tests when failures have occurred.
默认情况下,即使部分测试失败,Vitest 仍会继续运行所有测试用例。对于仅关注 100% 成功构建的 CI 环境而言,这种行为可能不符合需求——您可能希望在测试出现失败时尽早终止执行。通过配置 `bail` 选项,可在发生失败时阻止后续测试运行,从而加速 CI 流程。
2 changes: 1 addition & 1 deletion config/benchmark.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: benchmark | Config
title: benchmark | 配置
outline: deep
---

Expand Down
16 changes: 8 additions & 8 deletions config/browser/api.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
---
title: browser.api | Config
title: browser.api | 配置
outline: deep
---

<!-- TODO: translation -->

# browser.api

- **Type:** `number | object`
- **Default:** `63315`
- **CLI:** `--browser.api=63315`, `--browser.api.port=1234, --browser.api.host=example.com`
- **类型:** `number | object`
- **默认值:** `63315`
- **命令行终端:** `--browser.api=63315`, `--browser.api.port=1234, --browser.api.host=example.com`

Configure options for Vite server that serves code in the browser. Does not affect [`test.api`](/config/api) option. By default, Vitest assigns port `63315` to avoid conflicts with the development server, allowing you to run both in parallel.

## api.allowWrite <Version>4.1.0</Version> {#api-allowwrite}

- **Type:** `boolean`
- **Default:** `true` if not exposed to the network, `false` otherwise
- **类型:** `boolean`
- **默认值:** `true` if not exposed to the network, `false` otherwise

Vitest saves [annotation attachments](/guide/test-annotations), [artifacts](/api/advanced/artifacts) and [snapshots](/guide/snapshot) by receiving a WebSocket connection from the browser. This allows anyone who can connect to the API write any arbitrary code on your machine within the root of your project (configured by [`fs.allow`](https://vite.dev/config/server-options#server-fs-allow)).

If browser server is not exposed to the internet (the host is `localhost`), this should not be a problem, so the default value in that case is `true`. If you override the host, Vitest will set `allowWrite` to `false` by default to prevent potentially harmful writes.

## api.allowExec <Version>4.1.0</Version> {#api-allowexec}

- **Type:** `boolean`
- **Default:** `true` if not exposed to the network, `false` otherwise
- **类型:** `boolean`
- **默认值:** `true` if not exposed to the network, `false` otherwise

Allows running any test file via the UI. This only applies to the interactive elements (and the server code behind them) in the [UI](/guide/ui) that can run the code. If UI is disabled, this has no effect. See [`api.allowExec`](/config/api#api-allowexec) for more information.
6 changes: 3 additions & 3 deletions config/browser/commands.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: browser.commands | Config
title: browser.commands | 配置
outline: deep
---

# browser.commands

- **Type:** `Record<string, BrowserCommand>`
- **Default:** `{ readFile, writeFile, ... }`
- **类型:** `Record<string, BrowserCommand>`
- **默认值:** `{ readFile, writeFile, ... }`

Custom [commands](/api/browser/commands) that can be imported during browser tests from `vitest/browser`.
6 changes: 3 additions & 3 deletions config/browser/connecttimeout.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: browser.connectTimeout | Config
title: browser.connectTimeout | 配置
outline: deep
---

# browser.connectTimeout

- **Type:** `number`
- **Default:** `60_000`
- **类型:** `number`
- **默认值:** `60_000`

The timeout in milliseconds. If connection to the browser takes longer, the test suite will fail.

Expand Down
8 changes: 4 additions & 4 deletions config/browser/detailspanelposition.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
title: browser.detailsPanelPosition | Config
title: browser.detailsPanelPosition | 配置
outline: deep
---

<!-- TODO: translation -->

# browser.detailsPanelPosition

- **Type:** `'right' | 'bottom'`
- **Default:** `'right'`
- **CLI:** `--browser.detailsPanelPosition=bottom`, `--browser.detailsPanelPosition=right`
- **类型:** `'right' | 'bottom'`
- **默认值:** `'right'`
- **命令行终端:** `--browser.detailsPanelPosition=bottom`, `--browser.detailsPanelPosition=right`

Controls the default position of the details panel in the Vitest UI when running browser tests.

Expand Down
8 changes: 4 additions & 4 deletions config/browser/enabled.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: browser.enabled | Config
title: browser.enabled | 配置
---

# browser.enabled

- **Type:** `boolean`
- **Default:** `false`
- **CLI:** `--browser`, `--browser.enabled=false`
- **类型:** `boolean`
- **默认值:** `false`
- **命令行终端:** `--browser`, `--browser.enabled=false`

Enabling this flag makes Vitest run all tests in a [browser](/guide/browser/) by default. If you are configuring other browser options via the CLI, you can use `--browser.enabled` alongside them instead of `--browser`:

Expand Down
10 changes: 5 additions & 5 deletions config/browser/expect.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: browser.expect | Config
title: browser.expect | 配置
outline: deep
---

# browser.expect

- **Type:** `ExpectOptions`
- **类型:** `ExpectOptions`

## browser.expect.toMatchScreenshot

Expand Down Expand Up @@ -48,7 +48,7 @@ available: `resolveScreenshotPath` and `resolveDiffPath`.

## browser.expect.toMatchScreenshot.resolveScreenshotPath

- **Type:** `(data: PathResolveData) => string`
- **类型:** `(data: PathResolveData) => string`
- **Default output:** `` `${root}/${testFileDirectory}/${screenshotDirectory}/${testFileName}/${arg}-${browserName}-${platform}${ext}` ``

A function to customize where reference screenshots are stored. The function
Expand Down Expand Up @@ -127,7 +127,7 @@ resolveScreenshotPath: ({ arg, browserName, ext, root, testFileName }) =>

## browser.expect.toMatchScreenshot.resolveDiffPath

- **Type:** `(data: PathResolveData) => string`
- **类型:** `(data: PathResolveData) => string`
- **Default output:** `` `${root}/${attachmentsDir}/${testFileDirectory}/${testFileName}/${arg}-${browserName}-${platform}${ext}` ``

A function to customize where diff images are stored when screenshot comparisons
Expand All @@ -143,7 +143,7 @@ resolveDiffPath: ({ arg, attachmentsDir, browserName, ext, root, testFileName })

## browser.expect.toMatchScreenshot.comparators

- **Type:** `Record<string, Comparator>`
- **类型:** `Record<string, Comparator>`

Register custom screenshot comparison algorithms, like [SSIM](https://en.wikipedia.org/wiki/Structural_similarity_index_measure) or other perceptual similarity metrics.

Expand Down
8 changes: 4 additions & 4 deletions config/browser/headless.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: browser.headless | Config
title: browser.headless | 配置
outline: deep
---

# browser.headless

- **Type:** `boolean`
- **Default:** `process.env.CI`
- **CLI:** `--browser.headless`, `--browser.headless=false`
- **类型:** `boolean`
- **默认值:** `process.env.CI`
- **命令行终端:** `--browser.headless`, `--browser.headless=false`

Run the browser in a `headless` mode. If you are running Vitest in CI, it will be enabled by default.
6 changes: 3 additions & 3 deletions config/browser/instances.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: browser.instances | Config
title: browser.instances | 配置
outline: deep
---

# browser.instances

- **Type:** `BrowserConfig`
- **Default:** `[]`
- **类型:** `BrowserConfig`
- **默认值:** `[]`

Defines multiple browser setups. Every config has to have at least a `browser` field.

Expand Down
8 changes: 4 additions & 4 deletions config/browser/isolate.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: browser.isolate | Config
title: browser.isolate | 配置
outline: deep
---

# browser.isolate <Deprecated />

- **Type:** `boolean`
- **Default:** the same as [`--isolate`](/config/isolate)
- **CLI:** `--browser.isolate`, `--browser.isolate=false`
- **类型:** `boolean`
- **默认值:** the same as [`--isolate`](/config/isolate)
- **命令行终端:** `--browser.isolate`, `--browser.isolate=false`

Run every test in a separate iframe.

Expand Down
2 changes: 1 addition & 1 deletion config/browser/locators.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: browser.locators | Config
title: browser.locators | 配置
outline: deep
---

Expand Down
6 changes: 3 additions & 3 deletions config/browser/orchestratorscripts.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: browser.orchestratorScripts | Config
title: browser.orchestratorScripts | 配置
outline: deep
---

# browser.orchestratorScripts

- **Type:** `BrowserScript[]`
- **Default:** `[]`
- **类型:** `BrowserScript[]`
- **默认值:** `[]`

Custom scripts that should be injected into the orchestrator HTML before test iframes are initiated. This HTML document only sets up iframes and doesn't actually import your code.

Expand Down
Loading
Loading