Skip to content

fix(coverage): v8 browser memory leak between test files - #11466

Merged
AriPerkkio merged 2 commits into
vitest-dev:mainfrom
AriPerkkio:fix/browser-v8-coverage-leak
Oct 6, 2026
Merged

AriPerkkio merged 2 commits into
vitest-dev:mainfrom
AriPerkkio:fix/browser-v8-coverage-leak

Conversation

@AriPerkkio

@AriPerkkio AriPerkkio commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Description

Resolves #11447

As V8 coverage starts profiler, we end up collecting stuff between test files that share same V8 instance (tab). Currently we are not toggling coverage on-off between test files, as that used to break the results. It seems that collecting garbage between coverage toggling fixes this.

This has a performance hit of course, but it's more correct behavior. Running https://github.com/vitest-tests/coverage-large locally on M2 Air:

  • vitest@5.0.3: 0m36.104s, 0m33.941s
  • This PR on pkg.pr.new, 2953e5c: 0m40.244s, 0m41.833s

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:.

@pkg-pr-new

pkg-pr-new Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
@vitest/browser

npm i https://pkg.pr.new/@vitest/browser@2953e5c

@vitest/browser-playwright

npm i https://pkg.pr.new/@vitest/browser-playwright@2953e5c

@vitest/browser-preview

npm i https://pkg.pr.new/@vitest/browser-preview@2953e5c

@vitest/coverage-istanbul

npm i https://pkg.pr.new/@vitest/coverage-istanbul@2953e5c

@vitest/coverage-v8

npm i https://pkg.pr.new/@vitest/coverage-v8@2953e5c

@vitest/expect

npm i https://pkg.pr.new/@vitest/expect@2953e5c

@vitest/mocker

npm i https://pkg.pr.new/@vitest/mocker@2953e5c

@vitest/pretty-format

npm i https://pkg.pr.new/@vitest/pretty-format@2953e5c

@vitest/snapshot

npm i https://pkg.pr.new/@vitest/snapshot@2953e5c

@vitest/spy

npm i https://pkg.pr.new/@vitest/spy@2953e5c

@vitest/ui

npm i https://pkg.pr.new/@vitest/ui@2953e5c

@vitest/utils

npm i https://pkg.pr.new/@vitest/utils@2953e5c

vitest

npm i https://pkg.pr.new/vitest@2953e5c

@vitest/web-worker

npm i https://pkg.pr.new/@vitest/web-worker@2953e5c

commit: 2953e5c

@netlify

netlify Bot commented Oct 4, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 160a759
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6ac1f63a31bfdc0008b7b7e6
😎 Deploy Preview https://deploy-preview-11466--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.

},
})

expect(liveDocuments).toHaveLength(4)

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:

Image

And yes, this test passes fine when fix is reverted and coverage is disabled.

@AriPerkkio
AriPerkkio marked this pull request as ready for review October 5, 2026 19:05
@AriPerkkio
AriPerkkio merged commit 2297d93 into vitest-dev:main Oct 6, 2026
30 checks passed
@AriPerkkio
AriPerkkio deleted the fix/browser-v8-coverage-leak branch October 6, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser mode: coverage-v8 leaks memory between tests

2 participants