Skip to content

Conversation

@DevJoaoLopes
Copy link
Contributor

Description

Fixes coverage.include/coverage.exclude glob matching so it behaves like test.include/test.exclude (relative to the project root), addressing Vitest v4 regressions reported in #9395.

In v4, matching was done against the full (absolute) filename with picomatch using contains: true and ignore, which made patterns such as ./*.ts or **/foo/** unexpectedly match parts of the absolute path (including the CWD), causing everything to be excluded.

This change:

  • Matches include/exclude against the path relative to each project root when the file is inside the project, so top-level-only excludes like ./*.ts work as expected.
  • Avoids excluding the whole project when the CWD contains an excluded segment (e.g. /.../foo/...), by using relative paths for in-project files and only using the absolute filename for truly external files.
  • Keeps allowExternal: false semantics by skipping external files instead of incorrectly failing matches for everything.
  • Adjusts the glob cache key to include the root (so multi-project roots don’t share incorrect cached results).

fix #9395

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
Copy link

netlify bot commented Jan 9, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cab9966
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6961852bf47ddc0008bb041e
😎 Deploy Preview https://deploy-preview-9426--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

Could you check the failing tests and add new tests to test/coverage-test to validate this fix? Or maybe use the test/coverage-test/test/include-exclude.test.ts.

@DevJoaoLopes
Copy link
Contributor Author

Could you check the failing tests and add new tests to test/coverage-test to validate this fix? Or maybe use the test/coverage-test/test/include-exclude.test.ts.

@AriPerkkio Sure, I apologize for not doing it from the beginning... I'll work on it. 😅

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.

Options coverage.include and coverage.exclude do not work as expected

2 participants