|
6 | 6 |
|
7 | 7 | Vitest 拥有自己的测试运行生命周期。这些生命周期通过报告器的方法来表示: |
8 | 8 |
|
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) |
31 | 27 |
|
32 | 28 | 除非被跳过,否则单个模块中的测试和 reporters 将按顺序报告。所有跳过的测试将在 reporters 测试套件或模块的末尾报告。 |
33 | 29 |
|
@@ -55,7 +51,7 @@ function onInit(vitest: Vitest): Awaitable<void> |
55 | 51 | 当 [Vitest](/api/advanced/vitest) 初始化或启动时,但在测试被过滤之前,会调用此方法。 |
56 | 52 |
|
57 | 53 | ::: 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 将始终按正确的顺序运行方法。 |
59 | 55 | ::: |
60 | 56 |
|
61 | 57 | 请注意,我们还可以通过 [`project`](/api/advanced/test-project) 属性从测试用例、套件和测试模块中访问 `vitest` 实例,但在此方法中存储对 `vitest` 的引用也可能有用。 |
|
0 commit comments