Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 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. 别名只影响由 [inlined](/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:` 前缀进行别名。
:::
2 changes: 1 addition & 1 deletion config/allowonly.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ outline: deep

- **Type**: `boolean`
- **Default**: `!process.env.CI`
- **CLI:** `--allowOnly`, `--allowOnly=false`
- **命令行终端:** `--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.

Expand Down
14 changes: 7 additions & 7 deletions config/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ outline: deep

# 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.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 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.

Expand All @@ -28,7 +28,7 @@ If the host is set to anything other than `localhost` or `127.0.0.1`, Vitest wil

## 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 API. See the security advice in [`api.allowWrite`](#api-allowwrite).
4 changes: 2 additions & 2 deletions config/attachmentsdir.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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.
4 changes: 2 additions & 2 deletions config/bail.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ outline: deep

# bail

- **Type:** `number`
- **Default:** `0`
- **类型:** `number`
- **默认值:** `0`
- **CLI**: `--bail=<value>`

Stop test execution when given number of tests have failed.
Expand Down
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
14 changes: 7 additions & 7 deletions config/browser/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ outline: deep

# 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 arbitary 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.
4 changes: 2 additions & 2 deletions config/browser/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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`.
4 changes: 2 additions & 2 deletions config/browser/connecttimeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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
6 changes: 3 additions & 3 deletions config/browser/detailspanelposition.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ outline: deep

# 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
6 changes: 3 additions & 3 deletions config/browser/enabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ title: browser.enabled | Config

# 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
8 changes: 4 additions & 4 deletions config/browser/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
6 changes: 3 additions & 3 deletions config/browser/headless.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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.
4 changes: 2 additions & 2 deletions config/browser/instances.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ outline: deep

# browser.instances

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

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

Expand Down
6 changes: 3 additions & 3 deletions config/browser/isolate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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
4 changes: 2 additions & 2 deletions config/browser/orchestratorscripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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
4 changes: 2 additions & 2 deletions config/browser/playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ await userEvent.click(page.getByRole('button'), {

## `persistentContext` <Version>4.1.0</Version> {#persistentcontext}

- **Type:** `boolean | string`
- **Default:** `false`
- **类型:** `boolean | string`
- **默认值:** `false`

When enabled, Vitest uses Playwright's [persistent context](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context) instead of a regular browser context. This allows browser state (cookies, localStorage, DevTools settings, etc.) to persist between test runs.

Expand Down
2 changes: 1 addition & 1 deletion config/browser/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ outline: deep

# browser.provider {#browser-provider}

- **Type:** `BrowserProviderOption`
- **类型:** `BrowserProviderOption`

The return value of the provider factory. You can import the factory from `@vitest/browser-<provider-name>` or make your own provider:

Expand Down
4 changes: 2 additions & 2 deletions config/browser/screenshotfailures.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ outline: deep

# browser.screenshotFailures

- **Type:** `boolean`
- **Default:** `!browser.ui`
- **类型:** `boolean`
- **默认值:** `!browser.ui`

Should Vitest take screenshots if the test fails.
2 changes: 1 addition & 1 deletion config/browser/testerhtmlpath.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ outline: deep

# browser.testerHtmlPath

- **Type:** `string`
- **类型:** `string`

A path to the HTML entry point. Can be relative to the root of the project. This file will be processed with [`transformIndexHtml`](https://vite.dev/guide/api-plugin#transformindexhtml) hook.
6 changes: 3 additions & 3 deletions config/browser/trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ outline: deep

# browser.trace

- **Type:** `'on' | 'off' | 'on-first-retry' | 'on-all-retries' | 'retain-on-failure' | object`
- **CLI:** `--browser.trace=on`, `--browser.trace=retain-on-failure`
- **Default:** `'off'`
- **类型:** `'on' | 'off' | 'on-first-retry' | 'on-all-retries' | 'retain-on-failure' | object`
- **命令行终端:** `--browser.trace=on`, `--browser.trace=retain-on-failure`
- **默认值:** `'off'`

Capture a trace of your browser test runs. You can preview traces with [Playwright Trace Viewer](https://trace.playwright.dev/).

Expand Down
4 changes: 2 additions & 2 deletions config/browser/trackunhandlederrors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ outline: deep

# browser.trackUnhandledErrors

- **Type:** `boolean`
- **Default:** `true`
- **类型:** `boolean`
- **默认值:** `true`

Enables tracking uncaught errors and exceptions so they can be reported by Vitest.

Expand Down
6 changes: 3 additions & 3 deletions config/browser/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ outline: deep

# browser.ui

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

Should Vitest UI be injected into the page. By default, injects UI iframe during development.
16 changes: 8 additions & 8 deletions config/chaiconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ outline: deep

# chaiConfig

- **Type:** `{ includeStack?, showDiff?, truncateThreshold? }`
- **Default:** `{ includeStack: false, showDiff: true, truncateThreshold: 40 }`
- **类型:** `{ includeStack?, showDiff?, truncateThreshold? }`
- **默认值:** `{ includeStack: false, showDiff: true, truncateThreshold: 40 }`

Equivalent to [Chai config](https://github.com/chaijs/chai/blob/4.x.x/lib/chai/config.js).

## chaiConfig.includeStack

- **Type:** `boolean`
- **Default:** `false`
- **类型:** `boolean`
- **默认值:** `false`

Influences whether stack trace is included in Assertion error message. Default of false suppresses stack trace in the error message.

## chaiConfig.showDiff

- **Type:** `boolean`
- **Default:** `true`
- **类型:** `boolean`
- **默认值:** `true`

Influences whether or not the `showDiff` flag should be included in the thrown AssertionErrors. `false` will always be `false`; `true` will be true when the assertion has requested a diff to be shown.

## chaiConfig.truncateThreshold

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

Sets length threshold for actual and expected values in assertion errors. If this threshold is exceeded, for example for large data structures, the value is replaced with something like `[ Array(3) ]` or `{ Object (prop1, prop2) }`. Set it to `0` if you want to disable truncating altogether.

Expand Down
4 changes: 2 additions & 2 deletions config/clearmocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ outline: deep

# clearMocks

- **Type:** `boolean`
- **Default:** `false`
- **类型:** `boolean`
- **默认值:** `false`

Should Vitest automatically call [`vi.clearAllMocks()`](/api/vi#vi-clearallmocks) before each test.

Expand Down
Loading
Loading