-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: update coverage.include and coverage.exclude #9426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
70e0859
020faff
7d0747f
281c3fa
d25ca98
c013e42
c3348ed
c98cb54
8b2165f
f937b0a
c23a1ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,31 +149,45 @@ export class BaseCoverageProvider<Options extends ResolvedCoverageOptions<'istan | |
| const roots = root ? [root] : this.roots | ||
|
|
||
| const filename = slash(_filename) | ||
| const cacheHit = this.globCache.get(filename) | ||
| const cacheKey = root ? `${root}::${filename}` : filename | ||
| const cacheHit = this.globCache.get(cacheKey) | ||
|
|
||
| if (cacheHit !== undefined) { | ||
| return cacheHit | ||
| } | ||
|
|
||
| // File outside project root with default allowExternal | ||
| if (this.options.allowExternal === false && roots.every(root => !filename.startsWith(root))) { | ||
| this.globCache.set(filename, false) | ||
| const includeGlobs = this.options.include || '**' | ||
| const excludes = this.options.exclude | ||
|
|
||
| return false | ||
| } | ||
| for (const projectRoot of roots) { | ||
| const relativePath = slash(relative(projectRoot, filename)) | ||
| const isExternal = relativePath.startsWith('..') || path.isAbsolute(relativePath) | ||
|
|
||
| // By default `coverage.include` matches all files, except "coverage.exclude" | ||
| const glob = this.options.include || '**' | ||
| if (this.options.allowExternal === false && isExternal) { | ||
| continue | ||
| } | ||
|
|
||
| const included = pm.isMatch(filename, glob, { | ||
| contains: true, | ||
| dot: true, | ||
| ignore: this.options.exclude, | ||
| }) | ||
| const matchTarget = isExternal ? filename : relativePath | ||
|
|
||
| if (pm.isMatch(matchTarget, excludes, { dot: true })) { | ||
| continue | ||
| } | ||
|
|
||
| this.globCache.set(filename, included) | ||
| if (!isExternal) { | ||
| const absoluteExcludes = excludes.filter(pattern => path.isAbsolute(pattern)) | ||
| if (absoluteExcludes.length > 0 && pm.isMatch(filename, absoluteExcludes, { dot: true })) { | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| if (pm.isMatch(matchTarget, includeGlobs, { dot: true, contains: true })) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need 2x
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You’re right that we call pm.isMatch twice, but they serve different purposes and need distinct options: First call ( |
||
| this.globCache.set(cacheKey, true) | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return included | ||
| this.globCache.set(cacheKey, false) | ||
| return false | ||
| } | ||
|
|
||
| private async getUntestedFilesByRoot( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export function nestedLevel(n: number) { | ||
| return n * 2 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export function rootLevel(n: number) { | ||
| return n + 1 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { describe, expect, test } from 'vitest' | ||
| import { rootLevel } from '../src/root-level' | ||
| import { nestedLevel } from '../src/nested/nested-level' | ||
|
|
||
| describe('coverage include/exclude patterns', () => { | ||
| test('includes files from top-level', () => { | ||
| expect(rootLevel(5)).toBe(6) | ||
| }) | ||
|
|
||
| test('includes files from nested directories', () => { | ||
| expect(nestedLevel(5)).toBe(10) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this actually change how defined globs are interpreted when using
--projectfilter?root✅root❌This should show coverage for
packages/one, but it's missing:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will evaluate these cases.