-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Describe the bug
Hello! I am migrating from v3 to v4 and found that new coverage include/exclude logic in v4 does not quite match what was working in v3 and seems like a bug.
Case 1: I want to include all files, but exclude files from top-level
Coverage options:
coverage: {
include: [
// all .js,.ts,.tsx files
'**/*.ts',
],
exclude: [
// exclude .ts files for top-level
'*.ts',
],
}Expected behavior: files inside folders are included in coverage and files on top-level - are not
Actual behavior: all files are not included
Potential fix: Do not use contains options for picomatch.isMatch. When I remove it, I achieve expected behavior.
Case 2: I want to exclude all dirs with some particular name even if it happens that CWD already includes such name
Ignore Name: foo
CWD: /Users/iam/code/foo
Coverage options:
coverage: {
include: [
// all .js,.ts,.tsx files
'**/*.ts',
],
exclude: [
// exclude files in any "foo" folders
'**/foo/**',
],
}Expected behavior: all .ts files inside CWD are included in coverage, except files that are under folders with name "foo"
Actual behavior: all files are not included, because CWD is ignored
Potential fix: Use relative filename with picomatch.isMatch. When I use path.relative(process.cwd(), filename) instead of filename, I achieve expected behavior.
Reproduction
Case 1: https://stackblitz.com/edit/vitest-dev-vitest-4nte3ynw?file=vitest.config.ts
Case 2: https://stackblitz.com/edit/vitest-dev-vitest-tguz5bfs?file=vitest.config.ts
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@vitest/coverage-istanbul: 4.0.16 => 4.0.16
vite: latest => 7.3.0
vitest: 4.0.16 => 4.0.16Used 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.