-
Notifications
You must be signed in to change notification settings - Fork 19
/
generateSummaryTableHtml.ts
56 lines (49 loc) · 1.78 KB
/
generateSummaryTableHtml.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
50
51
52
53
54
55
56
import { icons } from './icons';
import { oneLine } from 'common-tags';
import { Thresholds } from './types/Threshold';
import { CoverageReport, ReportNumbers } from './types/JsonSummary';
const generateTableRow = ({ reportNumbers, category, threshold }: { reportNumbers: ReportNumbers; category: string; threshold?: number; }): string => {
let status = icons.blue;
let percent = `${reportNumbers.pct}%`;
if(threshold) {
status = reportNumbers.pct >= threshold ? icons.green : icons.red;
percent = `${percent} / ${threshold}%`;
}
return `
<td align="center">${status}</td>
<td align="left">${category}</td>
<td align="right">${percent}</td>
<td align="right">${reportNumbers.covered} / ${reportNumbers.total}</td>
`
}
const generateSummaryTableHtml = (jsonReport: CoverageReport, thresholds: Thresholds = {}): string => {
return oneLine`
<table>
<thead>
<tr>
<th align="center">Status</th>
<th align="left">Category</th>
<th align="right">Percentage</th>
<th align="right">Covered / Total</th>
</tr>
</thead>
<tbody>
<tr>
${generateTableRow({ reportNumbers: jsonReport.lines, category: 'Lines', threshold: thresholds.lines })}
</tr>
<tr>
${generateTableRow({ reportNumbers: jsonReport.statements, category: 'Statements', threshold: thresholds.statements })}
</tr>
<tr>
${generateTableRow({ reportNumbers: jsonReport.functions, category: 'Functions',threshold: thresholds.functions })}
</tr>
<tr>
${generateTableRow({ reportNumbers: jsonReport.branches, category: 'Branches', threshold: thresholds.branches })}
</tr>
</tbody>
</table>
`
}
export {
generateSummaryTableHtml
};