From df475a868ba91667471ceb8df032d93d1d2e787b Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 10:41:26 +0800 Subject: [PATCH 01/16] docs(cn): update config/api.md --- config/api.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/config/api.md b/config/api.md index ad6f9b0e..beb853ca 100644 --- a/config/api.md +++ b/config/api.md @@ -18,12 +18,10 @@ outline: deep Vitest 服务器可以通过 API 保存测试文件或快照文件。这意味着任何能连接到 API 的人都可以在你的机器上运行任意代码。 - - -In Browser Mode 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)). This option also gates privileged browser APIs that can write files indirectly, such as raw Chrome DevTools Protocol access through [`cdp()`](/api/browser/context#cdp). +在浏览器模式下,Vitest 通过接收来自浏览器的 WebSocket 连接来保存 [注解附件](/guide/test-annotations)、[产物](/api/advanced/artifacts) 和 [快照](/guide/snapshot)。这使得任何能够连接到 API 的人都可以在你机器上的项目根目录(由 [`fs.allow`](https://cn.vite.dev/config/server-options#server-fs-allow) 配置)内写入任意代码。此选项还会限制可间接写入文件的特权浏览器 API,例如通过 [`cdp()`](/api/browser/context#cdp) 直接访问 Chrome DevTools Protocol。 ::: danger 安全警告 -Vitest 默认不会将 API 暴露到互联网,仅在 `localhost` 上监听。但如果 `host` 被手动暴露到网络,任何连接到它的人都可以在你的机器上运行任意代码,除非将 `api.allowWrite` 和 `api.allowExec` 设置为`false`。 +Vitest 默认不会将 API 暴露到互联网,仅在 `localhost` 上监听。但如果 `host` 被手动暴露到网络,任何连接到它的人都可以在你的机器上运行任意代码,除非将 `api.allowWrite` 和 `api.allowExec` 设置为 `false`。 如果 host 设置为 `localhost` 或 `127.0.0.1` 以外的任何值,Vitest 会默认将 `api.allowWrite` 和 `api.allowExec` 设置为 `false`。这意味着任何写入操作(例如 在 UI 模式中修改代码)将不起作用。如果你了解安全风险,可以覆盖这些设置。 ::: @@ -33,4 +31,4 @@ Vitest 默认不会将 API 暴露到互联网,仅在 `localhost` 上监听。 - **类型:** `boolean` - **默认值:** `true` 表示未暴露在公共网络中,`false` 则表示已暴露 -允许通过 API 运行任何测试文件。 This applies to the interactive elements (and the server code behind them) in the [UI](/guide/ui) that can run the code. This option also gates privileged browser APIs that can execute code indirectly, such as raw Chrome DevTools Protocol access through [`cdp()`](/api/browser/context#cdp). +允许通过 API 运行任何测试文件。适用于 [UI 模式](/guide/ui) 中能够运行代码的交互元素(以及其背后的服务端代码)。此选项还会限制可间接执行代码的特权浏览器 API,例如通过 [`cdp()`](/api/browser/context#cdp) 直接访问 Chrome DevTools Protocol。 From 653ce1e0c8c5e88abad983df393fd16bb156e666 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 10:51:12 +0800 Subject: [PATCH 02/16] docs(cn): update config/fsmodulecachepath.md --- config/benchmark.md | 16 ++++++++-------- config/changed.md | 6 +++--- config/fsmodulecache.md | 8 ++++---- config/fsmodulecachepath.md | 14 +++++++------- config/injectcjsglobals.md | 6 +++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/config/benchmark.md b/config/benchmark.md index 04dcda08..72fc79bb 100644 --- a/config/benchmark.md +++ b/config/benchmark.md @@ -11,8 +11,8 @@ outline: deep ## benchmark.enabled -- **Type:** `boolean` -- **Default:** `false` +- **类型:** `boolean` +- **默认值:** `false` Enables the benchmark project. When set, Vitest creates a dedicated benchmark project alongside your regular test project, runs files matching [`benchmark.include`](#benchmark-include) in it, and exposes the [`bench` fixture](/guide/test-context#bench) to those files. Running `vitest bench` enables this automatically. @@ -41,15 +41,15 @@ Enables the benchmark project. When set, Vitest creates a dedicated benchmark pr ## benchmark.retainSamples -- **Type:** `boolean` -- **Default:** `false` +- **类型:** `boolean` +- **默认值:** `false` Include the `samples` array of per-iteration timings on every benchmark result. Disabled by default to reduce memory usage; enable when a custom reporter or API consumer needs the raw samples. ## benchmark.provider -- **Type:** `string` -- **Default:** `undefined` (uses the built-in provider) +- **类型:** `string` +- **默认值:** `undefined` (uses the built-in provider) The benchmark provider that executes registered benchmarks and returns their results. Set this to a module path whose default export implements `BenchmarkProvider`. Relative paths are resolved from the project root. @@ -57,7 +57,7 @@ See the [Custom Benchmark Provider](/guide/advanced/benchmark-provider) guide fo ## benchmark.suppressExportGetterWarnings -- **Type:** `boolean` -- **Default:** `false` +- **类型:** `boolean` +- **默认值:** `false` Suppress the warning printed when a benchmark accesses module export getters too many times. Vitest tracks getter access during benchmark runs because Vite's module runner wraps every export in a getter, and excessive access can dominate the measurement (see [Module Runner Overhead](/guide/benchmarking#module-runner-overhead)). Enable this when you've intentionally accepted the overhead, or when the warning is noisy for benchmarks where the getter cost is negligible. diff --git a/config/changed.md b/config/changed.md index 4638504f..182a53ab 100644 --- a/config/changed.md +++ b/config/changed.md @@ -5,9 +5,9 @@ outline: deep ### changed -- **Type:** `boolean | string` -- **Default:** `false` -- **CLI:** `--changed`, `--changed=HEAD~1` +- **类型:** `boolean | string` +- **默认值:** `false` +- **命令行终端:** `--changed`, `--changed=HEAD~1` Run tests only against changed files. If no value is provided, it will run tests against uncommitted changes (including staged and unstaged). diff --git a/config/fsmodulecache.md b/config/fsmodulecache.md index 21462176..c6e294e3 100644 --- a/config/fsmodulecache.md +++ b/config/fsmodulecache.md @@ -4,10 +4,10 @@ outline: deep --- # fsModuleCache 5.0.0 - -- **Type:** `boolean` -- **Default:** `false` -- **CLI:** `--fsModuleCache`, `--fsModuleCache=false` + +- **类型:** `boolean` +- **默认值:** `false` +- **命令行终端:** `--fsModuleCache`, `--fsModuleCache=false` In watch mode, Vitest caches all transformed files in memory, which makes reruns fast. However, this cache is discarded once the test run finishes. Enabling this option allows Vitest to persist the transformed modules on the file system, so they can be reused across reruns and separate Vitest processes. diff --git a/config/fsmodulecachepath.md b/config/fsmodulecachepath.md index 420e79ba..9a0dabad 100644 --- a/config/fsmodulecachepath.md +++ b/config/fsmodulecachepath.md @@ -1,19 +1,19 @@ --- -title: fsModuleCachePath | Config +title: fsModuleCachePath | 配置 outline: deep --- # fsModuleCachePath 5.0.0 -- **Type:** `string` -- **Default:** `'node_modules/.vitest-cache'` (resolved from the workspace root) -- **CLI:** `--fsModuleCachePath=` +- **类型:** `string` +- **默认值:** `'node_modules/.vitest-cache'`(从工作区根目录解析) +- **命令行终端:** `--fsModuleCachePath=` -Directory where the [`fsModuleCache`](/config/fsmodulecache) is stored. +存储 [`fsModuleCache`](/config/fsmodulecache) 的目录。 -This can be set per project; projects that don't override it fall back to the root's cache directory. The lockfile metadata used to invalidate the cache is always shared across the whole workspace. +可为每个项目单独设置此选项;未覆盖此选项的项目会降级使用根项目的缓存目录。整个工作区始终共享同一份锁文件元数据,并用它判断缓存是否失效。 -By default Vitest stores the cache inside `node_modules` at the workspace root. The root is based on your package manager's lockfile (for example, `.package-lock.json`, `.yarn-state.yml`, `.pnpm/lock.yaml` and so on). Keeping it inside `node_modules` means the cache is naturally invalidated whenever dependencies are reinstalled. +默认情况下,Vitest 将缓存存储在工作区根目录的 `node_modules` 中。根目录根据包管理器的锁文件确定(例如 `.package-lock.json`、`.yarn-state.yml`、`.pnpm/lock.yaml` 等)。由于缓存保存在 `node_modules` 中,重新安装依赖项时缓存也会随之失效。 ```ts import { defineConfig } from 'vitest/config' diff --git a/config/injectcjsglobals.md b/config/injectcjsglobals.md index 8119828d..6d6d9c5b 100644 --- a/config/injectcjsglobals.md +++ b/config/injectcjsglobals.md @@ -4,9 +4,9 @@ title: injectCjsGlobals | Config # injectCjsGlobals -- **Type:** `boolean` -- **Default:** `true` -- **CLI:** `--no-inject-cjs-globals`, `--injectCjsGlobals=false` +- **类型:** `boolean` +- **默认值:** `true` +- **命令行终端:** `--no-inject-cjs-globals`, `--injectCjsGlobals=false` Inject CommonJS module variables (`module`, `exports`, `require`, `__filename`, `__dirname`) into every module processed by Vitest. From f808fe073e81af5b96fd2c1d433274e1c6b13de9 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 10:57:24 +0800 Subject: [PATCH 03/16] docs(cn): update config/changed.md --- config/changed.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/changed.md b/config/changed.md index 182a53ab..46757970 100644 --- a/config/changed.md +++ b/config/changed.md @@ -1,18 +1,18 @@ --- -title: changed | Config +title: changed | 配置 outline: deep --- - + ### changed - **类型:** `boolean | string` - **默认值:** `false` - **命令行终端:** `--changed`, `--changed=HEAD~1` -Run tests only against changed files. If no value is provided, it will run tests against uncommitted changes (including staged and unstaged). +仅运行受文件变更影响的测试。未指定值时,Vitest 会根据尚未提交的变更(包括已暂存和未暂存的变更)筛选并运行测试。 -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`). +要运行受最近一次提交影响的测试,可使用 `--changed HEAD~1`。也可以传入提交哈希(例如 `--changed 09a9920`)或分支名称(例如 `--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/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. +与 [`forceRerunTriggers`](/config/forcereruntriggers) 配置项配合使用时,只要列表中的任一文件发生变更,Vitest 就会运行整个测试套件。默认情况下,只要 Vitest 配置文件或 `package.json` 发生变更,也会重新运行整个测试套件。 From 3ecc6dff513ebac3c28c541e608534b70979a988 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 11:09:31 +0800 Subject: [PATCH 04/16] docs(cn): update config/benchmark.md --- config/benchmark.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/config/benchmark.md b/config/benchmark.md index 72fc79bb..ec87b60b 100644 --- a/config/benchmark.md +++ b/config/benchmark.md @@ -7,57 +7,57 @@ outline: deep - **类型:** `{ include?, exclude?, ... }` -运行 `vitest bench` 时使用的选项。 - +运行 `vitest bench` 时生效的选项。 + ## benchmark.enabled - **类型:** `boolean` - **默认值:** `false` -Enables the benchmark project. When set, Vitest creates a dedicated benchmark project alongside your regular test project, runs files matching [`benchmark.include`](#benchmark-include) in it, and exposes the [`bench` fixture](/guide/test-context#bench) to those files. Running `vitest bench` enables this automatically. +启用独立的基准测试项目。启用后,Vitest 会在常规测试项目之外创建一个专门用于基准测试的项目。该项目会运行与 [`benchmark.include`](#benchmark-include) 匹配的文件,并向这些文件提供 [`bench` fixture](/guide/test-context#bench)。运行 `vitest bench` 时,此选项会自动启用。 ## benchmark.include - **类型:** `string[]` - **默认值:** `['**/*.{bench,benchmark}.?(c|m)[jt]s?(x)']` -匹配包含基准测试文件的 glob 规则。 +用于匹配基准测试文件的 glob 模式。 ## benchmark.exclude - **类型:** `string[]` - **默认值:** `['node_modules', 'dist', '.idea', '.git', '.cache']` -匹配排除基准测试文件的 glob 规则。 +用于排除基准测试文件的 glob 模式。 ## benchmark.includeSource - **类型:** `string[]` - **默认值:** `[]` -匹配包含内联基准测试文件的 glob 规则。此选项类似于 [`includeSource`](/config/include-source)。 +用于匹配包含内联基准测试的源文件的 glob 模式。此选项与 [`includeSource`](/config/include-source) 类似。 -定义后,Vitest 将运行所有匹配的文件,其中包含 `import.meta.vitest`。 +配置此选项后,Vitest 会运行所有符合模式且包含 `import.meta.vitest` 的文件。 ## benchmark.retainSamples - **类型:** `boolean` - **默认值:** `false` -Include the `samples` array of per-iteration timings on every benchmark result. Disabled by default to reduce memory usage; enable when a custom reporter or API consumer needs the raw samples. +启用后,每项基准测试的结果都会包含 `samples` 数组,用于记录每次迭代的耗时。此选项默认禁用,以减少内存占用。自定义报告器或 API 使用方需要原始采样数据时,可将其启用。 ## benchmark.provider - **类型:** `string` -- **默认值:** `undefined` (uses the built-in provider) +- **默认值:** `undefined`(使用内置 provider) -The benchmark provider that executes registered benchmarks and returns their results. Set this to a module path whose default export implements `BenchmarkProvider`. Relative paths are resolved from the project root. +指定负责执行已注册基准测试并返回结果的 provider。该选项应设置为模块路径,并且模块的默认导出必须实现 `BenchmarkProvider`。如果使用相对路径,Vitest 会从项目根目录开始解析。 -See the [Custom Benchmark Provider](/guide/advanced/benchmark-provider) guide for setup instructions and the provider API. +有关配置方法和 provider API,请参阅 [自定义基准测试 provider](/guide/advanced/benchmark-provider) 指南。 ## benchmark.suppressExportGetterWarnings - **类型:** `boolean` - **默认值:** `false` -Suppress the warning printed when a benchmark accesses module export getters too many times. Vitest tracks getter access during benchmark runs because Vite's module runner wraps every export in a getter, and excessive access can dominate the measurement (see [Module Runner Overhead](/guide/benchmarking#module-runner-overhead)). Enable this when you've intentionally accepted the overhead, or when the warning is noisy for benchmarks where the getter cost is negligible. +禁止显示因基准测试频繁访问模块导出 getter 而产生的警告。Vite 的模块运行器会将每个导出包装为 getter,因此 Vitest 会在基准测试运行期间记录 getter 的访问次数。访问过于频繁时,这部分开销可能成为影响测量结果的主要因素(参阅 [模块运行器开销](/guide/benchmarking#module-runner-overhead))。如果你已接受这项开销,或者 getter 的开销可以忽略不计但警告过于频繁造成了干扰,可启用此选项。 From 6ee64f871101e56847b8ba33426e531baf57c723 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 11:22:21 +0800 Subject: [PATCH 05/16] docs(cn): update config/injectcjsglobals.md --- config/injectcjsglobals.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/config/injectcjsglobals.md b/config/injectcjsglobals.md index 6d6d9c5b..c9b9203c 100644 --- a/config/injectcjsglobals.md +++ b/config/injectcjsglobals.md @@ -1,5 +1,5 @@ --- -title: injectCjsGlobals | Config +title: injectCjsGlobals | 配置 --- # injectCjsGlobals @@ -8,11 +8,11 @@ title: injectCjsGlobals | Config - **默认值:** `true` - **命令行终端:** `--no-inject-cjs-globals`, `--injectCjsGlobals=false` -Inject CommonJS module variables (`module`, `exports`, `require`, `__filename`, `__dirname`) into every module processed by Vitest. +Vitest 会向其处理的每个模块注入 CommonJS 模块变量(`module`、`exports`、`require`、`__filename` 和 `__dirname`)。 -By default, every file that Vitest transforms has access to these variables even if it is written using ESM syntax. This doesn't reflect how modules work in the wild: browsers do not support CommonJS variables, and Node.js doesn't expose them in ES modules. +默认情况下,所有经 Vitest 转换的文件都可以访问这些变量,即使文件使用 ESM 语法编写也不例外。但这与真实运行环境中的模块行为并不一致:浏览器不支持 CommonJS 变量,Node.js 也不会在 ES 模块中提供这些变量。 -To make the module environment stricter and closer to the target runtime, you can disable this behaviour: +如果要使用更严格且更接近目标运行时的模块环境,可以禁用此行为: ```js import { defineConfig } from 'vitest/config' @@ -24,15 +24,15 @@ export default defineConfig({ }) ``` -When this option is disabled, only modules that are detected to be CommonJS receive these variables. CommonJS modules always keep them because they are part of the module scope, without them the module cannot be evaluated at all. The module type is detected the same way Node.js does it: +禁用此选项后,只有被识别为 CommonJS 的模块才能使用这些变量。对于 CommonJS 模块,这些变量属于模块作用域;如果缺少它们,模块将完全无法执行。Vitest 采用与 Node.js 相同的规则识别模块类型: -1. The file extension: `.cjs` and `.cts` files are always CommonJS, `.mjs` and `.mts` files are always ES modules. -2. The `type` field in the nearest `package.json`: `"module"` means ES module, `"commonjs"` means CommonJS. Same as in Node.js, the lookup stops at the first `package.json` and never crosses a `node_modules` boundary, so dependencies don't inherit the `type` of your project. -3. The presence of ESM syntax in the file: if the file has no static `import`/`export` declarations and doesn't reference `import.meta`, it is treated as CommonJS. Syntax inside comments and strings doesn't affect the detection. Dynamic imports are allowed in CommonJS modules, so they don't count as ESM syntax; type-only TypeScript imports are erased during the transform, so they don't count either. +1. 文件扩展名:`.cjs` 和 `.cts` 文件始终被视为 CommonJS 模块,`.mjs` 和 `.mts` 文件始终被视为 ES 模块。 +2. 距离文件最近的 `package.json` 中的 `type` 字段:`"module"` 表示 ES 模块,`"commonjs"` 表示 CommonJS。与 Node.js 一样,Vitest 找到第一个 `package.json` 后便会停止查找,并且不会跨越 `node_modules` 边界。所以,依赖项不会继承当前项目的 `type` 设置。 +3. 文件中是否包含 ESM 语法:如果文件既没有静态 `import`/`export` 声明,也没有引用 `import.meta`,Vitest 就会将其视为 CommonJS 模块。注释和字符串中的语法不会影响识别结果。CommonJS 模块可以使用动态导入,因此动态导入不属于这里所指的 ESM 语法。仅导入类型的 TypeScript 语句会在转换时被移除,也不会影响识别结果。 -The syntax detection is always enabled: Vitest doesn't respect Node.js CLI flags that modify the module type resolution, like `--no-experimental-detect-module`, `--input-type` (it only applies to the string input in Node.js), or the `--experimental-default-type` flag removed in Node.js 23. +Vitest 始终会进行语法检测,不会遵循用于修改模块类型解析方式的 Node.js 命令行选项。例如 `--no-experimental-detect-module`、`--input-type`(在 Node.js 中仅适用于字符串输入),以及已在 Node.js 23 中移除的 `--experimental-default-type`。 -Referencing a CommonJS variable in an ES module throws a `ReferenceError`, just like outside of Vitest: +在 ES 模块中引用 CommonJS 变量时,Vitest 会与其他运行环境一样抛出 `ReferenceError`: ``` ReferenceError: __dirname is not defined @@ -41,7 +41,7 @@ ReferenceError: __dirname is not defined ``` ::: warning -This option doesn't affect externalized modules which are always executed by the native runtime. Node.js provides CommonJS variables to externalized CommonJS modules on its own. +此选项仅影响由 Vitest 处理的模块,不会影响外部化模块。外部化模块始终由原生运行时执行;如果外部化的是 CommonJS 模块,Node.js 会自动提供所需的 CommonJS 变量。 -Note that inlined CommonJS modules are not processed by Vite plugins even when this option is enabled: `require` calls always leave the module runner, so features like mocking do not apply to them. +另外,即使启用了此选项,被内联的 CommonJS 模块也不会经过 Vite 插件处理。由于 `require` 调用会离开模块运行器,mock 等依赖模块运行器的功能无法作用于这类模块。 ::: From 2d1a111534976312f375e284fde359444b1dab01 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 11:37:19 +0800 Subject: [PATCH 06/16] docs(cn): update config/fsmodulecache.md --- config/fsmodulecache.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/config/fsmodulecache.md b/config/fsmodulecache.md index c6e294e3..d00e78ab 100644 --- a/config/fsmodulecache.md +++ b/config/fsmodulecache.md @@ -1,37 +1,37 @@ --- -title: fsModuleCache | Config +title: fsModuleCache | 配置 outline: deep --- # fsModuleCache 5.0.0 - + - **类型:** `boolean` - **默认值:** `false` - **命令行终端:** `--fsModuleCache`, `--fsModuleCache=false` -In watch mode, Vitest caches all transformed files in memory, which makes reruns fast. However, this cache is discarded once the test run finishes. Enabling this option allows Vitest to persist the transformed modules on the file system, so they can be reused across reruns and separate Vitest processes. +在 watch 模式下,Vitest 会将所有转换后的文件缓存在内存中,从而加快重新运行测试的速度。但测试运行结束后,这些缓存便会被丢弃。启用此选项后,Vitest 会将转换后的模块持久化到文件系统中,以便在后续重新运行测试时复用,甚至可以在不同的 Vitest 进程之间共享。 -A single cache directory is shared by every project in the workspace. By default it lives in `node_modules` at the workspace root (so it is naturally invalidated when dependencies are reinstalled); use [`fsModuleCachePath`](/config/fsmodulecachepath) to change its location. You can delete the cache by running [`vitest --clearCache`](/guide/cli#clearcache). +工作区中的所有项目共用一个缓存目录。默认情况下,该目录位于工作区根目录的 `node_modules` 中,因此重新安装依赖项时,缓存也会随之失效。你可以通过 [`fsModuleCachePath`](/config/fsmodulecachepath) 更改缓存目录,也可以运行 [`vitest --clearCache`](/guide/cli#clearcache) 删除缓存。 -::: warning BROWSER SUPPORT -At the moment, this option does not affect [the browser](/guide/browser/). +::: warning 浏览器支持 +目前,此选项对 [浏览器模式](/guide/browser/) 无效。 ::: -You can debug if your modules are cached by running vitest with a `DEBUG=vitest:cache:fs` environment variable: +如果要调试模块的缓存状态,可以设置 `DEBUG=vitest:cache:fs` 环境变量并运行 Vitest: ```shell DEBUG=vitest:cache:fs vitest --fsModuleCache ``` ::: tip -The location of the cache is a single, workspace-wide directory. See [`fsModuleCachePath`](/config/fsmodulecachepath) to move it. +整个工作区的缓存统一存放在同一个目录中。如果要更改该目录,请参阅 [`fsModuleCachePath`](/config/fsmodulecachepath)。 ::: -## Known Issues +## 已知问题 {#known-issues} -Vitest creates a persistent file hash based on file content, its id, Vite's environment configuration and coverage status. Vitest tries to use as much information as it has about the configuration, but it is still incomplete. At the moment, it is not possible to track your plugin options because there is no standard interface for it. +Vitest 会根据文件内容、文件 ID、Vite 环境配置和覆盖率状态生成持久化的文件哈希。Vitest 会尽可能将已知的配置信息纳入计算,但这些信息仍不完整。目前,由于缺少统一的接口,Vitest 无法跟踪插件选项。 -If you have a plugin that relies on things outside the file content or the public configuration (like reading another file or a folder), it's possible that the cache will get stale. To work around that, you can define a [cache key generator](/api/advanced/plugin#definecachekeygenerator) to specify a dynamic option or to opt out of caching for that module: +如果插件的转换结果依赖文件内容或公开配置之外的信息(例如读取其他文件或目录),缓存可能无法及时失效。为避免这种情况,可以定义 [缓存键生成器](/api/advanced/plugin#definecachekeygenerator),将动态选项加入缓存键,或者禁止缓存相应模块: ```js [vitest.config.js] import { defineConfig } from 'vitest/config' @@ -42,12 +42,12 @@ export default defineConfig({ name: 'vitest-cache', configureVitest({ defineCacheKeyGenerator }) { defineCacheKeyGenerator(({ id, sourceCode }) => { - // never cache this id + // 不缓存包含此字符串的模块 if (id.includes('do-not-cache')) { return false } - // cache this file based on the value of a dynamic variable + // 根据动态变量的值缓存此文件 if (sourceCode.includes('myDynamicVar')) { return process.env.DYNAMIC_VAR_VALUE } @@ -61,9 +61,9 @@ export default defineConfig({ }) ``` -If you are a plugin author, consider defining a [cache key generator](/api/advanced/plugin#definecachekeygenerator) in your plugin if it can be registered with different options that affect the transform result. +如果你是插件作者,建议在你的插件中定义一个 [缓存键生成器](/api/advanced/plugin#definecachekeygenerator),因为该插件可能以不同配置项注册,且这些配置项会影响转换结果。 -On the other hand, if your plugin should not affect the cache key, you can opt out by setting `api.vitest.ignoreFsModuleCache` to `true`: +如果插件不应影响缓存键,可以将 `api.vitest.ignoreFsModuleCache` 设置为 `true`,使其不参与缓存键的计算: ```js [vitest.config.js] import { defineConfig } from 'vitest/config' @@ -85,4 +85,4 @@ export default defineConfig({ }) ``` -Note that you can still define the cache key generator even if the plugin opts out of module caching. +注意,即使插件选择不参与模块缓存,仍然可以定义缓存键生成器。 From 532decc56b90d6e6e24dc733a30330861e413f55 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 11:43:33 +0800 Subject: [PATCH 07/16] docs(cn): update config/vmmemorylimit.md --- config/vmmemorylimit.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/config/vmmemorylimit.md b/config/vmmemorylimit.md index 3709a147..e3743550 100644 --- a/config/vmmemorylimit.md +++ b/config/vmmemorylimit.md @@ -12,16 +12,14 @@ outline: deep 指定工作线程被回收之前的内存限制。 - +默认情况下,系统总内存会平均分配给各个工作线程。增大 [`maxWorkers`](/config/maxworkers) 后,每个工作线程可用的内存会相应减少,因此工作线程也会更频繁地被回收。 -By default, the total system memory is split evenly between workers. By increasing [`maxWorkers`](/config/maxworkers), workers have less memory available, so they're recycled more often. +合适的内存限制很大程度上取决于运行环境,因此建议手动设置,不要完全依赖默认值。 -This value heavily depends on your environment, so it's better to specify it manually instead of relying on the default. +之所以需要回收工作线程,是因为 VM 上下文存在 [内存泄漏](https://github.com/nodejs/node/issues/33439):工作线程每运行一个测试文件,内存占用都会增加,因此无法一直复用同一个工作线程。设置内存限制时,需要在以下两种情况之间进行权衡: -Recycling exists because VM contexts [leak memory](https://github.com/nodejs/node/issues/33439): a worker's memory usage grows with every test file it runs, so a worker cannot live forever. The limit is a trade-off: - -- A low limit recycles workers frequently. In the `vmThreads` pool this is expensive, because destroying a worker thread runs a full garbage collection over the worker's memory and competes with running tests for the process' shared background threads. The `vmForks` pool recycles workers by letting the child process exit, which makes frequent recycling much cheaper there. -- A high limit lets workers accumulate memory. When the combined memory usage of all workers approaches what the machine can hold, every pool slows down. +- 较低的限制会导致工作线程被频繁回收。对于 `vmThreads` 线程池,这项操作的开销较高:销毁工作线程时,会对该线程占用的内存执行一次完整的垃圾回收,同时还会与正在运行的测试争用进程共享的后台线程。`vmForks` 线程池则通过结束子进程来回收工作线程,因此频繁回收的开销要低得多。 +- 较高的限制会让工作线程持续占用更多内存。当所有工作线程的内存占用总量接近机器的可用上限时,所有线程池的运行速度都会下降。 ::: tip 该实现基于 Jest 的 [`workerIdleMemoryLimit`](https://jestjs.io/docs/configuration#workeridlememorylimit-numberstring)。 From f7ddebecc1fb339b9c6f8ba69b13adf1adabfe12 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 11:52:30 +0800 Subject: [PATCH 08/16] docs(cn): update config/pool.md --- config/pool.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config/pool.md b/config/pool.md index fe3ac6af..f5f3ab67 100644 --- a/config/pool.md +++ b/config/pool.md @@ -13,22 +13,22 @@ outline: deep ## threads -启用多线程模式。使用线程时,你无法调用进程相关 API 例如 `process.chdir()`。某些原生语言编写的库(如 `Prisma`、`bcrypt` 和 `canvas`)在多线程运行时会出现问题并导致存储器区段错误。此类情况下建议改用 `forks` 执行池。 +启用多线程模式。使用线程时,无法调用 `process.chdir()` 等进程相关 API。某些使用原生语言编写的库(如 `Prisma`、`bcrypt` 和 `canvas`)在多线程运行时会出现问题并导致存储器区段错误。此类情况下建议改用 `forks` 执行池。 ## forks -类似于 `threads` 线程池,但使用 `child_process` 代替 `worker_threads`。测试与主进程之间的通信不如 `threads` 线程池快。在 `forks` 线程池中可以使用与进程相关的 API,如 `process.chdir()`。 +类似于 `threads` 线程池,但使用 `child_process` 代替 `worker_threads`。测试与主进程之间的通信速度不如 `threads`,但可以使用 `process.chdir()` 等进程相关 API。 ## vmThreads -使用 [VM 上下文](https://nodejs.org/api/vm.html)(在沙箱环境中)在 `threads` 线程池中运行测试。 - -This makes tests run faster, but the VM module is unstable when running [ESM code](https://github.com/nodejs/node/issues/37648). Your tests will [leak memory](https://github.com/nodejs/node/issues/33439) - to battle that, workers are restarted when they exceed [`vmMemoryLimit`](/config/vmmemorylimit). +在 `threads` 池中使用 [VM 上下文](https://nodejs.org/api/vm.html),以沙箱方式运行测试。 -::: warning Worker recycling is expensive in `vmThreads` -Restarting a worker thread is not free: Node.js runs a full garbage collection over everything the worker accumulated before the thread can exit, and that work runs on a small pool of background threads shared by every worker in the process. When a large test suite hits [`vmMemoryLimit`](/config/vmmemorylimit) repeatedly, these teardowns pile up and also slow down the workers that are still running tests. +这种方式可以加快测试速度,但 VM 模块在运行 [ESM 代码](https://github.com/nodejs/node/issues/37648) 时并不稳定。此外,测试还会出现 [内存泄漏](https://github.com/nodejs/node/issues/33439)。为限制内存占用,当工作线程使用的内存超过 [`vmMemoryLimit`](/config/vmmemorylimit) 时,Vitest 会将其重启。 -The `vmForks` pool recycles workers by letting the child process exit, and the operating system reclaims the memory. If your test suite is large enough to recycle workers, `vmForks` is usually noticeably faster than `vmThreads`, even though its communication with the main process is slower. +::: warning 在 `vmThreads` 中回收工作线程的开销较高 +重启工作线程会产生明显的开销。在线程退出之前,Node.js 会对该线程积累的所有内存执行一次完整的垃圾回收。这项工作由进程内所有工作线程共用的一小组后台线程执行。当大型测试套件反复触及 [`vmMemoryLimit`](/config/vmmemorylimit) 时,工作线程的销毁操作会不断累积,并拖慢仍在运行测试的其他工作线程。 + +`vmForks` 则通过结束子进程完成回收,内存由操作系统负责释放。如果测试套件规模较大,需要定期回收子进程,那么即使 `vmForks` 与主进程之间的通信速度较慢,其整体运行速度通常仍会明显快于 `vmThreads`。 ::: ::: warning @@ -45,7 +45,7 @@ catch (err) { } ``` -- 导入 ES 模块会导致其被永久缓存,当存在大量上下文(测试文件)时,将引发内存泄漏问题。Node.js 目前未提供清除该缓存的API接口。 +- 导入 ES 模块会导致其被永久缓存,当存在大量上下文(测试文件)时,将引发内存泄漏问题。Node.js 目前未提供清除该缓存的 API 接口。 - 在沙箱环境中访问全局变量 [耗时更长](https://github.com/nodejs/node/issues/31658)。 使用此选项时,需要注意这些问题。Vitest 团队无法解决上诉问题。 @@ -55,4 +55,4 @@ catch (err) { 类似于 `vmThreads` 线程池,但使用 `child_process` 代替 `worker_threads`。测试与主进程之间的通信不如 `vmThreads` 线程池快。在 `vmForks` 线程池中可以使用与进程相关的 API,如 `process.chdir()`。请注意,此线程池具有 `vmThreads` 中列出的相同缺陷。 -Unlike `vmThreads`, recycling a worker that exceeded [`vmMemoryLimit`](/config/vmmemorylimit) only requires the child process to exit, so it is much cheaper. On large test suites that recycle workers regularly, prefer `vmForks` over `vmThreads`. +与 `vmThreads` 不同,当子进程的内存占用超过 [`vmMemoryLimit`](/config/vmmemorylimit) 时,`vmForks` 只需结束该进程即可完成回收,因此开销要低得多。对于需要定期回收子进程的大型测试套件,建议优先使用 `vmForks`。 From d61b9e17b7c4b35f2350699398ea47e1e348bbae Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 11:54:52 +0800 Subject: [PATCH 09/16] docs(cn): update config/projects.md --- config/projects.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/projects.md b/config/projects.md index 033dd923..d589de1e 100644 --- a/config/projects.md +++ b/config/projects.md @@ -10,5 +10,4 @@ outline: deep 一个由多个 [项目](/guide/projects) 组成的数组。 - -A config file that declares `projects` doesn't run tests itself, it only provides the projects that do. This also applies to project config files: a referenced config that declares `projects` becomes a container for [nested projects](/guide/projects#nested-projects). The option is not supported inside an inline project configuration. +声明了 `projects` 的配置文件本身不会运行测试,只负责提供实际运行测试的项目。项目配置文件同样如此:如果被引用的配置文件声明了 `projects`,它将作为 [嵌套项目](/guide/projects#nested-projects) 的容器。内联项目配置不支持此选项。 From 22d8647fdd40a3176eb311e5b5177bdf1842c1d2 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 11:58:52 +0800 Subject: [PATCH 10/16] docs(cn): update config/sequence.md --- config/sequence.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/config/sequence.md b/config/sequence.md index 04cd56d1..1f2b22cb 100644 --- a/config/sequence.md +++ b/config/sequence.md @@ -87,6 +87,7 @@ export default defineConfig({ 1. flaky |> 在 slow 和 fast 运行完后单独运行 ``` + ::: ## sequence.shuffle @@ -105,9 +106,9 @@ Vitest 通常使用缓存对测试进行排序,使耗时较长的测试优先 - **默认值:** `false` - **命令行终端:** `--sequence.shuffle.files`, `--sequence.shuffle.files=false` -是否启用文件随机排序,请注意启用此选项后,耗时较长的测试将无法优先启动执行。 - -Because file ordering is shared across [projects](/guide/projects), this option is resolved from the root config only. A project can still randomize its own tests with [`sequence.shuffle.tests`](#sequence-shuffle-tests). +是否随机排列测试文件。请注意,启用此选项后,耗时较长的测试将无法优先开始执行。 + +由于所有 [项目](/guide/projects) 共享同一套文件排序,因此此选项只能由根配置决定。各个项目仍可通过 [`sequence.shuffle.tests`](#sequence-shuffle-tests) 随机排列自身的测试用例。 ### sequence.shuffle.tests {#sequence-shuffle-tests} @@ -115,7 +116,7 @@ Because file ordering is shared across [projects](/guide/projects), this option - **默认值:** `false` - **命令行终端:** `--sequence.shuffle.tests`, `--sequence.shuffle.tests=false` -Whether to randomize tests. +是否随机排列测试用例。 ## sequence.concurrent {#sequence-concurrent} @@ -147,7 +148,7 @@ Whether to randomize tests. - `stack`:"after" 类钩子按定义顺序逆序执行,"before" 类钩子保持定义顺序执行 - `list`:所有钩子严格按定义顺序执行 -- `parallel`:在单个组内并行运行钩子(父套件的钩子仍会在当前套件的钩子之前运行)。实际并发数受[`maxConcurrency`](/config/maxconcurrency) 限制 +- `parallel`:在单个组内并行运行钩子(父套件的钩子仍会在当前套件的钩子之前运行)。实际并发数受 [`maxConcurrency`](/config/maxconcurrency) 限制 ::: tip 此选项不影响 [`onTestFinished`](/api/hooks#ontestfinished) 钩子,该钩子始终采用逆序调用。 From b0d4910dda2e9dac978a7a9428b7264f7ce7b845 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 12:03:34 +0800 Subject: [PATCH 11/16] docs(cn): update config/browser/expect.md --- config/browser/expect.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/browser/expect.md b/config/browser/expect.md index 9df23a3c..0461378e 100644 --- a/config/browser/expect.md +++ b/config/browser/expect.md @@ -39,15 +39,15 @@ export default defineConfig({ ``` [`toMatchScreenshot` 断言中所有可用选项](/api/browser/assertions#options) 均可在此配置。此外还提供两个路径解析函数:`resolveScreenshotPath` 和 `resolveDiffPath`。 - + ## browser.expect.toMatchScreenshot.screenshotDirectory -- **Type:** `string | undefined` -- **Default:** `__screenshots__` +- **类型:** `string | undefined` +- **默认值:** `__screenshots__` -The directory name used for storing reference screenshots. +用于存放参考截图的目录名称。 -This value is passed as `screenshotDirectory` to [`browser.expect.toMatchScreenshot.resolveScreenshotPath`](#browserexpecttomatchscreenshotresolvescreenshotpath) and [`browser.expect.toMatchScreenshot.resolveDiffPath`](#browserexpecttomatchscreenshotresolvediffpath), and used in the default path resolution of `resolveScreenshotPath`. +该值会作为 `screenshotDirectory` 参数传递给 [`browser.expect.toMatchScreenshot.resolveScreenshotPath`](#browserexpecttomatchscreenshotresolvescreenshotpath) 和 [`browser.expect.toMatchScreenshot.resolveDiffPath`](#browserexpecttomatchscreenshotresolvediffpath)。`resolveScreenshotPath` 的默认路径解析逻辑也会使用该值。 ## browser.expect.toMatchScreenshot.resolveScreenshotPath @@ -115,7 +115,7 @@ This value is passed as `screenshotDirectory` to [`browser.expect.toMatchScreens - `project: TestProject` 4.1.6 - The [`TestProject`](/api/advanced/test-project) the test belongs to. + 测试所属的 [`TestProject`](/api/advanced/test-project)。 例如,以下示例按浏览器分组存储截图: From bc878adecb5e46f11236aeadbd9213eb569211c9 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 12:05:56 +0800 Subject: [PATCH 12/16] docs(cn): update config/browser/webdriverio.md --- config/browser/webdriverio.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/browser/webdriverio.md b/config/browser/webdriverio.md index 37ada23d..aef2a90b 100644 --- a/config/browser/webdriverio.md +++ b/config/browser/webdriverio.md @@ -1,7 +1,7 @@ # 配置 WebdriverIO {#configuring-webdriverio} - -::: info Community maintained -The WebdriverIO provider ([`@vitest/browser-webdriverio`](https://github.com/vitest-community/vitest-webdriverio)) is maintained by the Vitest community in the [`vitest-community`](https://github.com/vitest-community) organization, separately from the core Vitest packages. Please report provider-specific issues to its repository. + +::: info 由社区维护 +WebdriverIO provider([`@vitest/browser-webdriverio`](https://github.com/vitest-community/vitest-webdriverio))由 [`vitest-community`](https://github.com/vitest-community) 组织中的 Vitest 社区负责维护,与 Vitest 核心包分开开发。如果遇到该 provider 特有的问题,请提交到对应的仓库。 ::: 要使用 WebdriverIO 运行测试,你需要安装 [`@vitest/browser-webdriverio`](https://npmx.dev/package/@vitest/browser-webdriverio) npm 包,并在配置中的 `test.browser.provider` 属性中指定其 `webdriverio` 导出: From ca7133f85ebdb35f76227e1c78ef9df03e6b3c54 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 12:13:42 +0800 Subject: [PATCH 13/16] docs(cn): update config/browser/dependencysourcemaps.md --- config/browser/dependencysourcemaps.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config/browser/dependencysourcemaps.md b/config/browser/dependencysourcemaps.md index e8deec98..2e1330a3 100644 --- a/config/browser/dependencysourcemaps.md +++ b/config/browser/dependencysourcemaps.md @@ -1,21 +1,21 @@ --- -title: browser.dependencySourcemaps | Config +title: browser.dependencySourcemaps | 配置 outline: deep --- # browser.dependencySourcemaps -- **Type:** `boolean` -- **Default:** `true` +- **类型:** `boolean` +- **默认值:** `true` -Serve sourcemaps of your dependencies (files in `node_modules`) to the browser during headless test runs. +在无头模式下运行测试时,向浏览器提供依赖项(即 `node_modules` 中的文件)的 source map。 -These sourcemaps are used by browser devtools: with `dependencySourcemaps: false`, pausing inside dependency code shows the compiled code the browser actually runs instead of the dependency's original sources. If you don't debug into your dependencies this way, disabling them makes test runs faster: the server doesn't generate and inline the maps, and every browser tab downloads several times fewer bytes. +浏览器开发者工具会使用这些 source map。设置 `dependencySourcemaps: false` 后,如果调试时暂停在依赖项代码中,开发者工具会显示浏览器实际运行的编译后代码,而不是依赖项的原始源代码。如果不需要以这种方式调试依赖项,可以禁用此选项来加快测试速度。禁用后,服务器无需生成并内联这些 source map,每个浏览器标签页需要下载的数据量也会减少数倍。 -Reported test errors are not affected: when an error is thrown inside a pre-bundled dependency, Vitest maps its stack frames using the sourcemaps stored on disk even when this option is disabled. Frames from dependencies that are served without pre-bundling (for example, [linked packages](https://vite.dev/guide/dep-pre-bundling#monorepos-and-linked-dependencies)) that don't ship their own sourcemaps fall back to the position in the served code, which usually matches the original file. +测试错误的报告结果不受此选项影响。如果错误由预打包的依赖项抛出,即使禁用了此选项,Vitest 仍会使用存储在磁盘上的 source map 映射堆栈帧。对于未经过预打包便直接提供的依赖项,例如 [链接的包](https://cn.vite.dev/guide/dep-pre-bundling#monorepos-and-linked-dependencies),如果它们自身不包含 source map,堆栈帧会回退到所提供代码中的位置。该位置通常与原始文件一致。 -Vitest never serves sourcemaps of its own pre-built modules in headless runs (unless [`--inspect`](/guide/cli#inspect) is used) — their frames are hidden from stack traces anyway. Sourcemaps of your own source files are always served. +在无头模式下运行测试时,Vitest 不会提供自身预构建模块的 source map,除非使用 [`--inspect`](/guide/cli#inspect)。这些模块的堆栈帧本来就会从堆栈跟踪中隐藏。项目自身源文件的 source map 则始终会提供给浏览器。 ::: tip -If some of your workspace code resolves to a `node_modules` path (for example, with `resolve.preserveSymlinks`), set [`server.sourcemapIgnoreList`](https://vite.dev/config/server-options#server-sourcemapignorelist) to keep its sourcemaps even when this option is disabled. +如果工作区中的部分代码被解析为 `node_modules` 下的路径,例如启用了 `resolve.preserveSymlinks`,请配置 [`server.sourcemapIgnoreList`](https://cn.vite.dev/config/server-options#server-sourcemapignorelist),确保即使禁用了此选项,浏览器仍能获取这些代码的 source map。 ::: From 09f0df01fd021c5cd478b4fa2c4f7acdcb7f9d5a Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 12:16:24 +0800 Subject: [PATCH 14/16] docs(cn): update config/testnamepattern.md --- config/testnamepattern.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/testnamepattern.md b/config/testnamepattern.md index c2f07985..2ed69e1f 100644 --- a/config/testnamepattern.md +++ b/config/testnamepattern.md @@ -8,7 +8,7 @@ outline: deep - **类型:** `string | RegExp` - **命令行终端:** `-t `, `--testNamePattern=`, `--test-name-pattern=` -运行名称完全匹配该模式的测试。如果在此属性中添加 `OnlyRunThis`,则测试中不包含 `OnlyRunThis` 关键字的用例将会被跳过。 +仅运行名称与指定模式匹配的测试。例如,将此选项设为 `OnlyRunThis` 后,名称中不包含 `OnlyRunThis` 的测试都会被跳过。 ```js import { expect, test } from 'vitest' @@ -24,7 +24,7 @@ test('doNotRun', () => { }) ``` -The pattern is matched against the test's full name: the enclosing suite names and the test name joined with `' > '` (the same string shown in the reporter output). For example, the test below has the full name `math > adds`, so it is matched by `-t 'math > adds'` or `-t adds`: +该模式会与测试的完整名称进行匹配。完整名称由外层测试套件名称和测试名称通过 `' > '` 连接而成,与报告器输出中显示的名称相同。例如,以下测试的完整名称为 `math > adds`,因此使用 `-t 'math > adds'` 或 `-t adds` 都能匹配该测试: ```js import { describe, expect, test } from 'vitest' @@ -37,5 +37,5 @@ describe('math', () => { ``` ::: warning -Before Vitest 5, the segments were joined with a single space (`math adds`) to mirror Jest. See the [migration guide](/guide/migration#vitest-5) for details. +在 Vitest 5 之前,为了与 Jest 保持一致,名称中的各部分使用单个空格连接(`math adds`)。详情请参阅 [迁移指南](/guide/migration#vitest-5)。 ::: From ffd7ddfbf7ece1a49bac13c74f207b45aac082c8 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 12:18:17 +0800 Subject: [PATCH 15/16] docs(cn): update config/attachmentsdir.md --- config/attachmentsdir.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/attachmentsdir.md b/config/attachmentsdir.md index ef94a63e..75890078 100644 --- a/config/attachmentsdir.md +++ b/config/attachmentsdir.md @@ -8,6 +8,6 @@ outline: deep - **类型:** `string` - **默认值:** `'.vitest/attachments'` -Directory path for storing file attachments created by [`context.annotate`](/guide/test-context#annotate). +指定通过 [`context.annotate`](/guide/test-context#annotate) 创建的文件附件的存储目录。 -This option is resolved relative to the root Vitest config. When using [`projects`](/guide/projects), all projects share the same `attachmentsDir`; it cannot be configured per project. +Vitest 会相对于根配置解析此路径。使用 [`projects`](/guide/projects) 时,所有项目共用同一个 `attachmentsDir`,无法为每个项目单独配置。 From 9f6d124fb2d7df1a818ed34dd3e967fdafae4728 Mon Sep 17 00:00:00 2001 From: noise Date: Sun, 9 Aug 2026 12:20:55 +0800 Subject: [PATCH 16/16] docs(cn): update .vitepress/config.ts --- .vitepress/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vitepress/config.ts b/.vitepress/config.ts index ef1e4e51..b180664d 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -613,7 +613,7 @@ export default ({ mode }: { mode: string }) => { ], }, { - text: 'Browser Mode', + text: '浏览器模式', collapsed: false, items: [ {