Skip to content

Commit d317bfd

Browse files
authored
Merge pull request #946 from vitest-dev/sync-fca844f9-1
docs(en): merge docs-cn/sync-docs into docs-cn/dev @ fca844f
2 parents f3af0aa + 82d89f0 commit d317bfd

3 files changed

Lines changed: 26 additions & 28 deletions

File tree

api/advanced/reporters.md

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,24 @@
66

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

9-
- [`onInit`](#oninit)
10-
- [`onTestRunStart`](#ontestrunstart)
11-
- [`onTestModuleQueued`](#ontestmodulequeued)
12-
- [`onTestModuleCollected`](#ontestmodulecollected)
13-
- [`onTestModuleStart`](#ontestmodulestart)
14-
- [`onTestSuiteReady`](#ontestsuiteready)
15-
- [`onHookStart(beforeAll)`](#onhookstart)
16-
- [`onHookEnd(beforeAll)`](#onhookend)
17-
- [`onTestCaseReady`](#ontestcaseready)
18-
- [`onTestCaseAnnotate`](#ontestcaseannotate) <Version>3.2.0</Version>
19-
- [`onTestCaseArtifactRecord`](#ontestcaseartifactrecord) <Version type="experimental">4.0.11</Version>
20-
- [`onHookStart(beforeEach)`](#onhookstart)
21-
- [`onHookEnd(beforeEach)`](#onhookend)
22-
- [`onHookStart(afterEach)`](#onhookstart)
23-
- [`onHookEnd(afterEach)`](#onhookend)
24-
- [`onTestCaseResult`](#ontestcaseresult)
25-
- [`onHookStart(afterAll)`](#onhookstart)
26-
- [`onHookEnd(afterAll)`](#onhookend)
27-
- [`onTestSuiteResult`](#ontestsuiteresult)
28-
- [`onTestModuleEnd`](#ontestmoduleend)
29-
- [`onCoverage`](#oncoverage)
30-
- [`onTestRunEnd`](#ontestrunend)
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)
3127

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

@@ -55,7 +51,7 @@ function onInit(vitest: Vitest): Awaitable<void>
5551
当 [Vitest](/api/advanced/vitest) 初始化或启动时,但在测试被过滤之前,会调用此方法。
5652

5753
::: info
58-
在内部,这个方法在 [`vitest.start`](/api/advanced/vitest#start)、[`vitest.init`](/api/advanced/vitest#init) 或 [`vitest.mergeReports`](/api/advanced/vitest#mergereports) 中调用。例如,如果我们使用 API,请确保根据我们的需要调用其中一个,然后再调用 [`vitest.runTestSpecifications`](/api/advanced/vitest#runtestspecifications)。内置的 CLI 将始终按正确的顺序运行方法。
54+
在内部,这个方法在 [`vitest.start`](/api/advanced/vitest#start)、[`vitest.standalone`](/api/advanced/vitest#standalone) 或 [`vitest.mergeReports`](/api/advanced/vitest#mergereports) 中调用。例如,如果我们使用 API,请确保根据我们的需要调用其中一个,然后再调用 [`vitest.runTestSpecifications`](/api/advanced/vitest#runtestspecifications)。内置的 CLI 将始终按正确的顺序运行方法。
5955
:::
6056

6157
请注意,我们还可以通过 [`project`](/api/advanced/test-project) 属性从测试用例、套件和测试模块中访问 `vitest` 实例,但在此方法中存储对 `vitest` 的引用也可能有用。

api/advanced/vitest.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,19 @@ function start(filters?: string[]): Promise<TestRunResult>
233233
初始化报告器、覆盖率提供者并运行测试。此方法接受字符串过滤器以匹配测试文件 - 这些过滤器与 [CLI 支持的过滤器](/guide/filtering#cli) 相同。
234234

235235
::: warning
236-
如果还调用了 [`vitest.init()`](#init),则不应调用此方法。如果我们需要在 Vitest 初始化后运行测试,请使用 [`runTestSpecifications`](#runtestspecifications) 或 [`rerunTestSpecifications`](#reruntestspecifications)。
236+
如果还调用了 [`vitest.standalone()`](#standalone),则不应调用此方法。如果我们需要在 Vitest 初始化后运行测试,请使用 [`runTestSpecifications`](#runtestspecifications) 或 [`rerunTestSpecifications`](#reruntestspecifications)。
237237
:::
238238

239239
如果未设置 `config.mergeReports``config.standalone`,则此方法由 [`startVitest`](/guide/advanced/tests) 自动调用。
240240

241-
## init
241+
## standalone <Version type="experimental">4.1.1</Version> {#standalone}
242242

243243
```ts
244-
function init(): Promise<void>
244+
function standalone(): Promise<void>
245245
```
246246

247+
- **别名:**: `init` <Deprecated />
248+
247249
初始化报告器和覆盖率提供者。此方法不运行任何测试。如果提供了 `--watch` 标志,Vitest 仍将运行更改的测试,即使未调用此方法。
248250

249251
在内部,仅当启用了 [`--standalone`](/guide/cli#standalone) 标志时才会调用此方法。
@@ -548,7 +550,7 @@ function waitForTestRunEnd(): Promise<void>
548550
function createCoverageProvider(): Promise<CoverageProvider | null>
549551
```
550552

551-
当配置中启用了 `coverage` 时,创建覆盖率提供器。若使用 [`start`](#start) 或 [`init`](#init) 方法启动测试,这一步会自动完成。
553+
当配置中启用了 `coverage` 时,创建覆盖率提供器。若使用 [`start`](#start) 或 [`standalone`](#standalone) 方法启动测试,这一步会自动完成。
552554

553555
::: warning
554556
若未将 [`coverage.clean`](/config/coverage#coverage-clean) 显式设为 false ,此方法还会清空之前的所有报告。

guide/cli-generated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ watch 模式下重新运行测试时清除终端屏幕(默认值:`true`)
853853

854854
- **命令行终端:** `--standalone`
855855

856-
单独启动 Vitest,且不运行任何测试。仅在文件变更时才运行测试。如果通过命令行参数过滤文件,此选项将被忽略。(默认值:`false`
856+
单独启动 Vitest,且不运行任何测试。仅在文件变更时才运行测试。若启用浏览器模式,UI 界面将自动打开。如果通过命令行参数过滤文件,此选项将被忽略。(默认值:`false`
857857

858858
### listTags
859859

0 commit comments

Comments
 (0)