Description
Describe the bug
Source files which include their tests with in-source testing will be dropped from coverage reported by @vitest/coverage-v8/browser
I tracked this down to
vitest/packages/coverage-v8/src/browser.ts
Lines 74 to 76 in 03660f9
Since the source files containing the in-source tests are loaded with the prefix &browserv=
in the URL they are omitted from coverage reporting. So to fix this the filter should be adjusted to not filter out those files.
Reproduction
@vitest/coverage-v8 doesn't work on StackBlitz, so I made a repo based on the in-source testing example:
https://github.com/egfx-notifications/vitest-issue-reproduction
Clone the repository, then run
npm install
npm run test
This shows that the in-source test passes with zero code coverage.
You can run npm run test:negative
to demonstrate that code coverage works fine with a separate test file.
System Info
System:
OS: Windows 11 10.0.26100
CPU: (22) x64 Intel(R) Core(TM) Ultra 7 165H
Memory: 40.73 GB / 63.45 GB
Binaries:
Node: 22.14.0 - ~\scoop\apps\nvm\current\nodejs\nodejs\node.EXE
npm: 10.9.2 - ~\scoop\apps\nvm\current\nodejs\nodejs\npm.CMD
pnpm: 10.9.0 - ~\scoop\apps\nvm\current\nodejs\nodejs\pnpm.CMD
Browsers:
Edge: Chromium (133.0.3065.69)
npmPackages:
@vitest/browser: ^3.1.2 => 3.1.2
@vitest/coverage-v8: ^3.1.2 => 3.1.2
playwright: ^1.52.0 => 1.52.0
vitest: latest => 3.1.2
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.