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 <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
cjihrig authored and targos committed May 2, 2023
1 parent 1f120a3 commit b6fb791
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 b6fb791

Please sign in to comment.