-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
reportCoverage.mjs
78 lines (66 loc) · 1.74 KB
/
reportCoverage.mjs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// @ts-check
import { bold, green, red, yellow } from "kleur/colors";
import { relative } from "node:path";
import errorConsole from "./errorConsole.mjs";
/**
* Reports a code coverage analysis to the console.
* @param {import("./analyseCoverage.mjs").CoverageAnalysis} coverageAnalysis
* Coverage analysis.
*/
export default function reportCoverage({
filesCount,
covered,
ignored,
uncovered,
}) {
if (covered.length) {
console.group(
`\n${green(
`${covered.length} file${covered.length === 1 ? "" : "s"} covered:`
)}\n`
);
for (const path of covered) console.info(relative("", path));
console.groupEnd();
}
if (ignored.length) {
console.group(
`\n${yellow(
`${ignored.length} file${
ignored.length === 1 ? "" : "s"
} ignoring coverage:`
)}\n`
);
for (const { path, ranges } of ignored)
for (const { start, end } of ranges)
console.info(
`${relative("", path)}:${start.line}:${start.column} → ${end.line}:${
end.column
}`
);
console.groupEnd();
}
if (uncovered.length) {
errorConsole.group(
`\n${red(
`${uncovered.length} file${
uncovered.length === 1 ? "" : "s"
} missing coverage:`
)}\n`
);
for (const { path, ranges } of uncovered)
for (const { start, end } of ranges)
errorConsole.info(
`${relative("", path)}:${start.line}:${start.column} → ${end.line}:${
end.column
}`
);
errorConsole.groupEnd();
}
console.info(
`\n${bold(
(uncovered.length ? red : ignored.length ? yellow : green)(
`${covered.length}/${filesCount} files covered.`
)
)}\n`
);
}