Commit 4de7e63

Browse files
semimikohaduh95
authored andcommitted
test_runner: match dotfiles in default coverage exclude
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: #63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63401 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent a77f9f7 commit 4de7e63

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

β€Žlib/internal/test_runner/coverage.jsβ€Ž

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4747
constkLineEndingRegex=/\r?\n$/u;
4848
constkLineSplitRegex=/(?<=\r?\n)/u;
4949
constkStatusRegex=/\/\*node:coverage(?<status>enable|disable)\*\//;
50+
// Match dotfiles (e.g. `test/.foo.js`) when applying coverage globs so the
51+
// default exclude patterns cover them.
52+
constkMatchGlobPatternOptions={__proto__: null,dot: true};
5053
constkTypeOnlyImportRegex=/^\s*import\s+type\b/u;
5154
constkTypeScriptSourceRegex=/\.(?:cts|mts|ts)$/u;
5255
constkSourceFileGlob='**/*.{cjs,cts,js,mjs,mts,ts}';
@@ -63,6 +66,14 @@ function getStripTypeScriptTypesForCoverage() {
6366
returnstripTypeScriptTypesForCoverage;
6467
}
6568

69+
functioncreateCoverageMatcher(pattern){
70+
return{
71+
__proto__: null,
72+
relative: createMatcher(pattern,kMatchGlobPatternOptions),
73+
absolute: createMatcher(pattern),
74+
};
75+
}
76+
6677
classCoverageLine{
6778
constructor(line,startOffset,src,length=src?.length){
6879
constnewlineLength=src==null ? 0 :
@@ -605,23 +616,28 @@ class TestCoverage {
605616
// TestCoverage instance, so compile each glob to a matcher once and reuse
606617
// it for every file. Building a fresh Minimatch per call (the previous
607618
// behavior) dominated the coverage report time, scaling with
608-
// files * globs.
619+
// files * globs. Each glob compiles to a matcher pair: `relative` enables
620+
// dot:true so globs match dotfiles within the project, while `absolute`
621+
// keeps the default behavior to avoid misinterpreting dot segments in the
622+
// absolute filesystem path (e.g. tmp dirs like `test/.tmp.0`).
609623
this.#excludeMatchers ??=ArrayPrototypeMap(
610-
this.options.coverageExcludeGlobs??[],(pattern)=>createMatcher(pattern));
624+
this.options.coverageExcludeGlobs??[],createCoverageMatcher);
611625
this.#includeMatchers ??=ArrayPrototypeMap(
612-
this.options.coverageIncludeGlobs??[],(pattern)=>createMatcher(pattern));
626+
this.options.coverageIncludeGlobs??[],createCoverageMatcher);
613627

614628
// This check filters out files that match the exclude globs.
615629
for(leti=0;i<this.#excludeMatchers.length;++i){
616630
constmatcher=this.#excludeMatchers[i];
617-
if(matcher.match(relativePath)||matcher.match(absolutePath))returntrue;
631+
if(matcher.relative.match(relativePath)||
632+
matcher.absolute.match(absolutePath))returntrue;
618633
}
619634

620635
// This check filters out files that do not match the include globs.
621636
if(this.#includeMatchers.length>0){
622637
for(leti=0;i<this.#includeMatchers.length;++i){
623638
constmatcher=this.#includeMatchers[i];
624-
if(matcher.match(relativePath)||matcher.match(absolutePath))returnfalse;
639+
if(matcher.relative.match(relativePath)||
640+
matcher.absolute.match(absolutePath))returnfalse;
625641
}
626642
returntrue;
627643
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
consttest=require('node:test');
2+
constassert=require('node:assert');
3+
const{ foo }=require('../logic-file.js');
4+
5+
test('foo returns 1 from a dotfile test',()=>{
6+
assert.strictEqual(foo(),1);
7+
});

β€Žtest/parallel/test-runner-coverage-default-exclusion.mjsβ€Ž

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ async function setupFixtures() {
1616
awaitcp(fixtureDir,tmpdir.path,{recursive: true});
1717
}
1818

19+
functionassertDefaultExclusions(stdout){
20+
assert.match(stdout,/#startofcoveragereport/);
21+
assert.doesNotMatch(stdout,/#file-test\.js\s+\|/);
22+
assert.doesNotMatch(stdout,/#file\.test\.mjs\s+\|/);
23+
assert.doesNotMatch(stdout,/#file\.test\.ts\s+\|/);
24+
assert.doesNotMatch(stdout,/#test\.cjs\s+\|/);
25+
assert.doesNotMatch(stdout,/#\s+not-matching-test-name\.js\s+\|/);
26+
assert.match(stdout,/#endofcoveragereport/);
27+
}
28+
1929
describe('test runner coverage default exclusion',skipIfNoInspector,()=>{
2030
before(async()=>{
2131
awaitsetupFixtures();
@@ -58,18 +68,6 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5868
});
5969

6070
it('should exclude test files from coverage by default',async()=>{
61-
constreport=[
62-
'# start of coverage report',
63-
'# --------------------------------------------------------------',
64-
'# file | line % | branch % | funcs % | uncovered lines',
65-
'# --------------------------------------------------------------',
66-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
67-
'# --------------------------------------------------------------',
68-
'# all files | 66.67 | 100.00 | 50.00 | ',
69-
'# --------------------------------------------------------------',
70-
'# end of coverage report',
71-
].join('\n');
72-
7371
constargs=[
7472
'--no-experimental-strip-types',
7573
'--test',
@@ -82,23 +80,11 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
8280
});
8381

8482
assert.strictEqual(result.stderr.toString(),'');
85-
assert(result.stdout.toString().includes(report));
83+
assertDefaultExclusions(result.stdout.toString());
8684
assert.strictEqual(result.status,0);
8785
});
8886

8987
it('should exclude ts test files',async()=>{
90-
constreport=[
91-
'# start of coverage report',
92-
'# --------------------------------------------------------------',
93-
'# file | line % | branch % | funcs % | uncovered lines',
94-
'# --------------------------------------------------------------',
95-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
96-
'# --------------------------------------------------------------',
97-
'# all files | 66.67 | 100.00 | 50.00 | ',
98-
'# --------------------------------------------------------------',
99-
'# end of coverage report',
100-
].join('\n');
101-
10288
constargs=[
10389
'--test',
10490
'--experimental-test-coverage',
@@ -111,7 +97,26 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
11197
});
11298

11399
assert.strictEqual(result.stderr.toString(),'');
114-
assert(result.stdout.toString().includes(report));
100+
assertDefaultExclusions(result.stdout.toString());
101+
assert.strictEqual(result.status,0);
102+
});
103+
104+
it('should exclude dotfile test files from coverage by default',async()=>{
105+
constargs=[
106+
'--no-experimental-strip-types',
107+
'--test',
108+
'--experimental-test-coverage',
109+
'--test-reporter=tap',
110+
'test/.dotfile.cjs',
111+
];
112+
constresult=spawnSync(process.execPath,args,{
113+
env: { ...process.env,NODE_TEST_TMPDIR: tmpdir.path},
114+
cwd: tmpdir.path
115+
});
116+
117+
assert.strictEqual(result.stderr.toString(),'');
118+
assertDefaultExclusions(result.stdout.toString());
119+
assert.doesNotMatch(result.stdout.toString(),/#\s+\.dotfile\.cjs\s+\|/);
115120
assert.strictEqual(result.status,0);
116121
});
117122
});

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 4de7e63

Browse files
semimikohaduh95
authored andcommitted
test_runner: match dotfiles in default coverage exclude
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: #63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63401 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent a77f9f7 commit 4de7e63

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

β€Žlib/internal/test_runner/coverage.jsβ€Ž

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4747
constkLineEndingRegex=/\r?\n$/u;
4848
constkLineSplitRegex=/(?<=\r?\n)/u;
4949
constkStatusRegex=/\/\*node:coverage(?<status>enable|disable)\*\//;
50+
// Match dotfiles (e.g. `test/.foo.js`) when applying coverage globs so the
51+
// default exclude patterns cover them.
52+
constkMatchGlobPatternOptions={__proto__: null,dot: true};
5053
constkTypeOnlyImportRegex=/^\s*import\s+type\b/u;
5154
constkTypeScriptSourceRegex=/\.(?:cts|mts|ts)$/u;
5255
constkSourceFileGlob='**/*.{cjs,cts,js,mjs,mts,ts}';
@@ -63,6 +66,14 @@ function getStripTypeScriptTypesForCoverage() {
6366
returnstripTypeScriptTypesForCoverage;
6467
}
6568

69+
functioncreateCoverageMatcher(pattern){
70+
return{
71+
__proto__: null,
72+
relative: createMatcher(pattern,kMatchGlobPatternOptions),
73+
absolute: createMatcher(pattern),
74+
};
75+
}
76+
6677
classCoverageLine{
6778
constructor(line,startOffset,src,length=src?.length){
6879
constnewlineLength=src==null ? 0 :
@@ -605,23 +616,28 @@ class TestCoverage {
605616
// TestCoverage instance, so compile each glob to a matcher once and reuse
606617
// it for every file. Building a fresh Minimatch per call (the previous
607618
// behavior) dominated the coverage report time, scaling with
608-
// files * globs.
619+
// files * globs. Each glob compiles to a matcher pair: `relative` enables
620+
// dot:true so globs match dotfiles within the project, while `absolute`
621+
// keeps the default behavior to avoid misinterpreting dot segments in the
622+
// absolute filesystem path (e.g. tmp dirs like `test/.tmp.0`).
609623
this.#excludeMatchers ??=ArrayPrototypeMap(
610-
this.options.coverageExcludeGlobs??[],(pattern)=>createMatcher(pattern));
624+
this.options.coverageExcludeGlobs??[],createCoverageMatcher);
611625
this.#includeMatchers ??=ArrayPrototypeMap(
612-
this.options.coverageIncludeGlobs??[],(pattern)=>createMatcher(pattern));
626+
this.options.coverageIncludeGlobs??[],createCoverageMatcher);
613627

614628
// This check filters out files that match the exclude globs.
615629
for(leti=0;i<this.#excludeMatchers.length;++i){
616630
constmatcher=this.#excludeMatchers[i];
617-
if(matcher.match(relativePath)||matcher.match(absolutePath))returntrue;
631+
if(matcher.relative.match(relativePath)||
632+
matcher.absolute.match(absolutePath))returntrue;
618633
}
619634

620635
// This check filters out files that do not match the include globs.
621636
if(this.#includeMatchers.length>0){
622637
for(leti=0;i<this.#includeMatchers.length;++i){
623638
constmatcher=this.#includeMatchers[i];
624-
if(matcher.match(relativePath)||matcher.match(absolutePath))returnfalse;
639+
if(matcher.relative.match(relativePath)||
640+
matcher.absolute.match(absolutePath))returnfalse;
625641
}
626642
returntrue;
627643
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
consttest=require('node:test');
2+
constassert=require('node:assert');
3+
const{ foo }=require('../logic-file.js');
4+
5+
test('foo returns 1 from a dotfile test',()=>{
6+
assert.strictEqual(foo(),1);
7+
});

β€Žtest/parallel/test-runner-coverage-default-exclusion.mjsβ€Ž

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ async function setupFixtures() {
1616
awaitcp(fixtureDir,tmpdir.path,{recursive: true});
1717
}
1818

19+
functionassertDefaultExclusions(stdout){
20+
assert.match(stdout,/#startofcoveragereport/);
21+
assert.doesNotMatch(stdout,/#file-test\.js\s+\|/);
22+
assert.doesNotMatch(stdout,/#file\.test\.mjs\s+\|/);
23+
assert.doesNotMatch(stdout,/#file\.test\.ts\s+\|/);
24+
assert.doesNotMatch(stdout,/#test\.cjs\s+\|/);
25+
assert.doesNotMatch(stdout,/#\s+not-matching-test-name\.js\s+\|/);
26+
assert.match(stdout,/#endofcoveragereport/);
27+
}
28+
1929
describe('test runner coverage default exclusion',skipIfNoInspector,()=>{
2030
before(async()=>{
2131
awaitsetupFixtures();
@@ -58,18 +68,6 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5868
});
5969

6070
it('should exclude test files from coverage by default',async()=>{
61-
constreport=[
62-
'# start of coverage report',
63-
'# --------------------------------------------------------------',
64-
'# file | line % | branch % | funcs % | uncovered lines',
65-
'# --------------------------------------------------------------',
66-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
67-
'# --------------------------------------------------------------',
68-
'# all files | 66.67 | 100.00 | 50.00 | ',
69-
'# --------------------------------------------------------------',
70-
'# end of coverage report',
71-
].join('\n');
72-
7371
constargs=[
7472
'--no-experimental-strip-types',
7573
'--test',
@@ -82,23 +80,11 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
8280
});
8381

8482
assert.strictEqual(result.stderr.toString(),'');
85-
assert(result.stdout.toString().includes(report));
83+
assertDefaultExclusions(result.stdout.toString());
8684
assert.strictEqual(result.status,0);
8785
});
8886

8987
it('should exclude ts test files',async()=>{
90-
constreport=[
91-
'# start of coverage report',
92-
'# --------------------------------------------------------------',
93-
'# file | line % | branch % | funcs % | uncovered lines',
94-
'# --------------------------------------------------------------',
95-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
96-
'# --------------------------------------------------------------',
97-
'# all files | 66.67 | 100.00 | 50.00 | ',
98-
'# --------------------------------------------------------------',
99-
'# end of coverage report',
100-
].join('\n');
101-
10288
constargs=[
10389
'--test',
10490
'--experimental-test-coverage',
@@ -111,7 +97,26 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
11197
});
11298

11399
assert.strictEqual(result.stderr.toString(),'');
114-
assert(result.stdout.toString().includes(report));
100+
assertDefaultExclusions(result.stdout.toString());
101+
assert.strictEqual(result.status,0);
102+
});
103+
104+
it('should exclude dotfile test files from coverage by default',async()=>{
105+
constargs=[
106+
'--no-experimental-strip-types',
107+
'--test',
108+
'--experimental-test-coverage',
109+
'--test-reporter=tap',
110+
'test/.dotfile.cjs',
111+
];
112+
constresult=spawnSync(process.execPath,args,{
113+
env: { ...process.env,NODE_TEST_TMPDIR: tmpdir.path},
114+
cwd: tmpdir.path
115+
});
116+
117+
assert.strictEqual(result.stderr.toString(),'');
118+
assertDefaultExclusions(result.stdout.toString());
119+
assert.doesNotMatch(result.stdout.toString(),/#\s+\.dotfile\.cjs\s+\|/);
115120
assert.strictEqual(result.status,0);
116121
});
117122
});

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 4de7e63

Browse files
semimikohaduh95
authored andcommitted
test_runner: match dotfiles in default coverage exclude
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: #63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63401 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent a77f9f7 commit 4de7e63

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

β€Žlib/internal/test_runner/coverage.jsβ€Ž

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4747
constkLineEndingRegex=/\r?\n$/u;
4848
constkLineSplitRegex=/(?<=\r?\n)/u;
4949
constkStatusRegex=/\/\*node:coverage(?<status>enable|disable)\*\//;
50+
// Match dotfiles (e.g. `test/.foo.js`) when applying coverage globs so the
51+
// default exclude patterns cover them.
52+
constkMatchGlobPatternOptions={__proto__: null,dot: true};
5053
constkTypeOnlyImportRegex=/^\s*import\s+type\b/u;
5154
constkTypeScriptSourceRegex=/\.(?:cts|mts|ts)$/u;
5255
constkSourceFileGlob='**/*.{cjs,cts,js,mjs,mts,ts}';
@@ -63,6 +66,14 @@ function getStripTypeScriptTypesForCoverage() {
6366
returnstripTypeScriptTypesForCoverage;
6467
}
6568

69+
functioncreateCoverageMatcher(pattern){
70+
return{
71+
__proto__: null,
72+
relative: createMatcher(pattern,kMatchGlobPatternOptions),
73+
absolute: createMatcher(pattern),
74+
};
75+
}
76+
6677
classCoverageLine{
6778
constructor(line,startOffset,src,length=src?.length){
6879
constnewlineLength=src==null ? 0 :
@@ -605,23 +616,28 @@ class TestCoverage {
605616
// TestCoverage instance, so compile each glob to a matcher once and reuse
606617
// it for every file. Building a fresh Minimatch per call (the previous
607618
// behavior) dominated the coverage report time, scaling with
608-
// files * globs.
619+
// files * globs. Each glob compiles to a matcher pair: `relative` enables
620+
// dot:true so globs match dotfiles within the project, while `absolute`
621+
// keeps the default behavior to avoid misinterpreting dot segments in the
622+
// absolute filesystem path (e.g. tmp dirs like `test/.tmp.0`).
609623
this.#excludeMatchers ??=ArrayPrototypeMap(
610-
this.options.coverageExcludeGlobs??[],(pattern)=>createMatcher(pattern));
624+
this.options.coverageExcludeGlobs??[],createCoverageMatcher);
611625
this.#includeMatchers ??=ArrayPrototypeMap(
612-
this.options.coverageIncludeGlobs??[],(pattern)=>createMatcher(pattern));
626+
this.options.coverageIncludeGlobs??[],createCoverageMatcher);
613627

614628
// This check filters out files that match the exclude globs.
615629
for(leti=0;i<this.#excludeMatchers.length;++i){
616630
constmatcher=this.#excludeMatchers[i];
617-
if(matcher.match(relativePath)||matcher.match(absolutePath))returntrue;
631+
if(matcher.relative.match(relativePath)||
632+
matcher.absolute.match(absolutePath))returntrue;
618633
}
619634

620635
// This check filters out files that do not match the include globs.
621636
if(this.#includeMatchers.length>0){
622637
for(leti=0;i<this.#includeMatchers.length;++i){
623638
constmatcher=this.#includeMatchers[i];
624-
if(matcher.match(relativePath)||matcher.match(absolutePath))returnfalse;
639+
if(matcher.relative.match(relativePath)||
640+
matcher.absolute.match(absolutePath))returnfalse;
625641
}
626642
returntrue;
627643
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
consttest=require('node:test');
2+
constassert=require('node:assert');
3+
const{ foo }=require('../logic-file.js');
4+
5+
test('foo returns 1 from a dotfile test',()=>{
6+
assert.strictEqual(foo(),1);
7+
});

β€Žtest/parallel/test-runner-coverage-default-exclusion.mjsβ€Ž

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ async function setupFixtures() {
1616
awaitcp(fixtureDir,tmpdir.path,{recursive: true});
1717
}
1818

19+
functionassertDefaultExclusions(stdout){
20+
assert.match(stdout,/#startofcoveragereport/);
21+
assert.doesNotMatch(stdout,/#file-test\.js\s+\|/);
22+
assert.doesNotMatch(stdout,/#file\.test\.mjs\s+\|/);
23+
assert.doesNotMatch(stdout,/#file\.test\.ts\s+\|/);
24+
assert.doesNotMatch(stdout,/#test\.cjs\s+\|/);
25+
assert.doesNotMatch(stdout,/#\s+not-matching-test-name\.js\s+\|/);
26+
assert.match(stdout,/#endofcoveragereport/);
27+
}
28+
1929
describe('test runner coverage default exclusion',skipIfNoInspector,()=>{
2030
before(async()=>{
2131
awaitsetupFixtures();
@@ -58,18 +68,6 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5868
});
5969

6070
it('should exclude test files from coverage by default',async()=>{
61-
constreport=[
62-
'# start of coverage report',
63-
'# --------------------------------------------------------------',
64-
'# file | line % | branch % | funcs % | uncovered lines',
65-
'# --------------------------------------------------------------',
66-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
67-
'# --------------------------------------------------------------',
68-
'# all files | 66.67 | 100.00 | 50.00 | ',
69-
'# --------------------------------------------------------------',
70-
'# end of coverage report',
71-
].join('\n');
72-
7371
constargs=[
7472
'--no-experimental-strip-types',
7573
'--test',
@@ -82,23 +80,11 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
8280
});
8381

8482
assert.strictEqual(result.stderr.toString(),'');
85-
assert(result.stdout.toString().includes(report));
83+
assertDefaultExclusions(result.stdout.toString());
8684
assert.strictEqual(result.status,0);
8785
});
8886

8987
it('should exclude ts test files',async()=>{
90-
constreport=[
91-
'# start of coverage report',
92-
'# --------------------------------------------------------------',
93-
'# file | line % | branch % | funcs % | uncovered lines',
94-
'# --------------------------------------------------------------',
95-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
96-
'# --------------------------------------------------------------',
97-
'# all files | 66.67 | 100.00 | 50.00 | ',
98-
'# --------------------------------------------------------------',
99-
'# end of coverage report',
100-
].join('\n');
101-
10288
constargs=[
10389
'--test',
10490
'--experimental-test-coverage',
@@ -111,7 +97,26 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
11197
});
11298

11399
assert.strictEqual(result.stderr.toString(),'');
114-
assert(result.stdout.toString().includes(report));
100+
assertDefaultExclusions(result.stdout.toString());
101+
assert.strictEqual(result.status,0);
102+
});
103+
104+
it('should exclude dotfile test files from coverage by default',async()=>{
105+
constargs=[
106+
'--no-experimental-strip-types',
107+
'--test',
108+
'--experimental-test-coverage',
109+
'--test-reporter=tap',
110+
'test/.dotfile.cjs',
111+
];
112+
constresult=spawnSync(process.execPath,args,{
113+
env: { ...process.env,NODE_TEST_TMPDIR: tmpdir.path},
114+
cwd: tmpdir.path
115+
});
116+
117+
assert.strictEqual(result.stderr.toString(),'');
118+
assertDefaultExclusions(result.stdout.toString());
119+
assert.doesNotMatch(result.stdout.toString(),/#\s+\.dotfile\.cjs\s+\|/);
115120
assert.strictEqual(result.status,0);
116121
});
117122
});

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 4de7e63

Browse files
semimikohaduh95
authored andcommitted
test_runner: match dotfiles in default coverage exclude
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: #63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63401 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent a77f9f7 commit 4de7e63

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

β€Žlib/internal/test_runner/coverage.jsβ€Ž

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4747
constkLineEndingRegex=/\r?\n$/u;
4848
constkLineSplitRegex=/(?<=\r?\n)/u;
4949
constkStatusRegex=/\/\*node:coverage(?<status>enable|disable)\*\//;
50+
// Match dotfiles (e.g. `test/.foo.js`) when applying coverage globs so the
51+
// default exclude patterns cover them.
52+
constkMatchGlobPatternOptions={__proto__: null,dot: true};
5053
constkTypeOnlyImportRegex=/^\s*import\s+type\b/u;
5154
constkTypeScriptSourceRegex=/\.(?:cts|mts|ts)$/u;
5255
constkSourceFileGlob='**/*.{cjs,cts,js,mjs,mts,ts}';
@@ -63,6 +66,14 @@ function getStripTypeScriptTypesForCoverage() {
6366
returnstripTypeScriptTypesForCoverage;
6467
}
6568

69+
functioncreateCoverageMatcher(pattern){
70+
return{
71+
__proto__: null,
72+
relative: createMatcher(pattern,kMatchGlobPatternOptions),
73+
absolute: createMatcher(pattern),
74+
};
75+
}
76+
6677
classCoverageLine{
6778
constructor(line,startOffset,src,length=src?.length){
6879
constnewlineLength=src==null ? 0 :
@@ -605,23 +616,28 @@ class TestCoverage {
605616
// TestCoverage instance, so compile each glob to a matcher once and reuse
606617
// it for every file. Building a fresh Minimatch per call (the previous
607618
// behavior) dominated the coverage report time, scaling with
608-
// files * globs.
619+
// files * globs. Each glob compiles to a matcher pair: `relative` enables
620+
// dot:true so globs match dotfiles within the project, while `absolute`
621+
// keeps the default behavior to avoid misinterpreting dot segments in the
622+
// absolute filesystem path (e.g. tmp dirs like `test/.tmp.0`).
609623
this.#excludeMatchers ??=ArrayPrototypeMap(
610-
this.options.coverageExcludeGlobs??[],(pattern)=>createMatcher(pattern));
624+
this.options.coverageExcludeGlobs??[],createCoverageMatcher);
611625
this.#includeMatchers ??=ArrayPrototypeMap(
612-
this.options.coverageIncludeGlobs??[],(pattern)=>createMatcher(pattern));
626+
this.options.coverageIncludeGlobs??[],createCoverageMatcher);
613627

614628
// This check filters out files that match the exclude globs.
615629
for(leti=0;i<this.#excludeMatchers.length;++i){
616630
constmatcher=this.#excludeMatchers[i];
617-
if(matcher.match(relativePath)||matcher.match(absolutePath))returntrue;
631+
if(matcher.relative.match(relativePath)||
632+
matcher.absolute.match(absolutePath))returntrue;
618633
}
619634

620635
// This check filters out files that do not match the include globs.
621636
if(this.#includeMatchers.length>0){
622637
for(leti=0;i<this.#includeMatchers.length;++i){
623638
constmatcher=this.#includeMatchers[i];
624-
if(matcher.match(relativePath)||matcher.match(absolutePath))returnfalse;
639+
if(matcher.relative.match(relativePath)||
640+
matcher.absolute.match(absolutePath))returnfalse;
625641
}
626642
returntrue;
627643
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
consttest=require('node:test');
2+
constassert=require('node:assert');
3+
const{ foo }=require('../logic-file.js');
4+
5+
test('foo returns 1 from a dotfile test',()=>{
6+
assert.strictEqual(foo(),1);
7+
});

β€Žtest/parallel/test-runner-coverage-default-exclusion.mjsβ€Ž

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ async function setupFixtures() {
1616
awaitcp(fixtureDir,tmpdir.path,{recursive: true});
1717
}
1818

19+
functionassertDefaultExclusions(stdout){
20+
assert.match(stdout,/#startofcoveragereport/);
21+
assert.doesNotMatch(stdout,/#file-test\.js\s+\|/);
22+
assert.doesNotMatch(stdout,/#file\.test\.mjs\s+\|/);
23+
assert.doesNotMatch(stdout,/#file\.test\.ts\s+\|/);
24+
assert.doesNotMatch(stdout,/#test\.cjs\s+\|/);
25+
assert.doesNotMatch(stdout,/#\s+not-matching-test-name\.js\s+\|/);
26+
assert.match(stdout,/#endofcoveragereport/);
27+
}
28+
1929
describe('test runner coverage default exclusion',skipIfNoInspector,()=>{
2030
before(async()=>{
2131
awaitsetupFixtures();
@@ -58,18 +68,6 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5868
});
5969

6070
it('should exclude test files from coverage by default',async()=>{
61-
constreport=[
62-
'# start of coverage report',
63-
'# --------------------------------------------------------------',
64-
'# file | line % | branch % | funcs % | uncovered lines',
65-
'# --------------------------------------------------------------',
66-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
67-
'# --------------------------------------------------------------',
68-
'# all files | 66.67 | 100.00 | 50.00 | ',
69-
'# --------------------------------------------------------------',
70-
'# end of coverage report',
71-
].join('\n');
72-
7371
constargs=[
7472
'--no-experimental-strip-types',
7573
'--test',
@@ -82,23 +80,11 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
8280
});
8381

8482
assert.strictEqual(result.stderr.toString(),'');
85-
assert(result.stdout.toString().includes(report));
83+
assertDefaultExclusions(result.stdout.toString());
8684
assert.strictEqual(result.status,0);
8785
});
8886

8987
it('should exclude ts test files',async()=>{
90-
constreport=[
91-
'# start of coverage report',
92-
'# --------------------------------------------------------------',
93-
'# file | line % | branch % | funcs % | uncovered lines',
94-
'# --------------------------------------------------------------',
95-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
96-
'# --------------------------------------------------------------',
97-
'# all files | 66.67 | 100.00 | 50.00 | ',
98-
'# --------------------------------------------------------------',
99-
'# end of coverage report',
100-
].join('\n');
101-
10288
constargs=[
10389
'--test',
10490
'--experimental-test-coverage',
@@ -111,7 +97,26 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
11197
});
11298

11399
assert.strictEqual(result.stderr.toString(),'');
114-
assert(result.stdout.toString().includes(report));
100+
assertDefaultExclusions(result.stdout.toString());
101+
assert.strictEqual(result.status,0);
102+
});
103+
104+
it('should exclude dotfile test files from coverage by default',async()=>{
105+
constargs=[
106+
'--no-experimental-strip-types',
107+
'--test',
108+
'--experimental-test-coverage',
109+
'--test-reporter=tap',
110+
'test/.dotfile.cjs',
111+
];
112+
constresult=spawnSync(process.execPath,args,{
113+
env: { ...process.env,NODE_TEST_TMPDIR: tmpdir.path},
114+
cwd: tmpdir.path
115+
});
116+
117+
assert.strictEqual(result.stderr.toString(),'');
118+
assertDefaultExclusions(result.stdout.toString());
119+
assert.doesNotMatch(result.stdout.toString(),/#\s+\.dotfile\.cjs\s+\|/);
115120
assert.strictEqual(result.status,0);
116121
});
117122
});

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 4de7e63

Browse files
semimikohaduh95
authored andcommitted
test_runner: match dotfiles in default coverage exclude
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: #63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63401 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent a77f9f7 commit 4de7e63

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

β€Žlib/internal/test_runner/coverage.jsβ€Ž

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4747
constkLineEndingRegex=/\r?\n$/u;
4848
constkLineSplitRegex=/(?<=\r?\n)/u;
4949
constkStatusRegex=/\/\*node:coverage(?<status>enable|disable)\*\//;
50+
// Match dotfiles (e.g. `test/.foo.js`) when applying coverage globs so the
51+
// default exclude patterns cover them.
52+
constkMatchGlobPatternOptions={__proto__: null,dot: true};
5053
constkTypeOnlyImportRegex=/^\s*import\s+type\b/u;
5154
constkTypeScriptSourceRegex=/\.(?:cts|mts|ts)$/u;
5255
constkSourceFileGlob='**/*.{cjs,cts,js,mjs,mts,ts}';
@@ -63,6 +66,14 @@ function getStripTypeScriptTypesForCoverage() {
6366
returnstripTypeScriptTypesForCoverage;
6467
}
6568

69+
functioncreateCoverageMatcher(pattern){
70+
return{
71+
__proto__: null,
72+
relative: createMatcher(pattern,kMatchGlobPatternOptions),
73+
absolute: createMatcher(pattern),
74+
};
75+
}
76+
6677
classCoverageLine{
6778
constructor(line,startOffset,src,length=src?.length){
6879
constnewlineLength=src==null ? 0 :
@@ -605,23 +616,28 @@ class TestCoverage {
605616
// TestCoverage instance, so compile each glob to a matcher once and reuse
606617
// it for every file. Building a fresh Minimatch per call (the previous
607618
// behavior) dominated the coverage report time, scaling with
608-
// files * globs.
619+
// files * globs. Each glob compiles to a matcher pair: `relative` enables
620+
// dot:true so globs match dotfiles within the project, while `absolute`
621+
// keeps the default behavior to avoid misinterpreting dot segments in the
622+
// absolute filesystem path (e.g. tmp dirs like `test/.tmp.0`).
609623
this.#excludeMatchers ??=ArrayPrototypeMap(
610-
this.options.coverageExcludeGlobs??[],(pattern)=>createMatcher(pattern));
624+
this.options.coverageExcludeGlobs??[],createCoverageMatcher);
611625
this.#includeMatchers ??=ArrayPrototypeMap(
612-
this.options.coverageIncludeGlobs??[],(pattern)=>createMatcher(pattern));
626+
this.options.coverageIncludeGlobs??[],createCoverageMatcher);
613627

614628
// This check filters out files that match the exclude globs.
615629
for(leti=0;i<this.#excludeMatchers.length;++i){
616630
constmatcher=this.#excludeMatchers[i];
617-
if(matcher.match(relativePath)||matcher.match(absolutePath))returntrue;
631+
if(matcher.relative.match(relativePath)||
632+
matcher.absolute.match(absolutePath))returntrue;
618633
}
619634

620635
// This check filters out files that do not match the include globs.
621636
if(this.#includeMatchers.length>0){
622637
for(leti=0;i<this.#includeMatchers.length;++i){
623638
constmatcher=this.#includeMatchers[i];
624-
if(matcher.match(relativePath)||matcher.match(absolutePath))returnfalse;
639+
if(matcher.relative.match(relativePath)||
640+
matcher.absolute.match(absolutePath))returnfalse;
625641
}
626642
returntrue;
627643
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
consttest=require('node:test');
2+
constassert=require('node:assert');
3+
const{ foo }=require('../logic-file.js');
4+
5+
test('foo returns 1 from a dotfile test',()=>{
6+
assert.strictEqual(foo(),1);
7+
});

β€Žtest/parallel/test-runner-coverage-default-exclusion.mjsβ€Ž

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ async function setupFixtures() {
1616
awaitcp(fixtureDir,tmpdir.path,{recursive: true});
1717
}
1818

19+
functionassertDefaultExclusions(stdout){
20+
assert.match(stdout,/#startofcoveragereport/);
21+
assert.doesNotMatch(stdout,/#file-test\.js\s+\|/);
22+
assert.doesNotMatch(stdout,/#file\.test\.mjs\s+\|/);
23+
assert.doesNotMatch(stdout,/#file\.test\.ts\s+\|/);
24+
assert.doesNotMatch(stdout,/#test\.cjs\s+\|/);
25+
assert.doesNotMatch(stdout,/#\s+not-matching-test-name\.js\s+\|/);
26+
assert.match(stdout,/#endofcoveragereport/);
27+
}
28+
1929
describe('test runner coverage default exclusion',skipIfNoInspector,()=>{
2030
before(async()=>{
2131
awaitsetupFixtures();
@@ -58,18 +68,6 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5868
});
5969

6070
it('should exclude test files from coverage by default',async()=>{
61-
constreport=[
62-
'# start of coverage report',
63-
'# --------------------------------------------------------------',
64-
'# file | line % | branch % | funcs % | uncovered lines',
65-
'# --------------------------------------------------------------',
66-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
67-
'# --------------------------------------------------------------',
68-
'# all files | 66.67 | 100.00 | 50.00 | ',
69-
'# --------------------------------------------------------------',
70-
'# end of coverage report',
71-
].join('\n');
72-
7371
constargs=[
7472
'--no-experimental-strip-types',
7573
'--test',
@@ -82,23 +80,11 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
8280
});
8381

8482
assert.strictEqual(result.stderr.toString(),'');
85-
assert(result.stdout.toString().includes(report));
83+
assertDefaultExclusions(result.stdout.toString());
8684
assert.strictEqual(result.status,0);
8785
});
8886

8987
it('should exclude ts test files',async()=>{
90-
constreport=[
91-
'# start of coverage report',
92-
'# --------------------------------------------------------------',
93-
'# file | line % | branch % | funcs % | uncovered lines',
94-
'# --------------------------------------------------------------',
95-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
96-
'# --------------------------------------------------------------',
97-
'# all files | 66.67 | 100.00 | 50.00 | ',
98-
'# --------------------------------------------------------------',
99-
'# end of coverage report',
100-
].join('\n');
101-
10288
constargs=[
10389
'--test',
10490
'--experimental-test-coverage',
@@ -111,7 +97,26 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
11197
});
11298

11399
assert.strictEqual(result.stderr.toString(),'');
114-
assert(result.stdout.toString().includes(report));
100+
assertDefaultExclusions(result.stdout.toString());
101+
assert.strictEqual(result.status,0);
102+
});
103+
104+
it('should exclude dotfile test files from coverage by default',async()=>{
105+
constargs=[
106+
'--no-experimental-strip-types',
107+
'--test',
108+
'--experimental-test-coverage',
109+
'--test-reporter=tap',
110+
'test/.dotfile.cjs',
111+
];
112+
constresult=spawnSync(process.execPath,args,{
113+
env: { ...process.env,NODE_TEST_TMPDIR: tmpdir.path},
114+
cwd: tmpdir.path
115+
});
116+
117+
assert.strictEqual(result.stderr.toString(),'');
118+
assertDefaultExclusions(result.stdout.toString());
119+
assert.doesNotMatch(result.stdout.toString(),/#\s+\.dotfile\.cjs\s+\|/);
115120
assert.strictEqual(result.status,0);
116121
});
117122
});

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 4de7e63

Browse files
semimikohaduh95
authored andcommitted
test_runner: match dotfiles in default coverage exclude
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: #63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63401 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent a77f9f7 commit 4de7e63

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

β€Žlib/internal/test_runner/coverage.jsβ€Ž

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4747
constkLineEndingRegex=/\r?\n$/u;
4848
constkLineSplitRegex=/(?<=\r?\n)/u;
4949
constkStatusRegex=/\/\*node:coverage(?<status>enable|disable)\*\//;
50+
// Match dotfiles (e.g. `test/.foo.js`) when applying coverage globs so the
51+
// default exclude patterns cover them.
52+
constkMatchGlobPatternOptions={__proto__: null,dot: true};
5053
constkTypeOnlyImportRegex=/^\s*import\s+type\b/u;
5154
constkTypeScriptSourceRegex=/\.(?:cts|mts|ts)$/u;
5255
constkSourceFileGlob='**/*.{cjs,cts,js,mjs,mts,ts}';
@@ -63,6 +66,14 @@ function getStripTypeScriptTypesForCoverage() {
6366
returnstripTypeScriptTypesForCoverage;
6467
}
6568

69+
functioncreateCoverageMatcher(pattern){
70+
return{
71+
__proto__: null,
72+
relative: createMatcher(pattern,kMatchGlobPatternOptions),
73+
absolute: createMatcher(pattern),
74+
};
75+
}
76+
6677
classCoverageLine{
6778
constructor(line,startOffset,src,length=src?.length){
6879
constnewlineLength=src==null ? 0 :
@@ -605,23 +616,28 @@ class TestCoverage {
605616
// TestCoverage instance, so compile each glob to a matcher once and reuse
606617
// it for every file. Building a fresh Minimatch per call (the previous
607618
// behavior) dominated the coverage report time, scaling with
608-
// files * globs.
619+
// files * globs. Each glob compiles to a matcher pair: `relative` enables
620+
// dot:true so globs match dotfiles within the project, while `absolute`
621+
// keeps the default behavior to avoid misinterpreting dot segments in the
622+
// absolute filesystem path (e.g. tmp dirs like `test/.tmp.0`).
609623
this.#excludeMatchers ??=ArrayPrototypeMap(
610-
this.options.coverageExcludeGlobs??[],(pattern)=>createMatcher(pattern));
624+
this.options.coverageExcludeGlobs??[],createCoverageMatcher);
611625
this.#includeMatchers ??=ArrayPrototypeMap(
612-
this.options.coverageIncludeGlobs??[],(pattern)=>createMatcher(pattern));
626+
this.options.coverageIncludeGlobs??[],createCoverageMatcher);
613627

614628
// This check filters out files that match the exclude globs.
615629
for(leti=0;i<this.#excludeMatchers.length;++i){
616630
constmatcher=this.#excludeMatchers[i];
617-
if(matcher.match(relativePath)||matcher.match(absolutePath))returntrue;
631+
if(matcher.relative.match(relativePath)||
632+
matcher.absolute.match(absolutePath))returntrue;
618633
}
619634

620635
// This check filters out files that do not match the include globs.
621636
if(this.#includeMatchers.length>0){
622637
for(leti=0;i<this.#includeMatchers.length;++i){
623638
constmatcher=this.#includeMatchers[i];
624-
if(matcher.match(relativePath)||matcher.match(absolutePath))returnfalse;
639+
if(matcher.relative.match(relativePath)||
640+
matcher.absolute.match(absolutePath))returnfalse;
625641
}
626642
returntrue;
627643
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
consttest=require('node:test');
2+
constassert=require('node:assert');
3+
const{ foo }=require('../logic-file.js');
4+
5+
test('foo returns 1 from a dotfile test',()=>{
6+
assert.strictEqual(foo(),1);
7+
});

β€Žtest/parallel/test-runner-coverage-default-exclusion.mjsβ€Ž

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ async function setupFixtures() {
1616
awaitcp(fixtureDir,tmpdir.path,{recursive: true});
1717
}
1818

19+
functionassertDefaultExclusions(stdout){
20+
assert.match(stdout,/#startofcoveragereport/);
21+
assert.doesNotMatch(stdout,/#file-test\.js\s+\|/);
22+
assert.doesNotMatch(stdout,/#file\.test\.mjs\s+\|/);
23+
assert.doesNotMatch(stdout,/#file\.test\.ts\s+\|/);
24+
assert.doesNotMatch(stdout,/#test\.cjs\s+\|/);
25+
assert.doesNotMatch(stdout,/#\s+not-matching-test-name\.js\s+\|/);
26+
assert.match(stdout,/#endofcoveragereport/);
27+
}
28+
1929
describe('test runner coverage default exclusion',skipIfNoInspector,()=>{
2030
before(async()=>{
2131
awaitsetupFixtures();
@@ -58,18 +68,6 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5868
});
5969

6070
it('should exclude test files from coverage by default',async()=>{
61-
constreport=[
62-
'# start of coverage report',
63-
'# --------------------------------------------------------------',
64-
'# file | line % | branch % | funcs % | uncovered lines',
65-
'# --------------------------------------------------------------',
66-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
67-
'# --------------------------------------------------------------',
68-
'# all files | 66.67 | 100.00 | 50.00 | ',
69-
'# --------------------------------------------------------------',
70-
'# end of coverage report',
71-
].join('\n');
72-
7371
constargs=[
7472
'--no-experimental-strip-types',
7573
'--test',
@@ -82,23 +80,11 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
8280
});
8381

8482
assert.strictEqual(result.stderr.toString(),'');
85-
assert(result.stdout.toString().includes(report));
83+
assertDefaultExclusions(result.stdout.toString());
8684
assert.strictEqual(result.status,0);
8785
});
8886

8987
it('should exclude ts test files',async()=>{
90-
constreport=[
91-
'# start of coverage report',
92-
'# --------------------------------------------------------------',
93-
'# file | line % | branch % | funcs % | uncovered lines',
94-
'# --------------------------------------------------------------',
95-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
96-
'# --------------------------------------------------------------',
97-
'# all files | 66.67 | 100.00 | 50.00 | ',
98-
'# --------------------------------------------------------------',
99-
'# end of coverage report',
100-
].join('\n');
101-
10288
constargs=[
10389
'--test',
10490
'--experimental-test-coverage',
@@ -111,7 +97,26 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
11197
});
11298

11399
assert.strictEqual(result.stderr.toString(),'');
114-
assert(result.stdout.toString().includes(report));
100+
assertDefaultExclusions(result.stdout.toString());
101+
assert.strictEqual(result.status,0);
102+
});
103+
104+
it('should exclude dotfile test files from coverage by default',async()=>{
105+
constargs=[
106+
'--no-experimental-strip-types',
107+
'--test',
108+
'--experimental-test-coverage',
109+
'--test-reporter=tap',
110+
'test/.dotfile.cjs',
111+
];
112+
constresult=spawnSync(process.execPath,args,{
113+
env: { ...process.env,NODE_TEST_TMPDIR: tmpdir.path},
114+
cwd: tmpdir.path
115+
});
116+
117+
assert.strictEqual(result.stderr.toString(),'');
118+
assertDefaultExclusions(result.stdout.toString());
119+
assert.doesNotMatch(result.stdout.toString(),/#\s+\.dotfile\.cjs\s+\|/);
115120
assert.strictEqual(result.status,0);
116121
});
117122
});

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 4de7e63

Browse files
semimikohaduh95
authored andcommitted
test_runner: match dotfiles in default coverage exclude
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: #63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63401 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent a77f9f7 commit 4de7e63

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

β€Žlib/internal/test_runner/coverage.jsβ€Ž

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4747
constkLineEndingRegex=/\r?\n$/u;
4848
constkLineSplitRegex=/(?<=\r?\n)/u;
4949
constkStatusRegex=/\/\*node:coverage(?<status>enable|disable)\*\//;
50+
// Match dotfiles (e.g. `test/.foo.js`) when applying coverage globs so the
51+
// default exclude patterns cover them.
52+
constkMatchGlobPatternOptions={__proto__: null,dot: true};
5053
constkTypeOnlyImportRegex=/^\s*import\s+type\b/u;
5154
constkTypeScriptSourceRegex=/\.(?:cts|mts|ts)$/u;
5255
constkSourceFileGlob='**/*.{cjs,cts,js,mjs,mts,ts}';
@@ -63,6 +66,14 @@ function getStripTypeScriptTypesForCoverage() {
6366
returnstripTypeScriptTypesForCoverage;
6467
}
6568

69+
functioncreateCoverageMatcher(pattern){
70+
return{
71+
__proto__: null,
72+
relative: createMatcher(pattern,kMatchGlobPatternOptions),
73+
absolute: createMatcher(pattern),
74+
};
75+
}
76+
6677
classCoverageLine{
6778
constructor(line,startOffset,src,length=src?.length){
6879
constnewlineLength=src==null ? 0 :
@@ -605,23 +616,28 @@ class TestCoverage {
605616
// TestCoverage instance, so compile each glob to a matcher once and reuse
606617
// it for every file. Building a fresh Minimatch per call (the previous
607618
// behavior) dominated the coverage report time, scaling with
608-
// files * globs.
619+
// files * globs. Each glob compiles to a matcher pair: `relative` enables
620+
// dot:true so globs match dotfiles within the project, while `absolute`
621+
// keeps the default behavior to avoid misinterpreting dot segments in the
622+
// absolute filesystem path (e.g. tmp dirs like `test/.tmp.0`).
609623
this.#excludeMatchers ??=ArrayPrototypeMap(
610-
this.options.coverageExcludeGlobs??[],(pattern)=>createMatcher(pattern));
624+
this.options.coverageExcludeGlobs??[],createCoverageMatcher);
611625
this.#includeMatchers ??=ArrayPrototypeMap(
612-
this.options.coverageIncludeGlobs??[],(pattern)=>createMatcher(pattern));
626+
this.options.coverageIncludeGlobs??[],createCoverageMatcher);
613627

614628
// This check filters out files that match the exclude globs.
615629
for(leti=0;i<this.#excludeMatchers.length;++i){
616630
constmatcher=this.#excludeMatchers[i];
617-
if(matcher.match(relativePath)||matcher.match(absolutePath))returntrue;
631+
if(matcher.relative.match(relativePath)||
632+
matcher.absolute.match(absolutePath))returntrue;
618633
}
619634

620635
// This check filters out files that do not match the include globs.
621636
if(this.#includeMatchers.length>0){
622637
for(leti=0;i<this.#includeMatchers.length;++i){
623638
constmatcher=this.#includeMatchers[i];
624-
if(matcher.match(relativePath)||matcher.match(absolutePath))returnfalse;
639+
if(matcher.relative.match(relativePath)||
640+
matcher.absolute.match(absolutePath))returnfalse;
625641
}
626642
returntrue;
627643
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
consttest=require('node:test');
2+
constassert=require('node:assert');
3+
const{ foo }=require('../logic-file.js');
4+
5+
test('foo returns 1 from a dotfile test',()=>{
6+
assert.strictEqual(foo(),1);
7+
});

β€Žtest/parallel/test-runner-coverage-default-exclusion.mjsβ€Ž

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ async function setupFixtures() {
1616
awaitcp(fixtureDir,tmpdir.path,{recursive: true});
1717
}
1818

19+
functionassertDefaultExclusions(stdout){
20+
assert.match(stdout,/#startofcoveragereport/);
21+
assert.doesNotMatch(stdout,/#file-test\.js\s+\|/);
22+
assert.doesNotMatch(stdout,/#file\.test\.mjs\s+\|/);
23+
assert.doesNotMatch(stdout,/#file\.test\.ts\s+\|/);
24+
assert.doesNotMatch(stdout,/#test\.cjs\s+\|/);
25+
assert.doesNotMatch(stdout,/#\s+not-matching-test-name\.js\s+\|/);
26+
assert.match(stdout,/#endofcoveragereport/);
27+
}
28+
1929
describe('test runner coverage default exclusion',skipIfNoInspector,()=>{
2030
before(async()=>{
2131
awaitsetupFixtures();
@@ -58,18 +68,6 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5868
});
5969

6070
it('should exclude test files from coverage by default',async()=>{
61-
constreport=[
62-
'# start of coverage report',
63-
'# --------------------------------------------------------------',
64-
'# file | line % | branch % | funcs % | uncovered lines',
65-
'# --------------------------------------------------------------',
66-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
67-
'# --------------------------------------------------------------',
68-
'# all files | 66.67 | 100.00 | 50.00 | ',
69-
'# --------------------------------------------------------------',
70-
'# end of coverage report',
71-
].join('\n');
72-
7371
constargs=[
7472
'--no-experimental-strip-types',
7573
'--test',
@@ -82,23 +80,11 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
8280
});
8381

8482
assert.strictEqual(result.stderr.toString(),'');
85-
assert(result.stdout.toString().includes(report));
83+
assertDefaultExclusions(result.stdout.toString());
8684
assert.strictEqual(result.status,0);
8785
});
8886

8987
it('should exclude ts test files',async()=>{
90-
constreport=[
91-
'# start of coverage report',
92-
'# --------------------------------------------------------------',
93-
'# file | line % | branch % | funcs % | uncovered lines',
94-
'# --------------------------------------------------------------',
95-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
96-
'# --------------------------------------------------------------',
97-
'# all files | 66.67 | 100.00 | 50.00 | ',
98-
'# --------------------------------------------------------------',
99-
'# end of coverage report',
100-
].join('\n');
101-
10288
constargs=[
10389
'--test',
10490
'--experimental-test-coverage',
@@ -111,7 +97,26 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
11197
});
11298

11399
assert.strictEqual(result.stderr.toString(),'');
114-
assert(result.stdout.toString().includes(report));
100+
assertDefaultExclusions(result.stdout.toString());
101+
assert.strictEqual(result.status,0);
102+
});
103+
104+
it('should exclude dotfile test files from coverage by default',async()=>{
105+
constargs=[
106+
'--no-experimental-strip-types',
107+
'--test',
108+
'--experimental-test-coverage',
109+
'--test-reporter=tap',
110+
'test/.dotfile.cjs',
111+
];
112+
constresult=spawnSync(process.execPath,args,{
113+
env: { ...process.env,NODE_TEST_TMPDIR: tmpdir.path},
114+
cwd: tmpdir.path
115+
});
116+
117+
assert.strictEqual(result.stderr.toString(),'');
118+
assertDefaultExclusions(result.stdout.toString());
119+
assert.doesNotMatch(result.stdout.toString(),/#\s+\.dotfile\.cjs\s+\|/);
115120
assert.strictEqual(result.status,0);
116121
});
117122
});

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 4de7e63

Browse files
semimikohaduh95
authored andcommitted
test_runner: match dotfiles in default coverage exclude
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: #63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63401 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent a77f9f7 commit 4de7e63

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

β€Žlib/internal/test_runner/coverage.jsβ€Ž

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4747
constkLineEndingRegex=/\r?\n$/u;
4848
constkLineSplitRegex=/(?<=\r?\n)/u;
4949
constkStatusRegex=/\/\*node:coverage(?<status>enable|disable)\*\//;
50+
// Match dotfiles (e.g. `test/.foo.js`) when applying coverage globs so the
51+
// default exclude patterns cover them.
52+
constkMatchGlobPatternOptions={__proto__: null,dot: true};
5053
constkTypeOnlyImportRegex=/^\s*import\s+type\b/u;
5154
constkTypeScriptSourceRegex=/\.(?:cts|mts|ts)$/u;
5255
constkSourceFileGlob='**/*.{cjs,cts,js,mjs,mts,ts}';
@@ -63,6 +66,14 @@ function getStripTypeScriptTypesForCoverage() {
6366
returnstripTypeScriptTypesForCoverage;
6467
}
6568

69+
functioncreateCoverageMatcher(pattern){
70+
return{
71+
__proto__: null,
72+
relative: createMatcher(pattern,kMatchGlobPatternOptions),
73+
absolute: createMatcher(pattern),
74+
};
75+
}
76+
6677
classCoverageLine{
6778
constructor(line,startOffset,src,length=src?.length){
6879
constnewlineLength=src==null ? 0 :
@@ -605,23 +616,28 @@ class TestCoverage {
605616
// TestCoverage instance, so compile each glob to a matcher once and reuse
606617
// it for every file. Building a fresh Minimatch per call (the previous
607618
// behavior) dominated the coverage report time, scaling with
608-
// files * globs.
619+
// files * globs. Each glob compiles to a matcher pair: `relative` enables
620+
// dot:true so globs match dotfiles within the project, while `absolute`
621+
// keeps the default behavior to avoid misinterpreting dot segments in the
622+
// absolute filesystem path (e.g. tmp dirs like `test/.tmp.0`).
609623
this.#excludeMatchers ??=ArrayPrototypeMap(
610-
this.options.coverageExcludeGlobs??[],(pattern)=>createMatcher(pattern));
624+
this.options.coverageExcludeGlobs??[],createCoverageMatcher);
611625
this.#includeMatchers ??=ArrayPrototypeMap(
612-
this.options.coverageIncludeGlobs??[],(pattern)=>createMatcher(pattern));
626+
this.options.coverageIncludeGlobs??[],createCoverageMatcher);
613627

614628
// This check filters out files that match the exclude globs.
615629
for(leti=0;i<this.#excludeMatchers.length;++i){
616630
constmatcher=this.#excludeMatchers[i];
617-
if(matcher.match(relativePath)||matcher.match(absolutePath))returntrue;
631+
if(matcher.relative.match(relativePath)||
632+
matcher.absolute.match(absolutePath))returntrue;
618633
}
619634

620635
// This check filters out files that do not match the include globs.
621636
if(this.#includeMatchers.length>0){
622637
for(leti=0;i<this.#includeMatchers.length;++i){
623638
constmatcher=this.#includeMatchers[i];
624-
if(matcher.match(relativePath)||matcher.match(absolutePath))returnfalse;
639+
if(matcher.relative.match(relativePath)||
640+
matcher.absolute.match(absolutePath))returnfalse;
625641
}
626642
returntrue;
627643
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
consttest=require('node:test');
2+
constassert=require('node:assert');
3+
const{ foo }=require('../logic-file.js');
4+
5+
test('foo returns 1 from a dotfile test',()=>{
6+
assert.strictEqual(foo(),1);
7+
});

β€Žtest/parallel/test-runner-coverage-default-exclusion.mjsβ€Ž

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ async function setupFixtures() {
1616
awaitcp(fixtureDir,tmpdir.path,{recursive: true});
1717
}
1818

19+
functionassertDefaultExclusions(stdout){
20+
assert.match(stdout,/#startofcoveragereport/);
21+
assert.doesNotMatch(stdout,/#file-test\.js\s+\|/);
22+
assert.doesNotMatch(stdout,/#file\.test\.mjs\s+\|/);
23+
assert.doesNotMatch(stdout,/#file\.test\.ts\s+\|/);
24+
assert.doesNotMatch(stdout,/#test\.cjs\s+\|/);
25+
assert.doesNotMatch(stdout,/#\s+not-matching-test-name\.js\s+\|/);
26+
assert.match(stdout,/#endofcoveragereport/);
27+
}
28+
1929
describe('test runner coverage default exclusion',skipIfNoInspector,()=>{
2030
before(async()=>{
2131
awaitsetupFixtures();
@@ -58,18 +68,6 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5868
});
5969

6070
it('should exclude test files from coverage by default',async()=>{
61-
constreport=[
62-
'# start of coverage report',
63-
'# --------------------------------------------------------------',
64-
'# file | line % | branch % | funcs % | uncovered lines',
65-
'# --------------------------------------------------------------',
66-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
67-
'# --------------------------------------------------------------',
68-
'# all files | 66.67 | 100.00 | 50.00 | ',
69-
'# --------------------------------------------------------------',
70-
'# end of coverage report',
71-
].join('\n');
72-
7371
constargs=[
7472
'--no-experimental-strip-types',
7573
'--test',
@@ -82,23 +80,11 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
8280
});
8381

8482
assert.strictEqual(result.stderr.toString(),'');
85-
assert(result.stdout.toString().includes(report));
83+
assertDefaultExclusions(result.stdout.toString());
8684
assert.strictEqual(result.status,0);
8785
});
8886

8987
it('should exclude ts test files',async()=>{
90-
constreport=[
91-
'# start of coverage report',
92-
'# --------------------------------------------------------------',
93-
'# file | line % | branch % | funcs % | uncovered lines',
94-
'# --------------------------------------------------------------',
95-
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
96-
'# --------------------------------------------------------------',
97-
'# all files | 66.67 | 100.00 | 50.00 | ',
98-
'# --------------------------------------------------------------',
99-
'# end of coverage report',
100-
].join('\n');
101-
10288
constargs=[
10389
'--test',
10490
'--experimental-test-coverage',
@@ -111,7 +97,26 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
11197
});
11298

11399
assert.strictEqual(result.stderr.toString(),'');
114-
assert(result.stdout.toString().includes(report));
100+
assertDefaultExclusions(result.stdout.toString());
101+
assert.strictEqual(result.status,0);
102+
});
103+
104+
it('should exclude dotfile test files from coverage by default',async()=>{
105+
constargs=[
106+
'--no-experimental-strip-types',
107+
'--test',
108+
'--experimental-test-coverage',
109+
'--test-reporter=tap',
110+
'test/.dotfile.cjs',
111+
];
112+
constresult=spawnSync(process.execPath,args,{
113+
env: { ...process.env,NODE_TEST_TMPDIR: tmpdir.path},
114+
cwd: tmpdir.path
115+
});
116+
117+
assert.strictEqual(result.stderr.toString(),'');
118+
assertDefaultExclusions(result.stdout.toString());
119+
assert.doesNotMatch(result.stdout.toString(),/#\s+\.dotfile\.cjs\s+\|/);
115120
assert.strictEqual(result.status,0);
116121
});
117122
});

0 commit comments

Comments
Β (0)