Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,20 @@ class TestCoverage {
ObjectAssign(range, mapRangeToLines(range, lines));

if (isBlockCoverage) {
ArrayPrototypePush(branchReports, {
__proto__: null,
line: range.lines[0]?.line,
count: range.count,
});

if (range.count !== 0 ||
range.ignoredLines === range.lines.length) {
branchesCovered++;
// Skip branches that are entirely on ignored lines
Copy link
Member

Choose a reason for hiding this comment

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

related?

Copy link
Contributor

Choose a reason for hiding this comment

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

No that's from #61845

if (range.ignoredLines !== range.lines.length) {
ArrayPrototypePush(branchReports, {
__proto__: null,
line: range.lines[0]?.line,
count: range.count,
});

if (range.count !== 0) {
branchesCovered++;
}

totalBranches++;
}

totalBranches++;
}
}

Expand Down
15 changes: 12 additions & 3 deletions test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,18 @@
// On Windows, paths are case-insensitive, so we need to use case-insensitive
// regex replacement to handle cases where the drive letter case differs.
const flags = common.isWindows ? 'gi' : 'g';
const urlEncodedRegex = new RegExp(RegExp.escape(urlEncoded), flags);
const dirnameRegex = new RegExp(RegExp.escape(dirname), flags);
const winPathRegex = new RegExp(RegExp.escape(winPath), flags);

Check failure on line 111 in test/common/assertSnapshot.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
// Escape and add word boundaries to prevent partial matches
// (e.g., /node shouldn't match /node_modules or nodejs.org)
const escapedUrlEncoded = RegExp.escape(urlEncoded);
const escapedDirname = RegExp.escape(dirname);
const escapedWinPath = RegExp.escape(winPath);

Check failure on line 117 in test/common/assertSnapshot.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
// Use negative lookahead to prevent matching if followed by alphanumeric or underscore
const urlEncodedRegex = new RegExp(escapedUrlEncoded + '(?![\\w/])', flags);
const dirnameRegex = new RegExp(escapedDirname + '(?![\\w/])', flags);
const winPathRegex = new RegExp(escapedWinPath + '(?![\\w/])', flags);

Check failure on line 122 in test/common/assertSnapshot.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
return (str) => {
return str.replaceAll('\\\'', "'")
// Replace fileUrl first as `winPath` could be a substring of the fileUrl.
Expand Down
Loading