Skip to content
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 api/advanced/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ function start(filters?: string[]): Promise<TestRunResult>
function standalone(): Promise<void>
```

<<<<<<< HEAD
- **别名:**: `init` <Deprecated />
=======
- **Alias:** `init` <Deprecated />
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

初始化报告器和覆盖率提供者。此方法不运行任何测试。如果提供了 `--watch` 标志,Vitest 仍将运行更改的测试,即使未调用此方法。

Expand Down
10 changes: 10 additions & 0 deletions api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ test('assert.fail', () => {

## isOk

<<<<<<< HEAD
- **类型:** `<T>(value: T, message?: string) => asserts value`
- **Alias** `ok`
=======
Comment on lines +38 to +41
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve leftover merge-conflict markers

This commit leaves raw conflict markers (<<<<<<<, =======, >>>>>>>) in published docs content (for example here, and repeated across many files in the same commit such as api/expect.md, config/sequence.md, and guide/cli.md). That indicates the merge was not actually resolved, so readers will see broken mixed content and any CI checks that enforce clean merges/content can fail. Please pick one side (or a true manual merge) and remove the markers everywhere.

Useful? React with 👍 / 👎.

- **Type:** `<T>(value: T, message?: string) => asserts value`
- **Alias:** `ok`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

断言给定的 `value` 是 true 。

Expand All @@ -51,8 +56,13 @@ test('assert.isOk', () => {

## isNotOk

<<<<<<< HEAD
- **类型:** `<T>(value: T, message?: string) => void`
- **Alias** `notOk`
=======
- **Type:** `<T>(value: T, message?: string) => void`
- **Alias:** `notOk`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

断言给定的 `value` 是 false 。

Expand Down
68 changes: 68 additions & 0 deletions api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,11 @@ test('spy function', () => {

## toHaveBeenCalledTimes

<<<<<<< HEAD
- **类型**: `(amount: number) => Awaitable<void>`
=======
- **Type:** `(amount: number) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查函数是否被调用了特定次数。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1102,7 +1106,11 @@ test('spy function called two times', () => {

## toHaveBeenCalledWith

<<<<<<< HEAD
- **类型**: `(...args: any[]) => Awaitable<void>`
=======
- **Type:** `(...args: any[]) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查函数是否至少一次被调用,并带有特定的参数。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1128,7 +1136,11 @@ test('spy function', () => {

## toHaveBeenCalledBefore

<<<<<<< HEAD
- **类型**: `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => Awaitable<void>`
=======
- **Type:** `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查一个 `Mock` 是否在另一个 `Mock` 之前被调用。

Expand All @@ -1147,7 +1159,11 @@ test('calls mock1 before mock2', () => {

## toHaveBeenCalledAfter

<<<<<<< HEAD
- **类型**: `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => Awaitable<void>`
=======
- **Type:** `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查一个 `Mock` 是否在另一个 `Mock` 之后被调用。

Expand All @@ -1166,7 +1182,11 @@ test('calls mock1 after mock2', () => {

## toHaveBeenCalledExactlyOnceWith

<<<<<<< HEAD
- **类型**: `(...args: any[]) => Awaitable<void>`
=======
- **Type:** `(...args: any[]) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查函数是否恰好被调用了一次,并且带有特定的参数。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1190,7 +1210,11 @@ test('spy function', () => {

## toHaveBeenLastCalledWith

<<<<<<< HEAD
- **类型**: `(...args: any[]) => Awaitable<void>`
=======
- **Type:** `(...args: any[]) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查函数在其最后一次调用时是否被传入了特定的参数。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1216,7 +1240,11 @@ test('spy function', () => {

## toHaveBeenNthCalledWith

<<<<<<< HEAD
- **类型**: `(time: number, ...args: any[]) => Awaitable<void>`
=======
- **Type:** `(time: number, ...args: any[]) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查函数是否在特定的次数被调用时带有特定的参数。计数从 1 开始。因此,要检查第二次调用,我们需要写成 `.toHaveBeenNthCalledWith(2, ...)`。

Expand All @@ -1243,7 +1271,11 @@ test('first call of spy function called with right params', () => {

## toHaveReturned

<<<<<<< HEAD
- **类型**: `() => Awaitable<void>`
=======
- **Type:** `() => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查函数是否至少成功返回了一次值( i.e. ,没有抛出错误)。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1267,7 +1299,11 @@ test('spy function returned a value', () => {

## toHaveReturnedTimes

<<<<<<< HEAD
- **类型**: `(amount: number) => Awaitable<void>`
=======
- **Type:** `(amount: number) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查函数是否在确切的次数内成功返回了值( i.e. ,没有抛出错误)。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1286,7 +1322,11 @@ test('spy function returns a value two times', () => {

## toHaveReturnedWith

<<<<<<< HEAD
- **类型**: `(returnValue: any) => Awaitable<void>`
=======
- **Type:** `(returnValue: any) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

我们可以调用这个断言来检查函数是否至少一次成功返回了带有特定参数的值。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1304,7 +1344,11 @@ test('spy function returns a product', () => {

## toHaveLastReturnedWith

<<<<<<< HEAD
- **类型**: `(returnValue: any) => Awaitable<void>`
=======
- **Type:** `(returnValue: any) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

我们可以使用这个断言来检查函数在最后一次被调用时是否成功返回了特定的值。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1323,7 +1367,11 @@ test('spy function returns bananas on a last call', () => {

## toHaveNthReturnedWith

<<<<<<< HEAD
- **类型**: `(time: number, returnValue: any) => Awaitable<void>`
=======
- **Type:** `(time: number, returnValue: any) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

我们可以调用这个断言来检查函数是否在特定的调用中成功返回了带有特定参数的值。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1344,7 +1392,11 @@ test('spy function returns bananas on second call', () => {

## toHaveResolved

<<<<<<< HEAD
- **类型**: `() => Awaitable<void>`
=======
- **Type:** `() => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

这个断言检查函数是否至少一次成功地解析了一个值( i.e. ,没有被拒绝)。需要将一个 spy 函数传递给 `expect`。

Expand All @@ -1370,7 +1422,11 @@ test('spy function resolved a value', async () => {

## toHaveResolvedTimes

<<<<<<< HEAD
- **类型**: `(amount: number) => Awaitable<void>`
=======
- **Type:** `(amount: number) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

此断言检查函数是否已成功解析值精确次数(即未 reject)。需要将 spy 函数传递给`expect`。

Expand All @@ -1391,7 +1447,11 @@ test('spy function resolved a value two times', async () => {

## toHaveResolvedWith

<<<<<<< HEAD
- **类型:** `(returnValue: any) => Awaitable<void>`
=======
- **Type:** `(returnValue: any) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

您可以调用此断言来检查函数是否至少成功解析过一次某个值。需要将 spy 函数传递给`expect`。

Expand All @@ -1411,7 +1471,11 @@ test('spy function resolved a product', async () => {

## toHaveLastResolvedWith

<<<<<<< HEAD
- **类型:** `(returnValue: any) => Awaitable<void>`
=======
- **Type:** `(returnValue: any) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

您可以调用此断言来检查函数在上次调用时是否已成功解析某个值。需要将 spy 函数传递给`expect`。

Expand All @@ -1432,7 +1496,11 @@ test('spy function resolves bananas on a last call', async () => {

## toHaveNthResolvedWith

<<<<<<< HEAD
- **类型:** `(time: number, returnValue: any) => Awaitable<void>`
=======
- **Type:** `(time: number, returnValue: any) => Awaitable<void>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

你可以调用此断言来检查函数在特定调用中是否成功解析了某个值。需要将一个 spy 函数传递给 `expect`。

Expand Down
6 changes: 6 additions & 0 deletions config/allowonly.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ outline: deep

# allowOnly

<<<<<<< HEAD
- **类型:**: `boolean`
- **默认值:**: `!process.env.CI`
- **命令行终端:** `--allowOnly`, `--allowOnly=false`
=======
- **Type:** `boolean`
- **Default:** `!process.env.CI`
- **CLI:** `--allowOnly`, `--allowOnly=false`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

默认情况下,Vitest 不允许在持续集成(CI)环境中运行带有 [`only`](/api/test#test-only) 标记的测试。相反,在本地开发环境中,Vitest 允许运行这些测试。

Expand Down
6 changes: 6 additions & 0 deletions config/bail.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ outline: deep

# bail

<<<<<<< HEAD
- **类型:** `number`
- **默认值:** `0`
- **命令行终端:** `--bail=<value>`
=======
- **Type:** `number`
- **Default:** `0`
- **CLI:** `--bail=<value>`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

当指定数量的测试用例失败时立即终止测试执行。

Expand Down
4 changes: 4 additions & 0 deletions config/browser/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export default defineConfig({
})
```

<<<<<<< HEAD
## 自定义 Provider <Badge type="danger">advanced</Badge> {#custom-provider}
=======
## Custom Provider <Badge type="danger">advanced</Badge> {#custom-provider}
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

::: danger 高级 API
自定义 provider API 处于高度实验阶段,可能会在小版本之间发生变化。如果你只需要在浏览器中运行测试,请使用 [`browser.instances`](/config/browser/instances) 选项替代。
Expand Down
5 changes: 5 additions & 0 deletions config/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ outline: deep

# cache <CRoot />

<<<<<<< HEAD
- **类型:** `false`
- **命令行终端:** `--no-cache`, `--cache=false`
=======
- **Type:** `false`
- **CLI:** `--no-cache`, `--cache=false`
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

使用此选项可禁用缓存功能。当前 Vitest 会缓存测试结果,以便优先运行耗时较长和失败的测试。

Expand Down
44 changes: 44 additions & 0 deletions config/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
- **可用的测试提供者:** `'v8' | 'istanbul'`
- **命令行终端:** `--coverage.clean`, `--coverage.clean=false`

<<<<<<< HEAD

Check failure on line 68 in config/coverage.md

View workflow job for this annotation

GitHub Actions / autofix

Unexpected additional H1 heading found
运行测试前清除代码覆盖率结果。
=======
Clean coverage results before running tests.
>>>>>>> 30df941749c0ffd4dfc4cc5c8691c9770e007b83

## coverage.cleanOnRerun

Expand Down Expand Up @@ -390,6 +394,46 @@

处理代码覆盖率结果时使用的并发限制。

## coverage.instrumenter <Version type="experimental">4.1.5</Version> {#coverage-instrumenter}

- **Type:** `(options: InstrumenterOptions) => CoverageInstrumenter`
- **Available for providers:** `'istanbul'`

Factory for a custom instrumenter to use in place of the default `istanbul-lib-instrument`. Vitest calls the factory once during initialization and reuses the returned instrumenter for every file. The rest of the Istanbul pipeline (collection, merging, reporting) is unchanged.

The factory receives an `InstrumenterOptions` object with Vitest's runtime coverage settings, and must return an object implementing the `CoverageInstrumenter` interface. Both types are exported from `vitest/node`.

<!-- eslint-skip -->
```ts
interface InstrumenterOptions {
coverageVariable: string
coverageGlobalScope: string
coverageGlobalScopeFunc: boolean
ignoreClassMethods: string[]
}

interface CoverageInstrumenter {
instrumentSync: (code: string, filename: string, inputSourceMap?: any) => string
lastSourceMap: () => any
lastFileCoverage: () => any
}
```

<!-- eslint-skip -->
```ts
import { defineConfig } from 'vitest/config'
import { createInstrumenter } from '@vitest/some-custom-instrumenter'

export default defineConfig({
test: {
coverage: {
provider: 'istanbul',
instrumenter: options => createInstrumenter(options),
}
}
})
```

## coverage.customProviderModule

- **类型:** `string`
Expand Down
Loading
Loading