Skip to content

Commit 368baa8

Browse files
authored
docs(cn): translate /guide (#1001)
* docs(cn): translate /guide * docs(cn): update package.json version * docs(cn): update guide/mocking/functions.md * docs(cn): update miss translate * typo
1 parent b202296 commit 368baa8

42 files changed

Lines changed: 231 additions & 235 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vitepress/components/FeaturesList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ListItem from './ListItem.vue'
66
<ul class="features-list" dir="auto">
77
<ListItem>
88
9-
<a target="_blank" href="https://vitejs.dev" rel="noopener noreferrer">Vite</a>
9+
<a target="_blank" href="https://cn.vitejs.dev" rel="noopener noreferrer">Vite</a>
1010
通用的配置、转换器、解析器和插件。
1111
</ListItem>
1212
<ListItem>使用与你的应用相同的设置来运行测试!</ListItem>

.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ export default ({ mode }: { mode: string }) => {
898898
],
899899
},
900900
{
901-
text: '测试',
901+
text: '测试标签',
902902
link: '/guide/test-tags',
903903
},
904904
{

api/advanced/reporters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function onTestRunStart(
7979
): Awaitable<void>
8080
```
8181

82-
当新的测试运行开始时调用此方法。它接收计划运行的 [测试规范](/api/advanced/test-specification) 数组。此数组是只读的,仅用于信息目的。
82+
当新的测试运行开始时调用此方法。它接收计划运行的 [TestSpecification](/api/advanced/test-specification) 数组。此数组是只读的,仅用于信息目的。
8383

8484
如果 Vitest 没有找到任何要运行的测试文件,此事件将以空数组调用,然后 [`onTestRunEnd`](#ontestrunend) 将立即被调用。
8585

api/advanced/test-case.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,19 @@ function artifacts(): ReadonlyArray<TestArtifact>
292292
```
293293

294294
通过 `recordArtifact` API,在测试执行过程中记录的 [测试产物](/api/advanced/artifacts)。
295-
<!-- TODO: translation -->
295+
296296
## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
297297

298298
```ts
299299
function toTestSpecification(): TestSpecification
300300
```
301301

302-
Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test case.
302+
返回一个新的 [TestSpecification](/api/advanced/test-specification),可用于过滤或运行此特定测试用例。
303303

304304
## logs <Version>5.0.0</Version> {#logs}
305305

306306
```ts
307307
function logs(): ReadonlyArray<UserConsoleLog>
308308
```
309309

310-
Console logs recorded during the test execution.
310+
测试执行期间记录的 console 日志。

api/advanced/test-module.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ if (task.type === 'module') {
3333
'example.test.ts' //
3434
'project\\example.test.ts' //
3535
```
36-
<!-- TODO: translation -->
36+
3737
## viteEnvironment <Version>4.1.0</Version> {#viteenvironment}
3838

39-
This is a Vite's [`DevEnvironment`](https://vite.dev/guide/api-environment) that transforms all files inside of the test module.
39+
这是一个 Vite[`DevEnvironment`](https://cn.vite.dev/guide/api-environment),它会转换测试模块内的所有文件。
4040

41-
::: details History
42-
- `v4.0.15`: added as experimental
41+
::: details 历史
42+
- `v4.0.15`:已作为实验性功能
4343
:::
4444

4545
## state
@@ -88,51 +88,52 @@ function diagnostic(): ModuleDiagnostic
8888
```ts
8989
interface ModuleDiagnostic {
9090
/**
91-
* 导入和初始化环境所需的时间
91+
* 导入和初始化环境所需的时间
9292
*/
9393
readonly environmentSetupDuration: number
9494
/**
95-
* Vitest 设置测试运行环境(运行器、模拟等)所需的时间
95+
* Vitest 设置测试运行环境(运行器、模拟等)所需的时间
9696
*/
9797
readonly prepareDuration: number
9898
/**
99-
* 导入测试模块所需的时间
100-
* 这包括导入模块中的所有内容以及执行套件回调函数
99+
* 导入测试模块所需的时间
100+
* 这包括导入模块中的所有内容以及执行套件回调函数
101101
*/
102102
readonly collectDuration: number
103103
/**
104-
* 导入设置模块所需的时间
104+
* 导入设置模块所需的时间
105105
*/
106106
readonly setupDuration: number
107107
/**
108108
* 模块中所有测试和钩子函数的累计持续时间。
109109
*/
110110
readonly duration: number
111111
/**
112-
* 模块使用的内存量(以字节为单位)
113-
* 此值仅在使用 `logHeapUsage` 参数执行测试时才可用
112+
* 模块使用的内存量(以字节为单位)
113+
* 此值仅在使用 `logHeapUsage` 参数执行测试时才可用
114114
*/
115115
readonly heap: number | undefined
116116
/**
117-
* Vitest处理的每个非外部化依赖项的导入时间
117+
* Vitest处理的每个非外部化依赖项的导入时间
118118
*/
119119
readonly importDurations: Record<string, ImportDuration>
120120
/**
121-
* The id of the worker that ran this file. This value cannot be higher than `maxWorkers`.
122-
* If file did not run yet, this will be 0.
121+
* 运行此文件的 worker 的 ID。此值不能高于 `maxWorkers`
122+
* 如果文件尚未运行,此值将为 0。
123123
*
124-
* **Warning**: Node.js tests and browser tests run in different pools and do not share `concurrencyId`.
125-
* It is possible to have multiple modules with the same `concurrencyId` because of that.
126-
* Use `project.isBrowserEnabled()` to distinguish the concurrency.
124+
* **警告**:Node.js 测试和浏览器测试在不同的池中运行,不共享 `concurrencyId`
125+
* 因此,可能存在多个具有相同 `concurrencyId` 的模块。
126+
* 使用 `project.isBrowserEnabled()` 来区分并发性。
127127
*/
128128
readonly concurrencyId: number
129129
/**
130-
* Incremental number of the worker that ran this file. This number increases with each worker.
131-
* If file did not run yet, this will be 0.
130+
* å
131+
* 运行此文件的 worker 的递增编号。编号随每个 worker 进行递增
132+
* 如果文件尚未运行,此值将为 0
132133
*
133-
* **Warning**: Node.js tests and browser tests run in different pools and do not share `workerId`.
134-
* It is possible to have multiple modules with the same `workerId` because of that.
135-
* Use `project.isBrowserEnabled()` to distinguish the concurrency.
134+
* **警告**:Node.js 测试和浏览器测试在不同的池中运行,不共享 `workerId`
135+
* 因此,可能存在多个具有相同 `workerId` 的模块
136+
* 使用 `project.isBrowserEnabled()` 来区分并发性
136137
*/
137138
readonly workerId: number
138139
}
@@ -146,14 +147,14 @@ interface ImportDuration {
146147
totalTime: number
147148
}
148149
```
149-
<!-- TODO: translation -->
150+
150151
## logs <Version>5.0.0</Version> {#logs}
151152

152153
```ts
153154
function logs(): ReadonlyArray<UserConsoleLog>
154155
```
155156

156-
Console logs recorded on top level of the module during test collection.For example:
157+
测试收集期间在模块顶层记录的 console 日志。例如:
157158

158159
```ts
159160
console.log('included') // [!code highlight]

api/advanced/test-project.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function createSpecification(
179179
): TestSpecification
180180
```
181181

182-
创建一个 [测试规范](/api/advanced/test-specification),可用于 [`vitest.runTestSpecifications`](/api/advanced/vitest#runtestspecifications)。规范将测试文件限定到特定的 `project` 和测试 `locations`(可选)。测试 [位置](/api/advanced/test-case#location) 是源代码中定义测试的代码行。如果提供了位置,Vitest 将仅运行在这些行上定义的测试。请注意,如果定义了 [`testNamePattern`](/config/testnamepattern),则它也将被应用。
182+
创建一个 [TestSpecification](/api/advanced/test-specification),可用于 [`vitest.runTestSpecifications`](/api/advanced/vitest#runtestspecifications)。规范将测试文件限定到特定的 `project` 和测试 `locations`(可选)。测试 [位置](/api/advanced/test-case#location) 是源代码中定义测试的代码行。如果提供了位置,Vitest 将仅运行在这些行上定义的测试。请注意,如果定义了 [`testNamePattern`](/config/testnamepattern),则它也将被应用。
183183

184184
```ts
185185
import { resolve } from 'node:path/posix'

api/advanced/test-specification.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Vite 模块图中的模块 ID。通常,它是一个使用 POSIX 分隔符的
4545
测试模块将运行的 [`pool`](/config/pool)
4646

4747
::: danger
48-
在启用 [`typecheck.enabled`](/config/typecheck#typecheck-enabled) 配置的情况下,单个测试项目中可能存在多个运行池。这意味着可能出现多个测试规范共享相同 `moduleId` 但使用不同 `pool` 的情况。请注意,后续版本将仅支持单一运行池模式。
48+
在启用 [`typecheck.enabled`](/config/typecheck#typecheck-enabled) 配置的情况下,单个测试项目中可能存在多个运行池。这意味着可能出现多个 TestSpecification 共享相同 `moduleId` 但使用不同 `pool` 的情况。请注意,后续版本将仅支持单一运行池模式。
4949
:::
5050

5151
## testLines
@@ -81,7 +81,7 @@ describe('a group of tests', () => { // [!code error]
8181

8282
## testIds <Version>4.1.0</Version> {#testids}
8383

84-
当前测试规范中需要运行的任务 ID 集合。
84+
当前 TestSpecification 中需要运行的任务 ID 集合。
8585

8686
## testTagsFilter <Version>4.1.0</Version> {#testtagsfilter}
8787

api/advanced/test-suite.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ describe('the validation works correctly', { meta: { decorated: true } }, () =>
222222
:::tip
223223
如果元数据是在收集阶段(而非 `test` 函数内部)附加的,那么它将在 available 的 [`onTestModuleCollected`](./reporters#ontestmodulecollected) 中可用。
224224
:::
225-
<!-- TODO: translation -->
225+
226226
## logs <Version>5.0.0</Version> {#logs}
227227

228228
```ts
229229
function logs(): ReadonlyArray<UserConsoleLog>
230230
```
231231

232-
Console logs recorded during test collection of this suite. For example:
232+
此套件测试收集期间记录的 console 日志。例如:
233233

234234
```ts
235235
describe('suite', () => {
@@ -251,4 +251,4 @@ describe('suite', () => {
251251
function toTestSpecification(): TestSpecification
252252
```
253253

254-
返回一个新的 [测试规范](/api/advanced/test-specification),该规范可用于筛选或运行此特定测试套件。
254+
返回一个新的 [TestSpecification](/api/advanced/test-specification),该规范可用于筛选或运行此特定测试套件。

api/advanced/vitest.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ function globTestSpecifications(
140140
): Promise<TestSpecification[]>
141141
```
142142

143-
此方法通过收集所有项目中的每个测试来构造新的 [测试规范](/api/advanced/test-specification),使用 [`project.globTestFiles`](/api/advanced/test-project#globtestfiles)。它接受字符串过滤器以匹配测试文件 - 这些过滤器与 [CLI 支持的过滤器](/guide/filtering#cli) 相同。
143+
此方法通过收集所有项目中的每个测试来构造新的 [TestSpecification](/api/advanced/test-specification),使用 [`project.globTestFiles`](/api/advanced/test-project#globtestfiles)。它接受字符串过滤器以匹配测试文件 - 这些过滤器与 [CLI 支持的过滤器](/guide/filtering#cli) 相同。
144144

145-
此方法自动缓存所有测试规范。当我们下次调用 [`getModuleSpecifications`](#getmodulespecifications) 时,它将返回相同的规范,除非在此之前调用了 [`clearSpecificationsCache`](#clearspecificationscache)。
145+
此方法自动缓存所有 TestSpecification。当我们下次调用 [`getModuleSpecifications`](#getmodulespecifications) 时,它将返回相同的规范,除非在此之前调用了 [`clearSpecificationsCache`](#clearspecificationscache)。
146146

147147
::: warning
148-
Vitest 3 开始,如果 `poolMatchGlob` 有多个池或启用了 `typecheck`,则可能有多个具有相同模块 ID(文件路径)的测试规范。这种可能性将在 Vitest 4 中移除。
148+
Vitest 3 开始,如果 `poolMatchGlob` 有多个池或启用了 `typecheck`,则可能有多个具有相同模块 ID(文件路径)TestSpecification。这种可能性将在 Vitest 4 中移除。
149149
:::
150150

151151
```ts
@@ -162,7 +162,7 @@ function getRelevantTestSpecifications(
162162
): Promise<TestSpecification[]>
163163
```
164164

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

167167
::: warning
168168
此方法可能很慢,因为它需要过滤 `--changed` 参数。如果我们只需要测试文件列表,请不要使用它。
@@ -191,7 +191,7 @@ function collect(filters?: string[]): Promise<TestRunResult>
191191

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

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

196196
::: warning
197197
请注意,Vitest 不使用静态分析来收集测试。Vitest 将像运行常规测试一样在隔离环境中运行每个测试文件。
@@ -237,7 +237,7 @@ function standalone(): Promise<void>
237237
function getModuleSpecifications(moduleId: string): TestSpecification[]
238238
```
239239

240-
返回与模块 ID 相关的测试规范列表ID 应已解析为绝对文件路径。如果 ID 不匹配 `include``includeSource` 模式,则返回的数组将为空。
240+
返回与模块 ID 相关的 TestSpecification 列表ID 应已解析为绝对文件路径。如果 ID 不匹配 `include``includeSource` 模式,则返回的数组将为空。
241241

242242
此方法可以根据 `moduleId``pool` 返回已缓存的规范。但请注意,[`project.createSpecification`](/api/advanced/test-project#createspecification) 总是返回一个新实例,并且不会自动缓存。但是,当调用 [`runTestSpecifications`](#runtestspecifications) 时,规范会自动缓存。
243243

@@ -251,7 +251,7 @@ function getModuleSpecifications(moduleId: string): TestSpecification[]
251251
function clearSpecificationsCache(moduleId?: string): void
252252
```
253253

254-
当调用 [`globTestSpecifications`](#globtestspecifications) 或 [`runTestSpecifications`](#runtestspecifications) 时,Vitest 会自动缓存每个文件的测试规范。此方法会根据第一个参数清除给定文件的缓存或整个缓存。
254+
当调用 [`globTestSpecifications`](#globtestspecifications) 或 [`runTestSpecifications`](#runtestspecifications) 时,Vitest 会自动缓存每个文件的 TestSpecification。此方法会根据第一个参数清除给定文件的缓存或整个缓存。
255255

256256
## runTestSpecifications
257257

@@ -288,7 +288,7 @@ function runTestFiles(
288288
): Promise<TestRunResult>
289289
```
290290

291-
该功能会根据文件路径过滤器自动创建待运行的测试规范
291+
该功能会根据文件路径过滤器自动创建待运行的 TestSpecification
292292

293293
这与 [`start`](#start) 的不同之处在于:它不会创建覆盖率提供程序、不会触发 `onInit``onWatcherStart` 事件,且在无文件可运行时也不会抛出错误(此时函数将返回空数组且不会触发测试运行)。
294294

@@ -312,7 +312,7 @@ function collectTests(
312312

313313
执行测试文件而不运行测试回调。`collectTests` 返回未处理的错误和 [测试模块](/api/advanced/test-module) 数组。
314314

315-
此方法与 [`collect`](#collect) 完全相同,但我们需要自己提供测试规范
315+
此方法与 [`collect`](#collect) 完全相同,但我们需要自己提供 TestSpecification
316316

317317
::: warning
318318
请注意,Vitest 不使用静态分析来收集测试。Vitest 将像运行常规测试一样在隔离环境中运行每个测试文件。

api/assert.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# assert
22

33
Vitest 从 [`chai`](https://www.chaijs.com/api/assert/) 重新导出了 `assert` 方法,用于验证不变量。
4-
<!-- TODO: translation -->
5-
::: warning In-Source Testing {#in-source-testing}
6-
When using [assertion functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) such as `assert` from `import.meta.vitest` in [in-source tests](/guide/in-source), TypeScript reports error `TS2775` because they must be called via an explicitly annotated name. Annotate the variable with `Chai.Assert` or call it directly:
4+
5+
::: warning 源码内联测试 {#in-source-testing}
6+
[源码内联测试](/guide/in-source) 中使用来自 `import.meta.vitest`[断言函数](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions)(例如 `assert`)时,TypeScript 会报告 `TS2775` 错误,因为这类函数必须通过带有显式类型注解的名称来调用。请为该变量标注 Chai.Assert,或直接调用它:
77

88
::: code-group
9-
```ts [Annotated variable]
9+
```ts [类型注释变量]
1010
if (import.meta.vitest) {
1111
const { test, assert } = import.meta.vitest // [!code --]
1212
const { test } = import.meta.vitest // [!code ++]
@@ -17,7 +17,7 @@ if (import.meta.vitest) {
1717
})
1818
}
1919
```
20-
```ts [Direct call]
20+
```ts [直接调用]
2121
if (import.meta.vitest) {
2222
const { test, assert } = import.meta.vitest // [!code --]
2323
const { test } = import.meta.vitest // [!code ++]

0 commit comments

Comments
 (0)