Skip to content
Open
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
40 changes: 40 additions & 0 deletions config/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,46 @@ Vitest 会将所有文件(包括匹配 glob 模式的文件)计入全局覆

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

## 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
2 changes: 1 addition & 1 deletion config/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ConfigReporter = string | Reporter | [string, object?]
- [`tap-flat`](/guide/reporters#tap-flat-reporter)
- [`hanging-process`](/guide/reporters#hanging-process-reporter)
- [`github-actions`](/guide/reporters#github-actions-reporter)
- [`agent`](/guide/reporters#agent-reporter)
- [`minimal`](/guide/reporters#minimal-reporter) (aliased as `agent`)
- [`blob`](/guide/reporters#blob-reporter)

## 示例 {#example}
Expand Down
4 changes: 4 additions & 0 deletions guide/cli-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@
- **命令行终端:** `--reporter <name>`
- **配置:** [reporters](/config/reporters)

<<<<<<< HEAD
指定报告器(default、agent、blob、verbose、dot、json、tap、tap-flat、junit、tree、hanging-process、github-actions)
=======
Specify reporters (default, agent, minimal, blob, verbose, dot, json, tap, tap-flat, junit, tree, hanging-process, github-actions)
>>>>>>> 2aae193f0f78a1bf6e7987cb80dc9950fb739a94
Comment on lines +105 to +109
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 Remove unresolved merge markers in reporters CLI section

This section still contains Git conflict markers (<<<<<<<, =======, >>>>>>>), which means the merge was left unresolved. As committed, the generated CLI docs will render raw conflict text (and many docs pipelines treat this as a hard failure), so users cannot reliably read the --reporter description until this block is resolved to a single final sentence.

Useful? React with 👍 / 👎.


### outputFile

Check failure on line 111 in guide/cli-generated.md

View workflow job for this annotation

GitHub Actions / autofix

Heading level skipped from 1 to 3

- **命令行终端:** `--outputFile <filename/-s>`
- **配置:** [outputFile](/config/outputfile)
Expand Down
15 changes: 9 additions & 6 deletions guide/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default defineConfig({
默认情况下(即如果没有指定报告器),Vitest 会在底部显示运行测试的摘要及其状态。一旦测试套件通过,其状态将被报告在摘要的顶部。
<!-- TODO: translation -->
::: tip
When Vitest detects it is running inside an AI coding agent, the [`agent`](#agent-reporter) reporter is used instead to reduce output and minimize token usage. You can override this by explicitly configuring the [`reporters`](/config/reporters) option.
When Vitest detects it is running inside an AI coding agent, the [`minimal`](#minimal-reporter) reporter is used instead to reduce output and minimize token usage. You can override this by explicitly configuring the [`reporters`](/config/reporters) option.
:::

我们可以通过配置报告器来禁用摘要:
Expand Down Expand Up @@ -670,21 +670,24 @@ export default defineConfig({
})
```

### Agent Reporter
### Minimal Reporter

Outputs a minimal report optimized for AI coding assistants and LLM-based workflows. Only failed tests and their error messages are displayed. Console logs from passing tests and the summary section are suppressed to reduce token usage.
- **Alias:** `agent`

This reporter is automatically enabled when no `reporters` option is configured and Vitest detects it is running inside an AI coding agent. If you configure custom reporters, you can explicitly add `agent`:
Outputs a minimal report containing only failed tests and their error messages. Console logs from passing tests and the summary section are also suppressed.

::: tip Agent Reporter
This reporter is well optimized for AI coding assistants and LLM-based workflows to reduce token usage. It is automatically enabled when no `reporters` option is configured and Vitest detects it is running inside an AI coding agent. If you configure custom reporters, you can explicitly add `minimal` or `agent`:

:::code-group
Comment on lines +679 to 682
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Close the tip container for Minimal Reporter docs

A new ::: tip Agent Reporter block is opened here, but only one closing ::: is present later (used to close the nested :::code-group). That leaves the tip container unbalanced before the next section header, which can cause subsequent content to be rendered inside the admonition and breaks page structure in Markdown container parsers.

Useful? React with 👍 / 👎.

```bash [CLI]
npx vitest --reporter=agent
npx vitest --reporter=minimal
```

```ts [vitest.config.ts]
export default defineConfig({
test: {
reporters: ['agent']
reporters: ['minimal']
},
})
```
Expand Down
Loading