Skip to content

Commit

Permalink
unify lines coverage logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jun 14, 2024
1 parent 99d08e8 commit 964911c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 54 deletions.
27 changes: 1 addition & 26 deletions lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,7 @@ const applyBytesToLines = (bytes, locator, lineMap) => {

// update lines coverage
const lines = Util.getRangeLines(sLoc, eLoc);

lines.forEach((it) => {
const lineItem = lineMap.get(it.line);
if (!lineItem) {
// not found line, could be comment or blank line
return;
}
if (lineItem.ignored) {
return;
}

it.count = count;

// default is covered, so only focus on
// 1, biggest covered count
// 2, uncovered entire and pieces
if (count > 0) {
lineItem.coveredCount = Math.max(lineItem.coveredCount, count);
} else {
if (it.entire) {
lineItem.uncoveredEntire = it;
} else {
lineItem.uncoveredPieces.push(it);
}
}
});
Util.updateLinesCoverage(lines, count, lineMap);

});

Expand Down
31 changes: 31 additions & 0 deletions lib/platform/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,37 @@ const Util = {
return lines;
},

updateLinesCoverage: (lines, count, lineMap) => {
lines.forEach((it) => {
const lineItem = lineMap.get(it.line);
if (!lineItem) {
// not found line, could be comment or blank line
return;
}

if (lineItem.ignored) {
return;
}

it.count = count;

// default is covered, so only focus on
// 1, biggest covered count
// 2, uncovered entire and pieces
if (count > 0) {
lineItem.coveredCount = Math.max(lineItem.coveredCount, count);
} else {
if (it.entire) {
lineItem.uncoveredEntire = it;
} else {
lineItem.uncoveredPieces.push(it);
}
}

});

},

// =============================================================================
// svg

Expand Down
29 changes: 1 addition & 28 deletions packages/app/src/utils/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,34 +255,7 @@ class CoverageParser {

const lines = Util.getRangeLines(sLoc, eLoc);
// console.log(lines);

lines.forEach((it) => {
const lineItem = lineMap.get(it.line);
if (!lineItem) {
// not found line, could be comment or blank line
return;
}

if (lineItem.ignored) {
return;
}

it.count = count;

// default is covered, so only focus on
// 1, last covered count
// 2, uncovered entire and pieces
if (count > 0) {
lineItem.coveredCount = count;
} else {
if (it.entire) {
lineItem.uncoveredEntire = it;
} else {
lineItem.uncoveredPieces.push(it);
}
}

});
Util.updateLinesCoverage(lines, count, lineMap);

}

Expand Down

0 comments on commit 964911c

Please sign in to comment.