Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions api/advanced/test-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export interface TestResultPending {
```ts
interface TestResultSkipped {
/**
* 使用 `skip` 或 `todo` 标志跳过测试
* 使用 `skip` 或 `todo` 参数跳过测试
* 你可以在 `options.mode` 选项中查看使用的是哪种模式。
*/
readonly state: 'skipped'
Expand All @@ -193,7 +193,7 @@ interface TestResultSkipped {
```

::: tip
如果测试因为其他测试有 `only` 标志而被跳过,则 `options.mode` 将等于 `skip`。
如果测试因为其他测试有 `only` 参数而被跳过,则 `options.mode` 将等于 `skip`。
:::

如果测试失败,返回值将是 `TestResultFailed`:
Expand Down Expand Up @@ -246,7 +246,7 @@ interface TestDiagnostic {
readonly slow: boolean
/**
* 测试使用的内存量(字节)。
* 只有使用 `logHeapUsage` 标志执行测试时,该值才可用。
* 只有使用 `logHeapUsage` 参数执行测试时,该值才可用。
*/
readonly heap: number | undefined
/**
Expand Down
2 changes: 1 addition & 1 deletion api/advanced/test-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ interface ModuleDiagnostic {
readonly duration: number
/**
* 模块使用的内存量(以字节为单位)。
* 此值仅在使用 `logHeapUsage` 标志执行测试时才可用
* 此值仅在使用 `logHeapUsage` 参数执行测试时才可用
*/
readonly heap: number | undefined
/**
Expand Down
2 changes: 1 addition & 1 deletion api/advanced/test-suite.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const hash = generateFileHash(

## location

套件在模块中定义的位置。仅当配置中启用了 [`includeTaskLocation`](/config/includetasklocation) 时才会收集位置信息。请注意,如果使用了 `--reporter=html`、`--ui` 或 `--browser` 标志,此选项会自动启用。
套件在模块中定义的位置。仅当配置中启用了 [`includeTaskLocation`](/config/includetasklocation) 时才会收集位置信息。请注意,如果使用了 `--reporter=html`、`--ui` 或 `--browser` 参数,此选项会自动启用。

此套件的位置将等于 `{ line: 3, column: 1 }`:

Expand Down
10 changes: 5 additions & 5 deletions api/advanced/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ function getRelevantTestSpecifications(
): Promise<TestSpecification[]>
```

此方法通过调用 [`project.globTestFiles`](/api/advanced/test-project#globtestfiles) 解析每个测试规范。它接受字符串过滤器以匹配测试文件 - 这些过滤器与 [CLI 支持的过滤器](/guide/filtering#cli) 相同。如果指定了 `--changed` 标志,则列表将被过滤为仅包含已更改的文件。`getRelevantTestSpecifications` 不会运行任何测试文件。
此方法通过调用 [`project.globTestFiles`](/api/advanced/test-project#globtestfiles) 解析每个测试规范。它接受字符串过滤器以匹配测试文件 - 这些过滤器与 [CLI 支持的过滤器](/guide/filtering#cli) 相同。如果指定了 `--changed` 参数,则列表将被过滤为仅包含已更改的文件。`getRelevantTestSpecifications` 不会运行任何测试文件。

::: warning
此方法可能很慢,因为它需要过滤 `--changed` 标志。如果我们只需要测试文件列表,请不要使用它。
此方法可能很慢,因为它需要过滤 `--changed` 参数。如果我们只需要测试文件列表,请不要使用它。

- 如果我们需要获取已知测试文件的规范列表,请使用 [`getModuleSpecifications`](#getmodulespecifications) 代替。
- 如果我们需要获取所有可能的测试文件列表,请使用 [`globTestSpecifications`](#globtestspecifications)。
Expand All @@ -216,7 +216,7 @@ function collect(filters?: string[]): Promise<TestRunResult>

执行测试文件而不运行测试回调。`collect` 返回未处理的错误和 [测试模块](/api/advanced/test-module) 数组。它接受字符串过滤器以匹配测试文件 - 这些过滤器与 [CLI 支持的过滤器](/guide/filtering#cli) 相同。

此方法根据配置的 `include`、`exclude` 和 `includeSource` 值解析测试规范。有关更多信息,请参阅 [`project.globTestFiles`](/api/advanced/test-project#globtestfiles)。如果指定了 `--changed` 标志,则列表将被过滤为仅包含已更改的文件。
此方法根据配置的 `include`、`exclude` 和 `includeSource` 值解析测试规范。有关更多信息,请参阅 [`project.globTestFiles`](/api/advanced/test-project#globtestfiles)。如果指定了 `--changed` 参数,则列表将被过滤为仅包含已更改的文件。

::: warning
请注意,Vitest 不使用静态分析来收集测试。Vitest 将像运行常规测试一样在隔离环境中运行每个测试文件。
Expand Down Expand Up @@ -246,9 +246,9 @@ function standalone(): Promise<void>

- **别名:** `init` <Deprecated />

初始化报告器和覆盖率提供者。此方法不运行任何测试。如果提供了 `--watch` 标志,Vitest 仍将运行更改的测试,即使未调用此方法。
初始化报告器和覆盖率提供者。此方法不运行任何测试。如果提供了 `--watch` 参数,Vitest 仍将运行更改的测试,即使未调用此方法。

在内部,仅当启用了 [`--standalone`](/guide/cli#standalone) 标志时才会调用此方法
在内部,仅当启用了 [`--standalone`](/guide/cli#standalone) 参数时才会调用此方法

::: warning
如果还调用了 [`vitest.start()`](#start),则不应调用此方法。
Expand Down
2 changes: 1 addition & 1 deletion api/assert-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
你可以使用此函数作为 [`expectTypeOf`](/api/expect-typeof) 的替代方法,以轻松地断言参数类型等于提供的泛型。

::: warning
在运行时,此函数不执行任何操作。要 [启用类型检查](/guide/testing-types#run-typechecking),不要忘记传递 `--typecheck` 标志
在运行时,此函数不执行任何操作。要 [启用类型检查](/guide/testing-types#run-typechecking),不要忘记传递 `--typecheck` 参数
:::

```ts
Expand Down
2 changes: 1 addition & 1 deletion api/browser/assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ function toMatchScreenshot(
:::

::: tip
若截图对比因**有意变更**而失败,可在监听模式下按 `u` 键,或运行测试时加上 `-u`/`--update` 标志,以更新基准图。
若截图对比因**有意变更**而失败,可在监听模式下按 `u` 键,或运行测试时加上 `-u`/`--update` 参数,以更新基准图。
:::

```html
Expand Down
2 changes: 1 addition & 1 deletion api/describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe.concurrent('suite', () => {

- **别名:** `suite.shuffle`

Vitest 通过 CLI 标志 [`--sequence.shuffle`](/guide/cli) 或配置选项 [`sequence.shuffle`](/config/sequence#sequence-shuffle),提供了一种以随机顺序运行所有测试的方法。但如果只想让测试套件的一部分以随机顺序运行,可以用这个标志来标记它
Vitest 通过 CLI 参数 [`--sequence.shuffle`](/guide/cli) 或配置选项 [`sequence.shuffle`](/config/sequence#sequence-shuffle),提供了一种以随机顺序运行所有测试的方法。但如果只想让测试套件的一部分以随机顺序运行,可以用这个参数来标记它

```ts
import { describe, test } from 'vitest'
Expand Down
2 changes: 1 addition & 1 deletion api/expect-typeof.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- **类型:** `<T>(a: unknown) => ExpectTypeOf`

::: warning
在运行时,此函数不执行任何操作。要 [enable typechecking](/guide/testing-types#run-typechecking),不要忘记传递 `--typecheck` 标志
在运行时,此函数不执行任何操作。要 [enable typechecking](/guide/testing-types#run-typechecking),不要忘记传递 `--typecheck` 参数
:::

## not
Expand Down
2 changes: 1 addition & 1 deletion api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ vitest interesting.test.ts
```

::: warning
Vitest 会检测当前是否在 CI 环境中运行,如果有任何测试带有 `only` 标志,将会抛出错误。你可以通过 [`allowOnly`](/config/allowonly) 选项来配置此行为。
Vitest 会检测当前是否在 CI 环境中运行,如果有任何测试带有 `only` 参数,将会抛出错误。你可以通过 [`allowOnly`](/config/allowonly) 选项来配置此行为。
:::

## test.concurrent
Expand Down
2 changes: 1 addition & 1 deletion blog/vitest-3-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ it('calls console.log', () => {

Vitest 现在向测试主体提供一个 [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) 对象。你可以使用它来停止任何支持此 Web API 的资源。

当测试超时、其他测试失败且 [`--bail` 标志](/config/bail) 设置为非零值,或者用户在终端中按下 Ctrl+C 时,信号会被中止。
当测试超时、其他测试失败且 [`--bail` 参数](/config/bail) 设置为非零值,或者用户在终端中按下 Ctrl+C 时,信号会被中止。

例如,你可以在测试中断时停止 `fetch` 请求:

Expand Down
2 changes: 1 addition & 1 deletion config/browser/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ type Comparator<Options> = (
::: tip 性能注意事项
`createDiff` 选项表示是否需要生成差异图像。在 [稳定截图检测](/guide/browser/visual-regression-testing#how-visual-tests-work) 过程中,Vitest 会以 `createDiff: false` 调用比较器以避免不必要的计算。

**请遵守此标志以保持测试速度**。
**请遵守此参数以保持测试速度**。

::: warning 处理缺失参数
`toMatchScreenshot()` 中的 `options` 参数是可选的,因此用户可能不会提供所有比较器选项。务必使用默认值使它们成为可选的:
Expand Down
2 changes: 1 addition & 1 deletion config/browser/playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default defineConfig({
::: warning
Vitest 将忽略 `launch.headless` 选项。请改用 [`test.browser.headless`](/config/browser/headless)。

请注意,如果启用了 [`--inspect`](/guide/cli#inspect),Vitest 会将调试标志推送到 `launch.args`。
请注意,如果启用了 [`--inspect`](/guide/cli#inspect),Vitest 会将调试参数推送到 `launch.args`。
:::

::: tip 启用新版 Chromium 无头模式
Expand Down
2 changes: 1 addition & 1 deletion config/chaiconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ outline: deep
- **类型:** `boolean`
- **默认值:** `true`

控制是否在抛出的 AssertionError 中包含 `showDiff` 标志。设为 `false` 将始终禁用差异显示;设为 `true` 则当断言请求显示差异时才会启用。
控制是否在抛出的 AssertionError 中包含 `showDiff` 参数。设为 `false` 将始终禁用差异显示;设为 `true` 则当断言请求显示差异时才会启用。

## chaiConfig.truncateThreshold

Expand Down
2 changes: 1 addition & 1 deletion config/exclude.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Vitest 使用 [`tinyglobby`](https://npmx.dev/package/tinyglobby) 包来解析 g
::: warning
该配置项不影响代码覆盖率。如需从覆盖率报告中排除特定文件,请使用 [`coverage.exclude`](/config/coverage#exclude)。

如果使用命令行参数,这是唯一一个不会被覆盖配置项。通过 `--exclude` 标志添加的所有 glob 规则都将追加到 `exclude` 中。
如果使用命令行参数,这是唯一一个不会被覆盖配置项。通过 `--exclude` 参数添加的所有 glob 规则都将追加到 `exclude` 中。
:::

## 示例 {#example}
Expand Down
6 changes: 3 additions & 3 deletions config/experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ vitest --experimental.importDurations.failOnDanger
- 测试文件及源码不会经过 Vite 处理
- 全局初始化文件不会被处理
- 自定义运行器 / 池 / 环境文件不会被处理
- 配置文件仍由 Vite 处理(该过程发生在 Vitest 获知 `viteModuleRunner` 标志之前执行
- 配置文件仍由 Vite 处理(该过程发生在 Vitest 获知 `viteModuleRunner` 参数之前执行

::: warning
当前 Vitest 仍需依赖 Vite 实现某些功能,如模块图或监视模式。
Expand Down Expand Up @@ -427,7 +427,7 @@ interface VCSProviderOptions {

- **默认值:** `'git'`

用于检测更改文件的自定义驱动。与 [`--changed`](/guide/cli#changed) 标志配合使用,用于确定哪些文件已被修改。
用于检测更改文件的自定义驱动。与 [`--changed`](/guide/cli#changed) 参数配合使用,用于确定哪些文件已被修改。

默认情况下,Vitest 使用 Git 检测更改的文件。你可以提供 `VCSProvider` 接口的自定义实现以使用不同的版本控制系统:

Expand Down Expand Up @@ -488,7 +488,7 @@ export default {
在运行测试前预解析测试规范。这会在所有文件中应用 [`.only`](/api/test#test-only) 修饰符、[`-t`](/config/testnamepattern) 测试名称模式、[`--tags-filter`](/guide/test-tags#syntax)、[测试行号](/api/advanced/test-specification#testlines) 和 [测试ID](/api/advanced/test-specification#testids) 而无需执行它们。例如,如果只有一个测试标记了 `.only`,Vitest 将跳过所有其他文件中的测试。

::: tip
使用 [`.only`](/api/test#test-only)、[`-t`](/config/testnamepattern) 标志或 [`--tags-filter`](/guide/test-tags#syntax) 时推荐启用此选项。
使用 [`.only`](/api/test#test-only)、[`-t`](/config/testnamepattern) 参数或 [`--tags-filter`](/guide/test-tags#syntax) 时推荐启用此选项。

无条件启用可能会因额外的解析步骤而降低测试运行速度。
:::
Expand Down
4 changes: 2 additions & 2 deletions config/stricttags.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ outline: deep
- **命令行终端:** `--strict-tags`, `--no-strict-tags`

如果测试使用了未在配置中定义的 [`tag`](/config/tags),Vitest 是否应抛出错误,以避免因拼写错误导致意外的行为(应用错误的配置或因
`--tags-filter` 标志而跳过测试)。
`--tags-filter` 参数而跳过测试)。

注意,如果 `--tags-filter` 标志定义了配置中不存在的标签,Vitest 将会抛出错误。
注意,如果 `--tags-filter` 参数定义了配置中不存在的标签,Vitest 将会抛出错误。

例如,以下测试将因标签 `fortnend` 存在拼写错误(正确应为 `frontend`)而抛出错误:

Expand Down
2 changes: 1 addition & 1 deletion config/watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ outline: deep

交互式环境中,默认启用监听模式,除非显式传入 `--run`。

在 CI 或非交互式 shell 中,监听模式默认关闭,但可通过该标志显式启用
在 CI 或非交互式 shell 中,监听模式默认关闭,但可通过该参数显式启用
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default antfu(
'no-self-compare': 'off',
'import/no-mutable-exports': 'off',
'no-throw-literal': 'off',
'markdown/no-missing-link-fragments': 'off',
},
},
createSimplePlugin({
Expand Down
20 changes: 10 additions & 10 deletions guide/advanced/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ class MyReporter implements Reporter {
}
}
```
<!-- TODO: translation -->
## Storing artifacts on file system

## 在文件系统上存储附件 {#storing-artifacts-on-file-system}

::: tip
Vitest provides [`vitest.createReport`](/api/advanced/vitest.html#createreport) that exposes collection of utilities for writing artifacts on file system conveniently.
Vitest 提供了 [`vitest.createReport`](/api/advanced/vitest.html#createreport),它公开了一组工具函数,用于在文件系统上写入附件。
:::

If your custom reporter needs to store any artifacts on file system it should place them inside `.vitest` directory. This directory is a convention that Vitest reporters and third party integrations can use to co-locate their results in a single directory. This way users of your custom reporter do not need to add multiple exclusion in their `.gitignore`. Only the `.vitest` is needed.
如果你的自定义报告器需要在文件系统上存储任何附件,应该将它们放在 `.vitest` 目录中。这个目录是一个约定,Vitest 报告器和第三方集成可以使用它将结果放在同一个目录中。这样,你的自定义报告器的用户就不需要在他们的 `.gitignore` 中添加多个排除项。只需要排除 `.vitest` 即可。

Reporters and other integrations should respect following rules around `.vitest` directory:
报告器和其他集成应遵守以下关于 `.vitest` 目录的规则:

- `.vitest` directory is placed in [the `root` of the project](/config/root)
- Reporter can create `.vitest` directory if it does not already exist
- Reporter should never remove `.vitest` directory
- Reporter should create their own directory inside `.vitest`, for example `.vitest/yaml-reporter/`
- Reporter can remove their own specific directory inside `.vitest`, for example `.vitest/yaml-reporter/`
- `.vitest` 目录位于项目的 [根目录](/config/root)
- 如果 `.vitest` 目录不存在,报告器将自行创建
- 报告器绝不会删除 `.vitest` 目录
- 报告器会在 `.vitest` 内创建自己的目录,例如 `.vitest/yaml-reporter/`
- 报告器会删除其在 `.vitest` 内的特定目录,例如 `.vitest/yaml-reporter/`

```ansi
.vitest
Expand Down
2 changes: 1 addition & 1 deletion guide/advanced/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ finally {
}
```

如果我们打算保留 `Vitest` 实例,请确保至少调用 [`init`](/api/advanced/vitest#init) 。这将初始化报告器和覆盖率提供者,但不会运行任何测试。即使我们不打算使用 Vitest 观察器,但希望保持实例运行,也建议启用 `watch` 模式。Vitest 依赖此标志使其某些功能在连续过程中正常工作
如果我们打算保留 `Vitest` 实例,请确保至少调用 [`init`](/api/advanced/vitest#init) 。这将初始化报告器和覆盖率提供者,但不会运行任何测试。即使我们不打算使用 Vitest 观察器,但希望保持实例运行,也建议启用 `watch` 模式。Vitest 依赖此参数使其某些功能在连续过程中正常工作

报告器初始化后,如果需要手动运行测试,可以使用 [`runTestSpecifications`](/api/advanced/vitest#runtestspecifications) 或 [`rerunTestSpecifications`](/api/advanced/vitest#reruntestspecifications) 来运行测试。

Expand Down
6 changes: 3 additions & 3 deletions guide/browser/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Vitest 使用 [Vite dev server](https://cn.vitejs.dev/guide/#browser-support)

## 运行测试 {#running-tests}

要使用 CLI 指定浏览器,请使用 `--browser` 标志后跟浏览器名称,如下所示:
要使用 CLI 指定浏览器,请使用 `--browser` 参数后跟浏览器名称,如下所示:

```sh
npx vitest --browser=chromium
Expand All @@ -330,7 +330,7 @@ Vitest 默认会在开发模式下自动打开浏览器界面,测试会在页

无头模式是浏览器模式下可用的另一个选项。在无头模式下,浏览器在没有用户界面的情况下在后台运行,这对于运行自动化测试非常有用。Vitest 中的 headless 选项可以设置为布尔值以启用或禁用无头模式。

在使用无头模式时,Vitest 不会自动打开用户界面。如果我们希望继续使用用户界面,同时让测试以 无头模式运行,我们可以安装 [`@vitest/ui`](/guide/ui) 包,并在运行Vitest时传递 `--ui` 标志
在使用无头模式时,Vitest 不会自动打开用户界面。如果我们希望继续使用用户界面,同时让测试以 无头模式运行,我们可以安装 [`@vitest/ui`](/guide/ui) 包,并在运行Vitest时传递 `--ui` 参数

这是启用无头模式的示例配置:

Expand All @@ -349,7 +349,7 @@ export default defineConfig({
})
```

你还可以在 CLI 中使用 `--browser.headless` 标志设置无头模式,如下所示:
你还可以在 CLI 中使用 `--browser.headless` 参数设置无头模式,如下所示:

```sh
npx vitest --browser.headless
Expand Down
2 changes: 1 addition & 1 deletion guide/browser/multiple-setups.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test('ratio works', () => {

## 过滤 {#filtering}

你可以使用 [`--project` 标志](/guide/cli#project) 来过滤要运行的项目。如果未手动分配项目名称,Vitest 会自动将浏览器名称作为项目名称。如果根配置已经有一个名称,Vitest 会将它们合并:`custom` -> `custom (browser)`。
你可以使用 [`--project` 参数](/guide/cli#project) 来过滤要运行的项目。如果未手动分配项目名称,Vitest 会自动将浏览器名称作为项目名称。如果根配置已经有一个名称,Vitest 会将它们合并:`custom` -> `custom (browser)`。

```shell
$ vitest --project=chromium
Expand Down
8 changes: 4 additions & 4 deletions guide/cli-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,13 @@ Coverage reporters to use. Visit [`coverage.reporter`](/config/coverage#coverage
- **配置:** [coverage.htmlDir](/config/coverage#coverage-htmldir)

UI 模式和 HTML 报告器中提供的 HTML 覆盖率输出目录。
<!-- TODO: translation -->

### coverage.autoAttachSubprocess

- **CLI:** `--coverage.autoAttachSubprocess`
- **Config:** [coverage.autoAttachSubprocess](/config/coverage#coverage-autoattachsubprocess)
- **命令行终端:** `--coverage.autoAttachSubprocess`
- **配置:** [coverage.autoAttachSubprocess](/config/coverage#coverage-autoattachsubprocess)

Track coverage of the `node:child_process` and `node:worker_threads` spawned during test run. Supported only by `v8` provider. (default: false)
跟踪测试运行期间生成的 `node:child_process` `node:worker_threads` 的覆盖率。仅 `v8` 提供程序支持。(默认值:false

### mode

Expand Down
Loading
Loading