[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(coverage): enforce order of `vitest:coverage-transform` plugin (#8477)

authored by

Ari Perkkiö and committed by
GitHub
(Aug 26, 2025, 10:54 AM +0200) ff5170cf 2c2d1d4c

+34 -2
+3 -1
test/coverage-test/utils.ts
··· 1 1 import type { CoverageSummary, FileCoverageData } from 'istanbul-lib-coverage' 2 + import type { UserConfig as ViteUserConfig } from 'vite' 2 3 import type { TestFunction } from 'vitest' 3 4 import type { TestUserConfig } from 'vitest/node' 4 5 import { existsSync, readFileSync } from 'node:fs' ··· 29 30 } 30 31 } 31 32 32 - export async function runVitest(config: TestUserConfig, options = { throwOnError: true }) { 33 + export async function runVitest(config: TestUserConfig, options = { throwOnError: true }, viteOverrides: ViteUserConfig = {}) { 33 34 const provider = process.env.COVERAGE_PROVIDER as any 34 35 35 36 const result = await testUtils.runVitest({ ··· 38 39 ...config, 39 40 browser: config.browser, 40 41 }, [], 'test', { 42 + ...viteOverrides, 41 43 test: { 42 44 env: { 43 45 COVERAGE_TEST: 'true',
+29
test/coverage-test/test/transform-plugin-order.istanbul.test.ts
··· 1 + import { expect } from 'vitest' 2 + import { customFilePlugin } from '../fixtures/configs/vitest.config.multi-transforms' 3 + import { readCoverageMap, runVitest, test } from '../utils' 4 + 5 + test('custom `viteOverrides.plugins` work with `vitest:coverage-transform` plugin (#8468)', async () => { 6 + const viteOverrides = { plugins: [customFilePlugin('1')] } 7 + 8 + await runVitest({ 9 + include: ['fixtures/test/custom-1-syntax.test.ts'], 10 + coverage: { reporter: 'json' }, 11 + }, undefined, viteOverrides) 12 + 13 + const coverageMap = await readCoverageMap() 14 + expect(coverageMap.files()).toMatchInlineSnapshot(` 15 + [ 16 + "<process-cwd>/fixtures/src/covered.custom-1", 17 + ] 18 + `) 19 + 20 + const fileCoverage = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/covered.custom-1') 21 + expect(fileCoverage).toMatchInlineSnapshot(` 22 + { 23 + "branches": "0/0 (100%)", 24 + "functions": "1/2 (50%)", 25 + "lines": "1/2 (50%)", 26 + "statements": "1/2 (50%)", 27 + } 28 + `) 29 + })
+1 -1
test/coverage-test/fixtures/configs/vitest.config.multi-transforms.ts
··· 37 37 /** 38 38 * Plugin for transforming `.custom-1` and/or `.custom-2` files to Javascript 39 39 */ 40 - function customFilePlugin(postfix: "1" | "2"): Plugin { 40 + export function customFilePlugin(postfix: "1" | "2"): Plugin { 41 41 function transform(code: MagicString) { 42 42 code.replaceAll( 43 43 "<function covered>",
+1
packages/vitest/src/node/plugins/coverageTransform.ts
··· 4 4 export function CoverageTransform(ctx: Vitest): VitePlugin { 5 5 return { 6 6 name: 'vitest:coverage-transform', 7 + enforce: 'post', 7 8 transform(srcCode, id) { 8 9 return ctx.coverageProvider?.onFileTransform?.( 9 10 srcCode,