-
Notifications
You must be signed in to change notification settings - Fork 21
/
getUncoveredLinesFromStatements.ts
49 lines (40 loc) · 1.14 KB
/
getUncoveredLinesFromStatements.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import type { StatementCoverageReport } from "../types/JsonFinal";
type LineRange = {
start: number;
end: number;
};
const getUncoveredLinesFromStatements = ({
s,
statementMap,
}: StatementCoverageReport): LineRange[] => {
const keys = Object.keys(statementMap);
const uncoveredLineRanges: LineRange[] = [];
let currentRange: LineRange | undefined = undefined;
for (const key of keys) {
if (s[key] > 0) {
// If the statement is covered, we need to close the current range.
if (currentRange) {
uncoveredLineRanges.push(currentRange);
currentRange = undefined;
}
// Besides that, we can just ignore covered lines
continue;
}
// Start a new range if we don't have one yet.
if (!currentRange) {
currentRange = {
start: statementMap[key].start.line,
end: statementMap[key].end.line,
};
continue;
}
currentRange.end = statementMap[key].end.line;
}
// If we still have a current range, we need to add it to the uncovered line ranges.
if (currentRange) {
uncoveredLineRanges.push(currentRange);
}
return uncoveredLineRanges;
};
export { getUncoveredLinesFromStatements };
export type { LineRange };