Skip to content

Commit

Permalink
test_runner: addressing PR comments
Browse files Browse the repository at this point in the history
Removed additional loop from calculating max counts for functions.
Simplified reporting of count for each line.
Returned arrow function to implicit return.
  • Loading branch information
philnash committed Aug 28, 2023
1 parent a382307 commit b023ec4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
22 changes: 9 additions & 13 deletions lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
});

Expand All @@ -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) {

Check failure on line 212 in lib/internal/test_runner/coverage.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected space(s) after "if"
ArrayPrototypePush(lineReports, {
__proto__: null,
line: line.line,
count: 0,
count: line.count

Check failure on line 216 in lib/internal/test_runner/coverage.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});
}
if (line.covered || line.ignore) {
coveredCnt++;
}
}

ArrayPrototypePush(coverageSummary.files, {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b023ec4

Please sign in to comment.