···390390391391Concurrency limit used when processing the coverage results.
392392393393+## coverage.instrumenter <Version type="experimental">4.1.5</Version> {#coverage-instrumenter}
394394+395395+- **Type:** `(options: InstrumenterOptions) => CoverageInstrumenter`
396396+- **Available for providers:** `'istanbul'`
397397+398398+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.
399399+400400+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`.
401401+402402+<!-- eslint-skip -->
403403+```ts
404404+interface InstrumenterOptions {
405405+ coverageVariable: string
406406+ coverageGlobalScope: string
407407+ coverageGlobalScopeFunc: boolean
408408+ ignoreClassMethods: string[]
409409+}
410410+411411+interface CoverageInstrumenter {
412412+ instrumentSync: (code: string, filename: string, inputSourceMap?: any) => string
413413+ lastSourceMap: () => any
414414+ lastFileCoverage: () => any
415415+}
416416+```
417417+418418+<!-- eslint-skip -->
419419+```ts
420420+import { defineConfig } from 'vitest/config'
421421+import { createInstrumenter } from '@vitest/some-custom-instrumenter'
422422+423423+export default defineConfig({
424424+ test: {
425425+ coverage: {
426426+ provider: 'istanbul',
427427+ instrumenter: options => createInstrumenter(options),
428428+ }
429429+ }
430430+})
431431+```
432432+393433## coverage.customProviderModule
394434395435- **Type:** `string`
···272272 ignoreClassMethods?: string[]
273273274274 /**
275275+ * Custom instrumenter factory to use instead of the default `istanbul-lib-instrument`.
276276+ *
277277+ * The factory receives the same runtime coverage options Vitest passes to its
278278+ * built-in Istanbul instrumenter and must return an object implementing the
279279+ * `CoverageInstrumenter` interface.
280280+ *
281281+ * This allows using faster instrumenters (e.g., oxc-coverage-instrument, SWC) while
282282+ * keeping the Istanbul coverage pipeline for collection, merging, and reporting.
283283+ *
284284+ * @example
285285+ * ```ts
286286+ * import { defineConfig } from 'vitest/config'
287287+ * import { createOxcInstrumenter } from 'oxc-coverage-instrument/vitest'
288288+ *
289289+ * export default defineConfig({
290290+ * test: {
291291+ * coverage: {
292292+ * provider: 'istanbul',
293293+ * instrumenter: options => createOxcInstrumenter(options),
294294+ * }
295295+ * }
296296+ * })
297297+ *
298298+ * @experimental
299299+ */
300300+ instrumenter?: (options: InstrumenterOptions) => CoverageInstrumenter
301301+302302+ /**
275303 * Directory of HTML coverage output to be served in UI mode and HTML reporter.
276304 * This is automatically configured for builtin reporter with html output (`html`, `html-spa`, and `lcov` reporters).
277305 * Use this option to override with custom coverage reporting location.
···316344317345 /** Thresholds for lines */
318346 lines?: number
347347+}
348348+349349+/**
350350+ * Options passed to the custom instrumenter factory.
351351+ */
352352+export interface InstrumenterOptions {
353353+ /** Global variable name that Vitest uses to store coverage data at runtime. */
354354+ coverageVariable: string
355355+ /** Global scope where the coverage variable is attached at runtime. */
356356+ coverageGlobalScope: string
357357+ /** Whether the coverage global scope should be resolved through an evaluated function. */
358358+ coverageGlobalScopeFunc: boolean
359359+ /** Class method names to exclude from function coverage. */
360360+ ignoreClassMethods: string[]
361361+}
362362+363363+/**
364364+ * Interface for custom coverage instrumenters.
365365+ *
366366+ * Matches the subset of istanbul-lib-instrument's `Instrumenter` that Vitest
367367+ * actually uses. Implement this to plug in a faster instrumenter while keeping
368368+ * the Istanbul coverage pipeline for collection, merging, and reporting.
369369+ */
370370+export interface CoverageInstrumenter {
371371+ /** Instrument source code synchronously. Returns the instrumented code string. */
372372+ instrumentSync: (code: string, filename: string, inputSourceMap?: any) => string
373373+ /** Get the source map of the last instrumented file. */
374374+ lastSourceMap: () => any
375375+ /** Get the Istanbul-compatible file coverage object of the last instrumented file. */
376376+ lastFileCoverage: () => any
319377}
320378321379/** @deprecated Use `CoverageOptions` instead */