Skip to content

docs(en): merge docs-cn/sync-docs into docs-cn/dev @ eec388d5 #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions advanced/api/test-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 27 additions & 0 deletions advanced/api/test-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ describe('the validation works correctly', (task) => {
如果元数据是在收集过程中附加的(在 `test` 函数之外),那么它将在自定义报告器中的['onTestModuleCollectd'](./reporters#onTestModuleCollected)挂钩中可用。
:::

## meta <Version>3.1.0</Version> {#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
Expand Down
27 changes: 27 additions & 0 deletions advanced/api/test-suite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Version>3.1.0</Version> {#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.
:::
48 changes: 48 additions & 0 deletions api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ interface TestOptions {

:::

<<<<<<< HEAD
你可以通过链接函数的属性来定义选项:
=======
You can define options by chaining properties on a function:
>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3

```ts
import { test } from 'vitest'
Expand All @@ -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'
Expand All @@ -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

两者的工作方式完全相同。使用其中任何一种纯粹是个人风格选择。

Expand Down Expand Up @@ -100,6 +146,8 @@ test('heavy test', { skip: true, timeout: 10_000 }, () => {
// ...
})
```
=======
>>>>>>> eec388d56b85bdce969334007efb2bf45fdf50c3

## test

Expand Down
10 changes: 10 additions & 0 deletions guide/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

<img alt="html coverage activation in Vitest UI" img-light src="/vitest-ui-show-coverage-light.png">
<img alt="html coverage activation in Vitest UI" img-dark src="/vitest-ui-show-coverage-dark.png">
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down