Skip to content

fix(coverage): v8 to ignore Vite SSR's generated import bindings - #11023

Merged
sheremet-va merged 1 commit into
vitest-dev:mainfrom
AriPerkkio:fix/v8-coverage-ignore-more-vite-ssr
Aug 20, 2026
Merged

sheremet-va merged 1 commit into
vitest-dev:mainfrom
AriPerkkio:fix/v8-coverage-ignore-more-vite-ssr

Conversation

@AriPerkkio

@AriPerkkio AriPerkkio commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Description

Resolves #11012

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify

netlify Bot commented Aug 20, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8c5ea92
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a86f5ece329340008e13d04
😎 Deploy Preview https://deploy-preview-11023--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@AriPerkkio
AriPerkkio force-pushed the fix/v8-coverage-ignore-more-vite-ssr branch from 8c5ea92 to f99d106 Compare August 20, 2026 12:43
Comment on lines +261 to +269
if (
type === 'statement'
&& node.type === 'VariableDeclarator'
&& node.init
&& node.init.type === 'MemberExpression'
&& node.init.object.type === 'MemberExpression'
&& node.init.object.object.type === 'Identifier'
&& node.init.object.object.name.startsWith('__vite_ssr_import_')
) {

@AriPerkkio AriPerkkio Aug 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@AriPerkkio
AriPerkkio force-pushed the fix/v8-coverage-ignore-more-vite-ssr branch from f99d106 to de8143a Compare August 20, 2026 13:00
Comment on lines +72 to +108
test.for(['node', 'jsdom'] as const)('vite SSR generated code ignored in { environment: %s }', async (environment, { skip }) => {
skip(isBrowser(), 'SSR not relevant to browser environment')

await runVitest({
include: ['fixtures/test/vite-ssr-imports.test.ts'],
environment,
coverage: { reporter: 'json',
},
})

const coverageMap = await readCoverageMap()
const fileCoverages = coverageMap.files().map(file => coverageMap.fileCoverageFor(file))

expect(fileCoverages).toMatchInlineSnapshot(`
{
"<process-cwd>/fixtures/src/node-built-ins.ts": {
"branches": "0/0 (100%)",
"functions": "1/1 (100%)",
"lines": "1/1 (100%)",
"statements": "1/1 (100%)",
},
}
`)

const lineCoverages = coverageMap.files().reduce((all, file) => ({
[file]: coverageMap.fileCoverageFor(file).getLineCoverage(),
...all,
}), {})

expect(lineCoverages).toMatchInlineSnapshot(`
{
"<process-cwd>/fixtures/src/node-built-ins.ts": {
"4": 1,
},
}
`)
})

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Failure without the fix, exactly as in repro

Image

@AriPerkkio
AriPerkkio marked this pull request as ready for review August 20, 2026 13:02

@sheremet-va sheremet-va left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice 👍

@sheremet-va
sheremet-va merged commit c6174a6 into vitest-dev:main Aug 20, 2026
48 of 51 checks passed
@AriPerkkio
AriPerkkio deleted the fix/v8-coverage-ignore-more-vite-ssr branch August 20, 2026 15:21
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coverage: a file’s statement map depends on which project reports it, so merged reports show an uncoverable statement

2 participants