Skip to content

Commit b023ec4

Browse files
committed
test_runner: addressing PR comments
Removed additional loop from calculating max counts for functions. Simplified reporting of count for each line. Returned arrow function to implicit return.
1 parent a382307 commit b023ec4

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

lib/internal/test_runner/coverage.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ class TestCoverage {
163163
for (let j = 0; j < functions.length; ++j) {
164164
const { isBlockCoverage, ranges } = functions[j];
165165

166+
let maxCountPerFunction = 0;
166167
for (let k = 0; k < ranges.length; ++k) {
167168
const range = ranges[k];
169+
maxCountPerFunction = MathMax(maxCountPerFunction, range.count);
168170

169171
mapRangeToLines(range, lines);
170172

@@ -190,7 +192,7 @@ class TestCoverage {
190192
ArrayPrototypePush(functionReports, {
191193
__proto__: null,
192194
name: functions[j].functionName,
193-
count: MathMax(...ArrayPrototypeMap(ranges, (r) => r.count)),
195+
count: maxCountPerFunction,
194196
line: range.lines[0].line,
195197
});
196198

@@ -207,23 +209,16 @@ class TestCoverage {
207209

208210
for (let j = 0; j < lines.length; ++j) {
209211
const line = lines[j];
210-
211-
if (line.covered || line.ignore) {
212-
coveredCnt++;
213-
if (!line.ignore) {
214-
ArrayPrototypePush(lineReports, {
215-
__proto__: null,
216-
line: line.line,
217-
count: line.count,
218-
});
219-
}
220-
} else {
212+
if(!line.ignore) {
221213
ArrayPrototypePush(lineReports, {
222214
__proto__: null,
223215
line: line.line,
224-
count: 0,
216+
count: line.count
225217
});
226218
}
219+
if (line.covered || line.ignore) {
220+
coveredCnt++;
221+
}
227222
}
228223

229224
ArrayPrototypePush(coverageSummary.files, {
@@ -350,6 +345,7 @@ function mapRangeToLines(range, lines) {
350345
if (count === 0 && startOffset <= line.startOffset &&
351346
endOffset >= line.endOffset) {
352347
line.covered = false;
348+
line.count = 0;
353349
}
354350
if (count > 0 && startOffset <= line.startOffset &&
355351
endOffset >= line.endOffset) {

lib/internal/test_runner/utils.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,8 @@ function getCoverageReport(pad, summary, symbol, color, table) {
330330
columnPadLengths = ArrayPrototypeMap(kColumns, (column) => (table ? MathMax(column.length, 6) : 0));
331331
const columnsWidth = ArrayPrototypeReduce(columnPadLengths, (acc, columnPadLength) => acc + columnPadLength + 3, 0);
332332

333-
uncoveredLinesPadLength = table && ArrayPrototypeReduce(summary.files, (acc, file) => {
334-
return MathMax(acc, formatUncoveredLines(getUncoveredLines(file.lines), table).length);
335-
}, 0);
333+
uncoveredLinesPadLength = table && ArrayPrototypeReduce(summary.files, (acc, file) =>
334+
MathMax(acc, formatUncoveredLines(getUncoveredLines(file.lines), table).length), 0);
336335
uncoveredLinesPadLength = MathMax(uncoveredLinesPadLength, 'uncovered lines'.length);
337336
const uncoveredLinesWidth = uncoveredLinesPadLength + 2;
338337

0 commit comments

Comments
 (0)