diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 2f12db6383c597..1ed45028f61575 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -163,8 +163,10 @@ class TestCoverage { for (let j = 0; j < functions.length; ++j) { const { isBlockCoverage, ranges } = functions[j]; + let maxCountPerFunction = 0; for (let k = 0; k < ranges.length; ++k) { const range = ranges[k]; + maxCountPerFunction = MathMax(maxCountPerFunction, range.count); mapRangeToLines(range, lines); @@ -190,7 +192,7 @@ class TestCoverage { ArrayPrototypePush(functionReports, { __proto__: null, name: functions[j].functionName, - count: MathMax(...ArrayPrototypeMap(ranges, (r) => r.count)), + count: maxCountPerFunction, line: range.lines[0].line, }); @@ -207,23 +209,16 @@ class TestCoverage { for (let j = 0; j < lines.length; ++j) { const line = lines[j]; - - if (line.covered || line.ignore) { - coveredCnt++; - if (!line.ignore) { - ArrayPrototypePush(lineReports, { - __proto__: null, - line: line.line, - count: line.count, - }); - } - } else { + if (!line.ignore) { ArrayPrototypePush(lineReports, { __proto__: null, line: line.line, - count: 0, + count: line.count, }); } + if (line.covered || line.ignore) { + coveredCnt++; + } } ArrayPrototypePush(coverageSummary.files, { @@ -350,6 +345,7 @@ function mapRangeToLines(range, lines) { if (count === 0 && startOffset <= line.startOffset && endOffset >= line.endOffset) { line.covered = false; + line.count = 0; } if (count > 0 && startOffset <= line.startOffset && endOffset >= line.endOffset) { diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 4a8ec3a04a6ebb..7923732f04dfcb 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -330,9 +330,8 @@ function getCoverageReport(pad, summary, symbol, color, table) { columnPadLengths = ArrayPrototypeMap(kColumns, (column) => (table ? MathMax(column.length, 6) : 0)); const columnsWidth = ArrayPrototypeReduce(columnPadLengths, (acc, columnPadLength) => acc + columnPadLength + 3, 0); - uncoveredLinesPadLength = table && ArrayPrototypeReduce(summary.files, (acc, file) => { - return MathMax(acc, formatUncoveredLines(getUncoveredLines(file.lines), table).length); - }, 0); + uncoveredLinesPadLength = table && ArrayPrototypeReduce(summary.files, (acc, file) => + MathMax(acc, formatUncoveredLines(getUncoveredLines(file.lines), table).length), 0); uncoveredLinesPadLength = MathMax(uncoveredLinesPadLength, 'uncovered lines'.length); const uncoveredLinesWidth = uncoveredLinesPadLength + 2;