Skip to content

Commit

Permalink
test_runner: support coverage of unnamed functions
Browse files Browse the repository at this point in the history
This commit updates the code coverage logic to skip the first
function in a file (which does not correspond to an actual
function) instead of skipping all functions without a name.

PR-URL: #47652
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
cjihrig authored and MoLow committed Jul 6, 2023
1 parent 882c612 commit 2033691
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TestCoverage {
});

for (let j = 0; j < functions.length; ++j) {
const { functionName, isBlockCoverage, ranges } = functions[j];
const { isBlockCoverage, ranges } = functions[j];

for (let k = 0; k < ranges.length; ++k) {
const range = ranges[k];
Expand All @@ -172,7 +172,7 @@ class TestCoverage {
}
}

if (functionName.length > 0 && ranges.length > 0) {
if (j > 0 && ranges.length > 0) {
const range = ranges[0];

if (range.count !== 0 || range.ignoredLines === range.lines.length) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (false) {
require('./invalid-tap.js');
}

test('a test', function testHandler() {
test('a test', () => {
const uncalled = () => {};

function fnWithControlFlow(val) {
Expand Down

0 comments on commit 2033691

Please sign in to comment.