diff --git a/advanced/api/test-case.md b/advanced/api/test-case.md index 30dba0d5..83fee639 100644 --- a/advanced/api/test-case.md +++ b/advanced/api/test-case.md @@ -126,7 +126,11 @@ function ok(): boolean function meta(): TaskMeta ``` +<<<<<<< HEAD 在测试执行期间附加到测试的自定义[元数据](/advanced/metadata)。在测试运行期间,可以通过为 `ctx.task.meta` 对象分配一个属性来附加元数据: +======= +Custom [metadata](/advanced/metadata) that was attached to the test during its execution. The meta can be attached by assigning a property to the `ctx.task.meta` object during a test run: +>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3 ```ts {3,6} import { test } from 'vitest' diff --git a/advanced/api/test-module.md b/advanced/api/test-module.md index ac7a5111..3daa533f 100644 --- a/advanced/api/test-module.md +++ b/advanced/api/test-module.md @@ -59,6 +59,33 @@ describe('the validation works correctly', (task) => { 如果元数据是在收集过程中附加的(在 `test` 函数之外),那么它将在自定义报告器中的['onTestModuleCollectd'](./reporters#onTestModuleCollected)挂钩中可用。 ::: +## meta 3.1.0 {#meta} + +```ts +function meta(): TaskMeta +``` + +Custom [metadata](/advanced/metadata) that was attached to the module during its execution or collection. The meta can be attached by assigning a property to the `task.meta` object during a test run: + +```ts {5,10} +import { test } from 'vitest' + +describe('the validation works correctly', (task) => { + // assign "decorated" during collection + task.file.meta.decorated = false + + test('some test', ({ task }) => { + // assign "decorated" during test run, it will be available + // only in onTestCaseReady hook + task.file.meta.decorated = false + }) +}) +``` + +:::tip +If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter. +::: + ## diagnostic ```ts diff --git a/advanced/api/test-suite.md b/advanced/api/test-suite.md index 52c113de..a727e968 100644 --- a/advanced/api/test-suite.md +++ b/advanced/api/test-suite.md @@ -219,3 +219,30 @@ describe('the validation works correctly', (task) => { :::tip If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter. ::: + +## meta 3.1.0 {#meta} + +```ts +function meta(): TaskMeta +``` + +Custom [metadata](/advanced/metadata) that was attached to the suite during its execution or collection. The meta can be attached by assigning a property to the `task.meta` object during a test run: + +```ts {5,10} +import { test } from 'vitest' + +describe('the validation works correctly', (task) => { + // assign "decorated" during collection + task.meta.decorated = false + + test('some test', ({ task }) => { + // assign "decorated" during test run, it will be available + // only in onTestCaseReady hook + task.suite.meta.decorated = false + }) +}) +``` + +:::tip +If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter. +::: diff --git a/api/index.md b/api/index.md index 1ac0ffd3..50b9674c 100644 --- a/api/index.md +++ b/api/index.md @@ -39,7 +39,11 @@ interface TestOptions { ::: +<<<<<<< HEAD 你可以通过链接函数的属性来定义选项: +======= +You can define options by chaining properties on a function: +>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3 ```ts import { test } from 'vitest' @@ -51,9 +55,17 @@ test.skip('skipped test', () => { test.concurrent.skip('skipped concurrent test', () => { // 一些现在失败的逻辑 }) + +test.concurrent.skip('skipped concurrent test', () => { + // some logic that fails right now +}) ``` +<<<<<<< HEAD 但你也可以提供一个对象作为第二个参数: +======= +But you can also provide an object as a second argument instead: +>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3 ```ts import { test } from 'vitest' @@ -65,7 +77,41 @@ test('skipped test', { skip: true }, () => { test('skipped concurrent test', { skip: true, concurrent: true }, () => { // some logic that fails right now }) + +test('skipped concurrent test', { skip: true, concurrent: true }, () => { + // some logic that fails right now +}) +``` + +They both work in exactly the same way. To use either one is purely a stylistic choice. + +Note that if you are providing timeout as the last argument, you cannot use options anymore: + +```ts +import { test } from 'vitest' + +// ✅ this works +test.skip('heavy test', () => { + // ... +}, 10_000) + +// ❌ this doesn't work +test('heavy test', { skip: true }, () => { + // ... +}, 10_000) +``` + +However, you can provide a timeout inside the object: + +```ts +import { test } from 'vitest' + +// ✅ this works +test('heavy test', { skip: true, timeout: 10_000 }, () => { + // ... +}) ``` +<<<<<<< HEAD 两者的工作方式完全相同。使用其中任何一种纯粹是个人风格选择。 @@ -100,6 +146,8 @@ test('heavy test', { skip: true, timeout: 10_000 }, () => { // ... }) ``` +======= +>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3 ## test diff --git a/guide/coverage.md b/guide/coverage.md index cb512adb..e3dae43f 100644 --- a/guide/coverage.md +++ b/guide/coverage.md @@ -173,7 +173,11 @@ export default CustomCoverageProviderModule ## 更改默认覆盖文件夹位置 +<<<<<<< HEAD 运行覆盖率报告时,会在项目的根目录中创建一个 `coverage` 文件夹。 如果你想将它移动到不同的目录,请使用 `vite.config.js` 文件中的 `test.coverage.reportsDirectory` 属性。 +======= +When running a coverage report, a `coverage` folder is created in the root directory of your project. If you want to move it to a different directory, use the `test.coverage.reportsDirectory` property in the `vitest.config.js` file. +>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3 ```js [vitest.config.js] import { defineConfig } from 'vite' @@ -223,10 +227,16 @@ if (condition) { 你可以在 [Vitest UI](/guide/ui) 中查看你的覆盖率报告。 +<<<<<<< HEAD Vitest UI 将在显式启用覆盖率报告且存在 html 覆盖率报告器的情况下启用覆盖率报告,否则将不可用: - 在配置中启用 `coverage.enabled=true` 或使用 `--coverage.enabled=true` 标志运行 Vitest - 在 `coverage.reporter` 列表中添加 `html`:也可以启用 `subdir` 选项,将覆盖率报告放到子目录中 +======= +Vitest UI will enable coverage report when it is enabled explicitly and the html coverage reporter is present, otherwise it will not be available: +- enable `coverage.enabled=true` in your configuration file or run Vitest with `--coverage.enabled=true` flag +- add `html` to the `coverage.reporter` list: you can also enable `subdir` option to put coverage report in a subdirectory +>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3 html coverage activation in Vitest UI html coverage activation in Vitest UI diff --git a/package.json b/package.json index 3e2e6c2b..ff46aaa1 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@unocss/reset": "latest", "@vite-pwa/assets-generator": "^0.2.6", "@vite-pwa/vitepress": "^0.5.4", +<<<<<<< HEAD "@vitejs/plugin-vue": "latest", "@vitest/browser": "^3.0.2", "@vitest/coverage-istanbul": "^3.0.2", @@ -40,6 +41,9 @@ "eslint": "^9.18.0", "esno": "^4.8.0", "fs-extra": "^11.3.0", +======= + "@vitejs/plugin-vue": "catalog:", +>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3 "https-localhost": "^4.7.1", "ofetch": "^1.4.1", "pathe": "^2.0.3",