Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 399ac68

Browse filesBrowse files
heathduttonaduh95
authored andcommitted
test_runner: fix coverage report when a directory is named file
The coverage tree traversal checked `tree[key].file` to detect file entries. When a directory named "file" contained a file also named "file", this check incorrectly matched the child entry instead of file metadata, causing a TypeError when accessing `.path`. Check for `.file?.path` instead to correctly identify file metadata. Fixes: #61080 PR-URL: #61169 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent 6e1beda commit 399ac68
Copy full SHA for 399ac68

4 files changed

+28-1Lines changed: 28 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/test_runner/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/utils.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ function getCoverageReport(pad, summary, symbol, color, table) {
551551

552552
function printCoverageBodyTree(tree, depth = 0) {
553553
for (const key in tree) {
554-
if (tree[key].file) {
554+
if (tree[key].file?.path) {
555555
const file = tree[key].file;
556556
const fileName = ArrayPrototypePop(StringPrototypeSplit(file.path, sep));
557557

Collapse file
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
module.exports.fn = function() {
3+
return 1;
4+
};
Collapse file
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
const { fn } = require('./file/file');
3+
const test = require('node:test');
4+
5+
test('coverage with file/file directory structure', () => {
6+
fn();
7+
});
Collapse file

‎test/parallel/test-runner-coverage.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-runner-coverage.js
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,19 @@ test('correctly prints the coverage report of files contained in parent director
550550
assert(result.stdout.toString().includes(report));
551551
assert.strictEqual(result.status, 0);
552552
});
553+
554+
// Regression test for https://github.com/nodejs/node/issues/61080
555+
test('coverage with directory and file named "file"', skipIfNoInspector, () => {
556+
const fixture = fixtures.path('test-runner', 'coverage-file-name', 'test.js');
557+
const args = [
558+
'--experimental-test-coverage',
559+
'--test-reporter',
560+
'tap',
561+
fixture,
562+
];
563+
const result = spawnSync(process.execPath, args);
564+
565+
assert.strictEqual(result.stderr.toString(), '');
566+
assert.strictEqual(result.status, 0);
567+
assert(result.stdout.toString().includes('start of coverage report'));
568+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.