Skip to content

Commit 4bbaa99

Browse files
committed
Fix folder coverage calculation using aggregated tracked/missing lines
Signed-off-by: Bhoomi <[email protected]>
1 parent f3e90e6 commit 4bbaa99

File tree

1 file changed

+21
-15
lines changed
  • workspaces/code-coverage/plugins/code-coverage/src/components/FileExplorer

1 file changed

+21
-15
lines changed

workspaces/code-coverage/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,33 @@ const removeVisitedPathGroup = (
9393

9494
export const buildFileStructure = (row: CoverageTableRow) => {
9595
const dataGroupedByPath: FileStructureObject = groupByPath(row.files);
96+
9697
row.files = Object.keys(dataGroupedByPath).map(pathGroup => {
98+
const aggregatedTracked = dataGroupedByPath[pathGroup].reduce(
99+
(acc: number, cur: CoverageTableRow) => acc + cur.tracked,
100+
0,
101+
);
102+
103+
const aggregatedMissing = dataGroupedByPath[pathGroup].reduce(
104+
(acc: number, cur: CoverageTableRow) => acc + cur.missing,
105+
0,
106+
);
107+
97108
return buildFileStructure({
98109
path: pathGroup,
99-
files: dataGroupedByPath.hasOwnProperty('files')
100-
? removeVisitedPathGroup(dataGroupedByPath.files, pathGroup)
101-
: removeVisitedPathGroup(dataGroupedByPath[pathGroup], pathGroup),
102-
coverage:
103-
dataGroupedByPath[pathGroup].reduce(
104-
(acc: number, cur: CoverageTableRow) => acc + cur.coverage,
105-
0,
106-
) / dataGroupedByPath[pathGroup].length,
107-
missing: dataGroupedByPath[pathGroup].reduce(
108-
(acc: number, cur: CoverageTableRow) => acc + cur.missing,
109-
0,
110-
),
111-
tracked: dataGroupedByPath[pathGroup].reduce(
112-
(acc: number, cur: CoverageTableRow) => acc + cur.tracked,
113-
0,
110+
files: removeVisitedPathGroup(
111+
dataGroupedByPath[pathGroup],
112+
pathGroup,
114113
),
114+
coverage:
115+
aggregatedTracked > 0
116+
? ((aggregatedTracked - aggregatedMissing) / aggregatedTracked) * 100
117+
: 0,
118+
missing: aggregatedMissing,
119+
tracked: aggregatedTracked,
115120
});
116121
});
122+
117123
return row;
118124
};
119125

0 commit comments

Comments
 (0)