Skip to content

Commit 759296d

Browse files
authored
docs(cn): complement the missing translation (#958)
* docs(cn): complement the missing translation * docs(cn): update /guide/ * docs(cn): update /guide/ * docs(cn): fix typo * docs(cn): update /config/ * docs(cn): update /api/
1 parent e79cdf6 commit 759296d

60 files changed

Lines changed: 347 additions & 474 deletions

Some content is hidden

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

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<!-- 感谢你的贡献! -->
22

3-
### 在提交PR之前,请确保您执行以下操作:
3+
### 在提交PR之前,请确保你执行以下操作:
44
- [ ] 曾阅读过[翻译须知](https://github.com/vitest-dev/docs-cn/issues/391)
55
- [ ] 检查是否已经有PR以同样的方式解决问题,以避免创建重复。
66
- [ ] 在此PR中描述正在解决的问题,或引用它解决的问题(例如:`fixes #123`)。
77

88
---
99

1010
### 描述
11-
<!-- 请在此处插入您的描述,并提供有关此PR正在解决的 “内容” 的特别信息 -->
11+
<!-- 请在此处插入你的描述,并提供有关此PR正在解决的 “内容” 的特别信息 -->
1212

1313
### 附加上下文
1414
<!-- 例如,你有什么想让代码审核的人重点关注的内容。 -->

api/advanced/plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function injectTestProjects(
9393
```ts
9494
// 为单个项目注入自定义别名
9595
const newProjects = await injectTestProjects({
96-
// 您可以通过引用 `extends` 来继承当前项目配置
96+
// 你可以通过引用 `extends` 来继承当前项目配置
9797
// 注意,不能使用已经存在的项目名称,
9898
// 所以定义自定义名称是一个好实践。
9999
extends: project.vite.config.configFile,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!-- 因经常误被错误格式化,估另抽单个文件处理-->
2+
3+
- [`onInit`](#oninit)
4+
- [`onTestRunStart`](#ontestrunstart)
5+
- [`onTestModuleQueued`](#ontestmodulequeued)
6+
- [`onTestModuleCollected`](#ontestmodulecollected)
7+
- [`onTestModuleStart`](#ontestmodulestart)
8+
- [`onTestSuiteReady`](#ontestsuiteready)
9+
- [`onHookStart(beforeAll)`](#onhookstart)
10+
- [`onHookEnd(beforeAll)`](#onhookend)
11+
- [`onTestCaseReady`](#ontestcaseready)
12+
- [`onTestCaseAnnotate`](#ontestcaseannotate) <Version>3.2.0</Version>
13+
- [`onTestCaseArtifactRecord`](#ontestcaseartifactrecord) <Version type="experimental">4.0.11</Version>
14+
- [`onHookStart(beforeEach)`](#onhookstart)
15+
- [`onHookEnd(beforeEach)`](#onhookend)
16+
- [`onHookStart(afterEach)`](#onhookstart)
17+
- [`onHookEnd(afterEach)`](#onhookend)
18+
- [`onTestCaseResult`](#ontestcaseresult)
19+
- [`onHookStart(afterAll)`](#onhookstart)
20+
- [`onHookEnd(afterAll)`](#onhookend)
21+
- [`onTestSuiteResult`](#ontestsuiteresult)
22+
- [`onTestModuleEnd`](#ontestmoduleend)
23+
- [`onCoverage`](#oncoverage)
24+
- [`onTestRunEnd`](#ontestrunend)

api/advanced/reporters.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,7 @@
66

77
Vitest 拥有自己的测试运行生命周期。这些生命周期通过报告器的方法来表示:
88

9-
- [报告器 {#reporters}](#报告器-reporters)
10-
- [onInit](#oninit)
11-
- [onBrowserInit {#onbrowserinit}](#onbrowserinit-onbrowserinit)
12-
- [onTestRunStart](#ontestrunstart)
13-
- [onTestRunEnd](#ontestrunend)
14-
- [onCoverage](#oncoverage)
15-
- [onTestModuleQueued](#ontestmodulequeued)
16-
- [onTestModuleCollected](#ontestmodulecollected)
17-
- [onTestModuleStart](#ontestmodulestart)
18-
- [onTestModuleEnd](#ontestmoduleend)
19-
- [onHookStart](#onhookstart)
20-
- [onHookEnd](#onhookend)
21-
- [onTestSuiteReady](#ontestsuiteready)
22-
- [onTestSuiteResult](#ontestsuiteresult)
23-
- [onTestCaseReady](#ontestcaseready)
24-
- [onTestCaseResult](#ontestcaseresult)
25-
- [onTestCaseAnnotate 3.2.0 {#ontestcaseannotate}](#ontestcaseannotate-320-ontestcaseannotate)
26-
- [onTestCaseArtifactRecord 4.0.11 {#ontestcaseartifactrecord}](#ontestcaseartifactrecord-4011-ontestcaseartifactrecord)
9+
<!--@include: ./reporters-life-cycle.md-->
2710

2811
除非被跳过,否则单个模块中的测试和 reporters 将按顺序报告。所有跳过的测试将在 reporters 测试套件或模块的末尾报告。
2912

api/advanced/runner.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export interface TaskResult {
275275

276276
## 你的任务函数 {#your-task-function}
277277

278-
Vitest 提供了 `createTaskCollector` 工具来创建您自己的 `test` 方法。它的行为与测试相同,但在收集期间会调用自定义方法。
278+
Vitest 提供了 `createTaskCollector` 工具来创建你自己的 `test` 方法。它的行为与测试相同,但在收集期间会调用自定义方法。
279279

280280
任务是套件的一部分对象。它会通过 `suite.task` 方法自动添加到当前套件中:
281281

api/advanced/test-case.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# TestCase
22

3-
`TestCase` 类表示单个测试。此类仅在主线程中可用。如果您正在处理运行时任务,请参阅 [“运行器 API”](/api/advanced/runner#tasks)
3+
`TestCase` 类表示单个测试。此类仅在主线程中可用。如果你正在处理运行时任务,请参阅 [“运行器 API”](/api/advanced/runner#tasks)
44

5-
`TestCase` 实例始终有一个值为 `test``type` 属性。您可以使用它来区分不同的任务类型
5+
`TestCase` 实例始终有一个值为 `test``type` 属性。你可以使用它来区分不同的任务类型
66

77
```ts
88
if (task.type === 'test') {

api/advanced/test-specification.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ Vite 模块图中的模块 ID。通常,它是一个使用 POSIX 分隔符的
4444

4545
测试模块将运行的 [`pool`](/config/pool)
4646

47-
<!-- TODO: translation -->
48-
4947
::: danger
50-
It's possible to have multiple pools in a single test project with [`typecheck.enabled`](/config/typecheck#typecheck-enabled). This means it's possible to have several specifications with the same `moduleId` but different `pool`. In later versions, the project will only support a single pool.
48+
在启用 [`typecheck.enabled`](/config/typecheck#typecheck-enabled) 配置的情况下,单个测试项目中可能存在多个运行池。这意味着可能出现多个测试规范共享相同 `moduleId` 但使用不同 `pool` 的情况。请注意,后续版本将仅支持单一运行池模式。
5149
:::
5250

5351
## testLines
@@ -79,15 +77,15 @@ describe('a group of tests', () => { // [!code error]
7977

8078
## testNamePattern <Version>4.1.0</Version> {#testnamepattern}
8179

82-
A regexp that matches the name of the test in this module. This value will override the global [`testNamePattern`](/config/testnamepattern) option if it's set.
80+
用于匹配当前模块中测试名称的正则表达式。如果已设置,该值将覆盖全局 [`testNamePattern`](/config/testnamepattern) 配置。
8381

8482
## testIds <Version>4.1.0</Version> {#testids}
8583

86-
The ids of tasks inside of this specification to run.
84+
当前测试规范中需要运行的任务 ID 集合。
8785

8886
## testTagsFilter <Version>4.1.0</Version> {#testtagsfilter}
8987

90-
The [tags filter](/guide/test-tags#syntax) that a test must pass in order to be included in the run. Multiple filters are treated as `AND`.
88+
测试必须通过的 [标签过滤器](/guide/test-tags#syntax) 才能被纳入运行范围。多个过滤器将按 `AND` 逻辑处理。
9189

9290
## toJSON
9391

api/advanced/vitest.md

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ function rerunTestSpecifications(
304304

305305
此方法发出 `reporter.onWatcherRerun``onTestsRerun` 事件,然后使用 [`runTestSpecifications`](#runtestspecifications) 运行测试。如果主进程中没有错误,它将发出 `reporter.onWatcherStart` 事件。
306306

307-
<!-- TODO: translation -->
308-
309307
## runTestFiles <Version>4.1.0</Version> {#runtestfiles}
310308

311309
```ts
@@ -315,11 +313,11 @@ function runTestFiles(
315313
): Promise<TestRunResult>
316314
```
317315

318-
This automatically creates specifications to run based on filepaths filters.
316+
该功能会根据文件路径过滤器自动创建待运行的测试规范。
319317

320-
This is different from [`start`](#start) because it does not create a coverage provider, trigger `onInit` and `onWatcherStart` events, or throw an error if there are no files to run (in this case, the function will return empty arrays without triggering a test run).
318+
这与 [`start`](#start) 的不同之处在于:它不会创建覆盖率提供程序、不会触发 `onInit` `onWatcherStart` 事件,且在无文件可运行时也不会抛出错误(此时函数将返回空数组且不会触发测试运行)。
321319

322-
This function accepts the same filters as [`start`](#start) and the CLI.
320+
此函数接受的过滤器参数与 [`start`](#start) 及命令行接口完全一致。
323321

324322
## updateSnapshot
325323

@@ -482,8 +480,7 @@ function onCancel(fn: (reason: CancelReason) => Awaitable<void>): () => void
482480

483481
注册一个处理程序,当测试运行被 [`vitest.cancelCurrentRun`](#cancelcurrentrun) 取消时调用。
484482

485-
<!-- TODO: translation -->
486-
Since 4.0.10, `onCancel` experimentally returns a teardown function that will remove the listener. Since 4.1.0 this behaviour is considered stable.
483+
自 4.0.10 起,`onCancel` 实验性地返回一个清理函数,该函数会移除监听器。自 4.1.0 起,此行为被视为稳定。
487484

488485
## onClose
489486

@@ -696,26 +693,26 @@ export interface SourceModuleDiagnostic {
696693
::: warning
697694
[浏览器模式](/guide/browser/) 暂不支持。
698695
:::
699-
<!-- TODO: translation -->
696+
700697
## createReport <Version>5.0.0</Version> {#createreport}
701698

702699
```ts
703700
function createReport(scope: string): Report
704701
```
705702

706-
Creates a report that is limited to the given scope. `Report` follows Vitest's rules around [Storing artifacts on file system](/guide/advanced/reporters.html#storing-artifacts-on-file-system).
703+
创建一个仅限于给定作用域的报告。`Report` 遵循 Vitest 关于 [在文件系统中存储工件](/guide/advanced/reporters.html#storing-artifacts-on-file-system) 的规则。
707704

708-
`Report` provides collection of utilities for writing test results, temporary files and other artifacts on the file system. It's especially intended for third party integrations like custom reporters.
705+
`Report` 提供了一系列用于在文件系统中写入测试结果、临时文件和其他产物的工具函数。它特别适用于第三方集成,例如自定义报告器。
709706

710-
All operations of `Report` are limited to given `scope`. A single report cannot interfere with other reports. Internally Vitest creates `.vitest` directory where each `scope` creates their own directory. This convention of `.vitest` directory reduces the amount of entries end-users need to specify in their `.gitignore`.
707+
`Report` 的所有操作都限制在给定的 `scope` 内。单个报告不会干扰其他报告。Vitest 内部会创建一个 `.vitest` 目录,每个 `scope` 在其中创建自己的子目录。这种 `.vitest` 目录的约定减少了最终用户需要在 `.gitignore` 中指定的条目数量。
711708

712709
```ts
713710
import type { Report } from 'vitest/node'
714711
715712
const scope = 'example-yaml-reporter'
716713
717-
// Automatically creates `<project-root>/.vitest/example-yaml-reporter/`
718-
// directory if it does not exist already
714+
// 自动创建 `<project-root>/.vitest/example-yaml-reporter/`
715+
// 如果目录不存在
719716
const report: Report = vitest.createReport(scope)
720717
```
721718

@@ -730,7 +727,7 @@ The root directory for this scope.
730727
```ts
731728
const report = vitest.createReport('my-json-reporter')
732729
733-
// Is <project-root>/.vitest/my-json-reporter
730+
// <project-root>/.vitest/my-json-reporter
734731
const root = report.root
735732
```
736733

@@ -740,12 +737,12 @@ const root = report.root
740737
function clean(): Promise<void>
741738
```
742739

743-
Clean up the report directory for this scope.
740+
清理此作用域的报告目录。
744741

745742
```ts
746743
const report = vitest.createReport('my-json-reporter')
747744
748-
// Removes everything inside <project-root>/.vitest/my-json-reporter/
745+
// 删除 <project-root>/.vitest/my-json-reporter/ 内的所有内容
749746
await report.clean()
750747
```
751748

@@ -759,12 +756,12 @@ function writeFile(
759756
): Promise<void>
760757
```
761758

762-
Write a file to the report directory for this scope. By default the file will be written with UTF-8 encoding. The filename is relative to the scope directory.
759+
向此作用域的报告目录写入文件。默认情况下,文件将以 UTF-8 编码写入。文件名是相对于作用域目录的。
763760

764761
```ts
765762
const report = vitest.createReport('my-json-reporter')
766763
767-
// Writes file to .vitest/my-json-reporter/test-report.json
764+
// 将文件写入 .vitest/my-json-reporter/test-report.json
768765
await report.writeFile('test-report.json', JSON.stringify(results))
769766
```
770767

@@ -774,12 +771,12 @@ await report.writeFile('test-report.json', JSON.stringify(results))
774771
function readFile(filename: string, encoding?: BufferEncoding): Promise<string>
775772
```
776773

777-
Read a file from the report directory for this scope.
774+
从此作用域的报告目录读取文件。
778775

779776
```ts
780777
const report = vitest.createReport('my-json-reporter')
781778
782-
// Reads file from .vitest/my-json-reporter/test-report.json
779+
// .vitest/my-json-reporter/test-report.json 读取文件
783780
const content: string = await report.readFile('test-report.json')
784781
```
785782

@@ -789,12 +786,12 @@ const content: string = await report.readFile('test-report.json')
789786
function readdir(): Promise<string[]>
790787
```
791788

792-
Read contents of the report directory for this scope.
789+
读取此作用域报告目录的内容。
793790

794791
```ts
795792
const report = vitest.createReport('my-json-reporter')
796793
797-
// Reads contents from .vitest/my-json-reporter
794+
// from .vitest/my-json-reporter 读取内容
798795
const filenames: string[] = await report.readdir()
799796
```
800797

@@ -805,11 +802,11 @@ const filenames: string[] = await report.readdir()
805802
function delete(filename: string): Promise<void>
806803
```
807804

808-
Delete a file from the report directory for this scope.
805+
从此作用域的报告目录删除文件。
809806

810807
```ts
811808
const report = vitest.createReport('my-json-reporter')
812809
813-
// Deletes file from .vitest/my-json-reporter/test-report.json
810+
// .vitest/my-json-reporter/test-report.json 删除文件
814811
await report.delete('test-report.json')
815812
```

api/browser/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ declare module 'vitest/browser' {
131131
Vitest 在命令上下文中公开了几个`playwright`特定属性。
132132

133133
- `page`引用包含测试 iframe 的完整页面。这是协调器 HTML,为避免出现问题,最好不要碰它。
134-
- `frame` 是一个异步方法,用于解析测试器 [`Frame`](https://playwright.dev/docs/api/class-frame)。它的 API 与 `page` 类似,但不支持某些方法。如果您需要查询元素,应优先使用 `context.iframe` 代替,因为它更稳定、更快速。
134+
- `frame` 是一个异步方法,用于解析测试器 [`Frame`](https://playwright.dev/docs/api/class-frame)。它的 API 与 `page` 类似,但不支持某些方法。如果你需要查询元素,应优先使用 `context.iframe` 代替,因为它更稳定、更快速。
135135
- `iframe` 是一个 [`FrameLocator`](https://playwright.dev/docs/api/class-framelocator),用于查询页面上的其他元素。
136136
- `context` 是指唯一的[BrowserContext](https://playwright.dev/docs/api/class-browsercontext)
137137

api/browser/context.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export const commands: BrowserCommands
5959
页面导出提供了与当前页面交互的实用程序。
6060
6161
::: warning
62-
虽然它从 Playwright 的 `page` 中获取了一些实用程序,但它与 Playwright 的 `page` 并不是同一个对象。由于浏览器上下文是在浏览器中评估的,您的测试无法访问 Playwright 的 `page`,因为它是在服务器上运行的。
62+
虽然它从 Playwright 的 `page` 中获取了一些实用程序,但它与 Playwright 的 `page` 并不是同一个对象。由于浏览器上下文是在浏览器中评估的,你的测试无法访问 Playwright 的 `page`,因为它是在服务器上运行的。
6363
:::
6464
65-
使用 [Commands API](/api/browser/commands) 如果您需要访问 Playwright 的 `page` 对象。
65+
使用 [Commands API](/api/browser/commands) 如果你需要访问 Playwright 的 `page` 对象。
6666
<!-- TODO: translation -->
6767
```ts
6868
export const page: {

0 commit comments

Comments
 (0)