diff --git a/config/coverage.md b/config/coverage.md index c3c23949..93431cb5 100644 --- a/config/coverage.md +++ b/config/coverage.md @@ -390,6 +390,46 @@ Vitest 会将所有文件(包括匹配 glob 模式的文件)计入全局覆 处理代码覆盖率结果时使用的并发限制。 +## coverage.instrumenter 4.1.5 {#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`. + + +```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 +} +``` + + +```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` diff --git a/config/reporters.md b/config/reporters.md index f9f8f018..a9d74af6 100644 --- a/config/reporters.md +++ b/config/reporters.md @@ -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} diff --git a/guide/cli-generated.md b/guide/cli-generated.md index 727ab561..118ccba7 100644 --- a/guide/cli-generated.md +++ b/guide/cli-generated.md @@ -102,7 +102,11 @@ - **命令行终端:** `--reporter ` - **配置:** [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 ### outputFile diff --git a/guide/reporters.md b/guide/reporters.md index b6d7ed23..99a38bf7 100644 --- a/guide/reporters.md +++ b/guide/reporters.md @@ -100,7 +100,7 @@ export default defineConfig({ 默认情况下(即如果没有指定报告器),Vitest 会在底部显示运行测试的摘要及其状态。一旦测试套件通过,其状态将被报告在摘要的顶部。 ::: 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. ::: 我们可以通过配置报告器来禁用摘要: @@ -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 ```bash [CLI] -npx vitest --reporter=agent +npx vitest --reporter=minimal ``` ```ts [vitest.config.ts] export default defineConfig({ test: { - reporters: ['agent'] + reporters: ['minimal'] }, }) ```