Skip to content

Commit

Permalink
fix uncovered groups
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Sep 14, 2024
1 parent 1b8713e commit 62974d6
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ const mergeV8Data = (state, stateList) => {
// console.log(stateList);

// let debug = false;
// if (state.sourcePath.endsWith('component.js')) {
// if (state.sourcePath.endsWith('counter.tsx')) {
// debug = true;
// console.log('merge v8 data ===================================', state.sourcePath);
// console.log('bytes before ============', stateList.map((it) => it.bytes));
Expand All @@ -1356,7 +1356,7 @@ const mergeV8Data = (state, stateList) => {
const uncoveredMap = new Map();
const uncoveredGroups = [];
stateList.forEach((st) => {
const group = new Map();
const groupMap = new Map();
const bytes = dedupeCountRanges(st.bytes);
bytes.forEach((range) => {
const key = `${range.start}_${range.end}`;
Expand All @@ -1365,10 +1365,10 @@ const mergeV8Data = (state, stateList) => {
coveredMap.set(key, true);
} else {
uncoveredMap.set(key, range);
group.set(key, true);
groupMap.set(key, range);
}
});
uncoveredGroups.push(group);
uncoveredGroups.push(groupMap);
});

// if (debug) {
Expand All @@ -1377,19 +1377,41 @@ const mergeV8Data = (state, stateList) => {
// console.log('uncoveredGroups ============', uncoveredGroups);
// }

const isInUncoveredGroup = (range, key) => {

let num = 0;
uncoveredGroups.forEach((groupMap) => {
if (groupMap.has(key)) {
num += 1;
return;
}

for (const item of groupMap.values()) {
if (range.start >= item.start && range.end <= item.end) {
num += 1;
return;
}
}

});

if (num >= uncoveredGroups.length) {
return true;
}

return false;

};

uncoveredMap.forEach((range, key) => {
if (coveredMap.has(key)) {
return;
}

for (const group of uncoveredGroups) {
if (!group.has(key)) {
return;
}
if (isInUncoveredGroup(range, key)) {
mergedBytes.push(range);
}

mergedBytes.push(range);

});

// will be dedupeCountRanges in collectFileCoverage
Expand Down

0 comments on commit 62974d6

Please sign in to comment.