test_runner: match dotfiles in default coverage exclude - #63401
Conversation
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63401 +/- ##
==========================================
+ Coverage 90.23% 90.25% +0.02%
==========================================
Files 741 741
Lines 241194 241210 +16
Branches 45432 45430 -2
==========================================
+ Hits 217640 217704 +64
+ Misses 15129 15080 -49
- Partials 8425 8426 +1
🚀 New features to boost your workflow:
|
| @@ -403,7 +405,7 @@ function parseCommandLine() { | |||
| if (!coverageExcludeGlobs || coverageExcludeGlobs.length === 0) { | |||
| // TODO(pmarchini): this default should follow something similar to c8 defaults | |||
| // Default exclusions should be also exported to be used by other tools / users | |||
| coverageExcludeGlobs = [kDefaultPattern]; | |||
| coverageExcludeGlobs = [kDefaultPattern, kDefaultCoverageDotfilePattern]; | |||
There was a problem hiding this comment.
Can't we just set dot: true?
There was a problem hiding this comment.
Good catch — reverted to the dot: true approach (which the PR body originally described). Pushed as a follow-up fixup. This also makes user-supplied --test-coverage-exclude globs match dotfiles, which the extra default pattern wouldn't have covered.
d807464 to
b0e1f2c
Compare
The default coverage exclude globs did not match dotfiles, so test files such as `test/.foo.test.js` were incorrectly included in coverage reports. Apply the `dot: true` minimatch option when matching the relative path so the default exclude patterns cover dotfiles, while keeping plain matching for the absolute path to avoid misinterpreting dot segments in the filesystem path (e.g. tmp dirs like `test/.tmp.0`). Fixes: nodejs#63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com>
b0e1f2c to
8437db0
Compare
|
@avivkeller PTAL |
| function createCoverageMatcher(pattern) { | ||
| return { | ||
| __proto__: null, | ||
| relative: createMatcher(pattern, kMatchGlobPatternOptions), | ||
| absolute: createMatcher(pattern), | ||
| }; | ||
| } |
There was a problem hiding this comment.
Can't we pass the same options and thus and use the same matcher for both or no?
There was a problem hiding this comment.
Intentional — relative needs dot: true so the default exclude globs match project dotfiles like test/.foo.test.js (the point of this PR), but absolute deliberately leaves it off. Enabling dot: true there could make a glob unintentionally match a dot segment that shows up in the absolute path for unrelated reasons (e.g. an OS temp dir like test/.tmp.0), which isn't something the user's pattern was written to target.
There was a problem hiding this comment.
Shouldn't they be on par? As in, if we are changing this to include dots locally, wouldn't it make sense to also include them globally?
The default coverage exclude patterns ... (본문)
Fixes: #63397
Problem
node --experimental-test-coverageincludes dotfile test files (e.g.test/.foo.cjs) in the coverage report even though the default exclude patterns are intended to drop everything undertest/. Non-dotfile siblings are correctly excluded.This is caused by
matchGlobPatterncalling minimatch withoutdot: true; minimatch's default behavior is to not match dot-prefixed entries unless the pattern itself starts with a dot.Reported in #63397.
Fix
lib/internal/fs/glob.js: extendmatchGlobPatternwith an optionaloptionsargument forwarded to minimatch. Fixed options (nocase,windowsPathsNoEscape, etc.) still take precedence so callers cannot accidentally override them.lib/internal/test_runner/coverage.js: route the four exclude/include match calls through a small helper that passes{ dot: true }. Applied to both exclude and include for consistency.Test
Added a new scenario to
test-runner-coverage-default-exclusion.mjsthat runstest/.dotfile.cjsexplicitly and asserts the dotfile does not appear in the coverage report under the default exclude patterns. The new fixturetest/.dotfile.cjsexercises the samelogic-file.jsas the existing fixtures.Fixes: #63397