[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): infer transform mode for uncovered files (#9435)

authored by

Ari Perkkiö and committed by
GitHub
(Jan 13, 2026, 3:32 PM +0100) f396792d e977f3de

+44 -15
+27 -3
test/coverage-test/test/include-exclude.test.ts
··· 225 225 expect(coverageMap.files()).toMatchInlineSnapshot(`{}`) 226 226 }) 227 227 228 - test('uncovered files are transformed correctly', async () => { 228 + test('uncovered files are transformed correctly (node and browser)', async () => { 229 229 await runVitest({ 230 230 config: 'fixtures/configs/vitest.config.conditional.ts', 231 231 include: ['fixtures/test/math.test.ts'], ··· 242 242 expect(files).toMatchInlineSnapshot(` 243 243 [ 244 244 "<process-cwd>/fixtures/src/math.ts", 245 - "<process-cwd>/fixtures/src/conditional/browser.ts", 245 + "<process-cwd>/fixtures/src/conditional/web.ts", 246 246 ] 247 247 `) 248 248 } ··· 250 250 expect(files).toMatchInlineSnapshot(` 251 251 [ 252 252 "<process-cwd>/fixtures/src/math.ts", 253 - "<process-cwd>/fixtures/src/conditional/node.ts", 253 + "<process-cwd>/fixtures/src/conditional/ssr.ts", 254 254 ] 255 255 `) 256 256 } 257 + }) 258 + 259 + test('uncovered files are transformed correctly (jsdom)', async ({ skip }) => { 260 + skip(isBrowser(), 'node relevant test') 261 + 262 + await runVitest({ 263 + config: 'fixtures/configs/vitest.config.conditional.ts', 264 + include: ['fixtures/test/math.test.ts'], 265 + environment: 'jsdom', 266 + coverage: { 267 + include: ['fixtures/src/math.ts', 'fixtures/src/conditional/*'], 268 + reporter: 'json', 269 + }, 270 + }) 271 + 272 + const coverageMap = await readCoverageMap() 273 + const files = coverageMap.files() 274 + 275 + expect(files).toMatchInlineSnapshot(` 276 + [ 277 + "<process-cwd>/fixtures/src/math.ts", 278 + "<process-cwd>/fixtures/src/conditional/web.ts", 279 + ] 280 + `) 257 281 }) 258 282 259 283 test('files included and excluded in plugin\'s configureVitest are excluded', async () => {
+8 -3
packages/vitest/src/node/coverage.ts
··· 634 634 root: project.config.root, 635 635 isBrowserEnabled: project.isBrowserEnabled(), 636 636 vite: project.vite, 637 + environment: project.config.environment, 637 638 })), 638 639 // Check core last as it will match all files anyway 639 - { root: ctx.config.root, vite: ctx.vite, isBrowserEnabled: ctx.getRootProject().isBrowserEnabled() }, 640 + { root: ctx.config.root, vite: ctx.vite, isBrowserEnabled: ctx.getRootProject().isBrowserEnabled(), environment: ctx.config.environment }, 640 641 ] 641 642 642 643 return async function transformFile(filename: string): Promise<TransformResult | null | undefined> { 643 644 let lastError 644 645 645 - for (const { root, vite, isBrowserEnabled } of servers) { 646 + for (const { root, vite, isBrowserEnabled, environment } of servers) { 646 647 // On Windows root doesn't start with "/" while filenames do 647 648 if (!filename.startsWith(root) && !filename.startsWith(`/${root}`)) { 648 649 continue ··· 657 658 } 658 659 659 660 try { 661 + if (environment === 'jsdom' || environment === 'happy-dom') { 662 + return await vite.environments.client.transformRequest(filename) 663 + } 664 + 660 665 return await vite.environments.ssr.transformRequest(filename) 661 666 } 662 667 catch (error) { ··· 664 669 } 665 670 } 666 671 667 - // All vite-node servers failed to transform the file 672 + // All vite servers failed to transform the file 668 673 throw lastError 669 674 } 670 675 }
+3 -3
test/coverage-test/fixtures/configs/vitest.config.conditional.ts
··· 1 - import { join, resolve } from 'node:path' 1 + import { resolve } from 'node:path' 2 2 import { defineConfig } from 'vitest/config' 3 3 4 4 export default defineConfig({ ··· 9 9 replacement: "$1", 10 10 customResolver(_, __, options) { 11 11 if ('ssr' in options && options.ssr) { 12 - return { id: resolve('fixtures/src/conditional/node.ts') } 12 + return { id: resolve('fixtures/src/conditional/ssr.ts') } 13 13 } 14 - return { id: resolve('fixtures/src/conditional/browser.ts') } 14 + return { id: resolve('fixtures/src/conditional/web.ts') } 15 15 }, 16 16 }, 17 17 ],
-3
test/coverage-test/fixtures/src/conditional/browser.ts
··· 1 - export function browser() { 2 - return "This is for browsers only" 3 - }
-3
test/coverage-test/fixtures/src/conditional/node.ts
··· 1 - export function node() { 2 - return "This is for node only" 3 - }
+3
test/coverage-test/fixtures/src/conditional/ssr.ts
··· 1 + export function ssr() { 2 + return "This is for ssr transform" 3 + }
+3
test/coverage-test/fixtures/src/conditional/web.ts
··· 1 + export function web() { 2 + return "This is for web transform" 3 + }