diff --git a/api/advanced/reporters.md b/api/advanced/reporters.md index 12a96518..64a8def0 100644 --- a/api/advanced/reporters.md +++ b/api/advanced/reporters.md @@ -6,26 +6,30 @@ Vitest 拥有自己的测试运行生命周期。这些生命周期通过报告器的方法来表示: -- [报告器 {#reporters}](#报告器-reporters) - - [onInit](#oninit) - - [onBrowserInit {#onbrowserinit}](#onbrowserinit-onbrowserinit) - - [onTestRunStart](#ontestrunstart) - - [onTestRunEnd](#ontestrunend) - - [onCoverage](#oncoverage) - - [onTestModuleQueued](#ontestmodulequeued) - - [onTestModuleCollected](#ontestmodulecollected) - - [onTestModuleStart](#ontestmodulestart) - - [onTestModuleEnd](#ontestmoduleend) - - [onHookStart](#onhookstart) - - [onHookEnd](#onhookend) - - [onTestSuiteReady](#ontestsuiteready) - - [onTestSuiteResult](#ontestsuiteresult) - - [onTestCaseReady](#ontestcaseready) - - [onTestCaseResult](#ontestcaseresult) - - [onTestAnnotate 3.2.0 {#ontestannotate}](#ontestannotate-320-ontestannotate) - - [onTestCaseArtifactRecord 4.0.11 {#ontestcaseartifactrecord}](#ontestcaseartifactrecord-4011-ontestcaseartifactrecord) - -除非被跳过,否则单个模块中的测试和 reporters 将按顺序报告。所有跳过的测试将在 reporters /模块的末尾报告。 +- [`onInit`](#oninit) +- [`onTestRunStart`](#ontestrunstart) + - [`onTestModuleQueued`](#ontestmodulequeued) + - [`onTestModuleCollected`](#ontestmodulecollected) + - [`onTestModuleStart`](#ontestmodulestart) + - [`onTestSuiteReady`](#ontestsuiteready) + - [`onHookStart(beforeAll)`](#onhookstart) + - [`onHookEnd(beforeAll)`](#onhookend) + - [`onTestCaseReady`](#ontestcaseready) + - [`onTestCaseAnnotate`](#ontestcaseannotate) 3.2.0 + - [`onTestCaseArtifactRecord`](#ontestcaseartifactrecord) 4.0.11 + - [`onHookStart(beforeEach)`](#onhookstart) + - [`onHookEnd(beforeEach)`](#onhookend) + - [`onHookStart(afterEach)`](#onhookstart) + - [`onHookEnd(afterEach)`](#onhookend) + - [`onTestCaseResult`](#ontestcaseresult) + - [`onHookStart(afterAll)`](#onhookstart) + - [`onHookEnd(afterAll)`](#onhookend) + - [`onTestSuiteResult`](#ontestsuiteresult) + - [`onTestModuleEnd`](#ontestmoduleend) + - [`onCoverage`](#oncoverage) +- [`onTestRunEnd`](#ontestrunend) + +除非被跳过,否则单个模块中的测试和 reporters 将按顺序报告。所有跳过的测试将在 reporters 测试套件或模块的末尾报告。 请注意,由于测试模块可以并行运行,Vitest 将并行报告它们。 @@ -309,16 +313,16 @@ function onTestCaseResult(testCase: TestCase): Awaitable 此时,[`testCase.result()`](/api/advanced/test-case#result) 已不再是挂起状态。 -## onTestAnnotate 3.2.0 {#ontestannotate} +## onTestCaseAnnotate 3.2.0 {#ontestcaseannotate} ```ts -function onTestAnnotate( +function onTestCaseAnnotate( testCase: TestCase, annotation: TestAnnotation, ): Awaitable ``` -onTestAnnotate 是与 [`context.annotate`](/guide/test-context#annotate) 方法配套使用的钩子。当你在测试中调用 annotate 后, Vitest 会将注解内容序列化,并将其发送到主线程,从而让报告器可以处理这些附加信息。 +`onTestCaseAnnotate` 是与 [`context.annotate`](/guide/test-context#annotate) 方法配套使用的钩子。当你在测试中调用 annotate 后, Vitest 会将注解内容序列化,并将其发送到主线程,从而让报告器可以处理这些附加信息。 如果在注解中指定了文件路径, Vitest 会将附件保存到一个独立的目录(该目录通过 [`attachmentsDir`](/config/#attachmentsdir) 配置),并自动更新 path 属性,使其指向存储后的文件位置。 diff --git a/api/advanced/test-module.md b/api/advanced/test-module.md index 5d833189..a451c222 100644 --- a/api/advanced/test-module.md +++ b/api/advanced/test-module.md @@ -121,10 +121,14 @@ interface ImportDuration { } ``` -## viteEnvironment 4.0.15 {#viteenvironment} +## viteEnvironment 4.1.0 {#viteenvironment} This is a Vite's [`DevEnvironment`](https://vite.dev/guide/api-environment) that transforms all files inside of the test module. +::: details History +- `v4.0.15`: added as experimental +::: + ## toTestSpecification 4.1.0 {#totestspecification} ```ts diff --git a/api/advanced/test-specification.md b/api/advanced/test-specification.md index 719a5f03..bd64c455 100644 --- a/api/advanced/test-specification.md +++ b/api/advanced/test-specification.md @@ -40,7 +40,7 @@ Vite 模块图中的模块 ID。通常,它是一个使用 POSIX 分隔符的 与规范相关联的 [`TestModule`](/api/advanced/test-module) 实例。如果测试还未加入队列,则将是 `undefined`。 -## pool experimental {#pool} +## pool {#pool} 测试模块将运行的 [`pool`](/config/#pool)。 diff --git a/api/advanced/vitest.md b/api/advanced/vitest.md index b4d02eee..5daeb43c 100644 --- a/api/advanced/vitest.md +++ b/api/advanced/vitest.md @@ -480,9 +480,8 @@ function onCancel(fn: (reason: CancelReason) => Awaitable): () => void 注册一个处理程序,当测试运行被 [`vitest.cancelCurrentRun`](#cancelcurrentrun) 取消时调用。 -::: warning 实验性 -自 4.0.10 起,`onCancel` 会返回一个用于移除监听器的清理函数。 -::: + +Since 4.0.10, `onCancel` experimentally returns a teardown function that will remove the listener. Since 4.1.0 this behaviour is considered stable. ## onClose diff --git a/api/browser/context.md b/api/browser/context.md index 2daa222d..65e8e2d7 100644 --- a/api/browser/context.md +++ b/api/browser/context.md @@ -218,7 +218,6 @@ export const utils: { /** * Configures default options of `prettyDOM` and `debug` functions. * This will also affect `vitest-browser-{framework}` package. - * @experimental */ configurePrettyDOM(options: StringifyOptions): void /** diff --git a/guide/advanced/tests.md b/guide/advanced/tests.md index e7178f59..1f6e2453 100644 --- a/guide/advanced/tests.md +++ b/guide/advanced/tests.md @@ -29,10 +29,6 @@ for (const testModule of testModules) { } ``` -::: tip -[`TestModule`](/api/advanced/test-module), [`TestSuite`](/api/advanced/test-suite) 和 [`TestCase`](/api/advanced/test-case) API 从 Vitest 2.1 开始不再是实验性的,并且遵循 SemVer。 -::: - ## `createVitest` 创建一个 [Vitest](/api/advanced/vitest) 实例而不运行测试。 diff --git a/guide/environment.md b/guide/environment.md index 6b502486..b7e3eb23 100644 --- a/guide/environment.md +++ b/guide/environment.md @@ -49,7 +49,7 @@ import type { Environment } from 'vitest/runtime' export default { name: 'custom', viteEnvironment: 'ssr', - // 可选 - 仅在支持 "experimental-vm" 的情况下使用 + // 可选 - 仅在支持 "vmForks" 或 "vmThreads" 线程池时需要设置 async setupVM() { const vm = await import('node:vm') const context = vm.createContext() diff --git a/guide/snapshot.md b/guide/snapshot.md index 23884ab0..99db52a4 100644 --- a/guide/snapshot.md +++ b/guide/snapshot.md @@ -98,7 +98,7 @@ it('render basic', async () => { ## 图像快照 {#visual-snapshots} -对于 UI 组件和页面的视觉回归测试,Vitest 通过[浏览器模式](/guide/browser/)提供了内置支持,使用 [`toMatchScreenshot()`](/api/browser/assertions#tomatchscreenshot-experimental) 断言: +对于 UI 组件和页面的视觉回归测试,Vitest 通过 [浏览器模式](/guide/browser/) 提供了内置支持,使用 [`toMatchScreenshot()`](/api/browser/assertions#tomatchscreenshot) 断言: ```ts import { expect, test } from 'vitest' @@ -110,7 +110,7 @@ test('button looks correct', async () => { }) ``` -它会捕获屏幕截图并与参考图像进行比较,以检测意外的视觉变化。在[视觉回归测试指南](/guide/browser/visual-regression-testing)中了解更多内容。 +它会捕获屏幕截图并与参考图像进行比较,以检测意外的视觉变化。在 [视觉回归测试指南](/guide/browser/visual-regression-testing)中了解更多内容。 ## 自定义序列化程序 {#custom-serializer}