Skip to content

Commit 78f1b3f

Browse files
committed
chore: improve formatting of templated strings
1 parent 7dcb03b commit 78f1b3f

File tree

2 files changed

+115
-95
lines changed

2 files changed

+115
-95
lines changed

src/lib/reporters/html/pages/details.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,40 @@ export const generateDetailsPage = ({
3131
const relativePathToIndex = path.relative(`${filename}.html`, "index.html");
3232

3333
return `
34-
<div style="margin-top: 3em;" class="ui container">
35-
<h1 class="ui header">
36-
<a href="${relativePathToIndex}">TypeScript coverage report</a>
37-
</h1>
38-
<table class="ui table celled fixed">
39-
<thead>
40-
<tr>
41-
<th class="ten wide">Filename</th>
42-
<th>Percent</th>
43-
<th>Threshold</th>
44-
<th>Total</th>
45-
<th>Covered</th>
46-
<th>Uncovered</th>
47-
</tr>
48-
</thead>
49-
<tbody>
50-
<tr class="${isValid ? "positive" : "negative"}">
51-
<td>${filename}</td>
52-
<td>${percentageCoverage}</td>
53-
<td>${threshold}%</td>
54-
<td>${totalCount}</td>
55-
<td>${correctCount}</td>
56-
<td>${totalCount - correctCount}</td>
57-
</tr>
58-
</tbody>
59-
</table>
60-
<textarea
61-
id="editor"
62-
readonly
63-
style="margin-top: 3em;"
64-
>${sourceCode}</textarea>
65-
<pre id="annotations" style="display: none;">
66-
${JSON.stringify(annotations)}
67-
</pre>
68-
</div>
34+
<div style="margin-top: 3em;" class="ui container">
35+
<h1 class="ui header">
36+
<a href="${relativePathToIndex}">TypeScript coverage report</a>
37+
</h1>
38+
<table class="ui table celled fixed">
39+
<thead>
40+
<tr>
41+
<th class="ten wide">Filename</th>
42+
<th>Percent</th>
43+
<th>Threshold</th>
44+
<th>Total</th>
45+
<th>Covered</th>
46+
<th>Uncovered</th>
47+
</tr>
48+
</thead>
49+
<tbody>
50+
<tr class="${isValid ? "positive" : "negative"}">
51+
<td>${filename}</td>
52+
<td>${percentageCoverage}</td>
53+
<td>${threshold}%</td>
54+
<td>${totalCount}</td>
55+
<td>${correctCount}</td>
56+
<td>${totalCount - correctCount}</td>
57+
</tr>
58+
</tbody>
59+
</table>
60+
<textarea
61+
id="editor"
62+
readonly
63+
style="margin-top: 3em;"
64+
>${sourceCode}</textarea>
65+
<pre id="annotations" style="display: none;">
66+
${JSON.stringify(annotations)}
67+
</pre>
68+
</div>
6969
`;
7070
};
Lines changed: 80 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
import path from "node:path";
2-
import { CoverageData } from "../../../getCoverage";
2+
import type { CoverageData } from "../../../getCoverage";
33

44
type GenerateSummaryPageContext = Omit<CoverageData, "anys"> & {
55
threshold: number;
66
};
77

8+
const generateSummaryTableRow = ({
9+
filename,
10+
totalCount,
11+
correctCount,
12+
threshold
13+
}: {
14+
filename: string;
15+
correctCount: number;
16+
totalCount: number;
17+
threshold: number;
18+
}) => {
19+
const percentage = totalCount === 0 ? 100 : (correctCount * 100) / totalCount;
20+
const percentageCoverage = percentage.toFixed(2) + "%";
21+
const isValid = percentage >= threshold;
22+
23+
const pathToFile = path.join("files", `${filename}.html`);
24+
25+
return `
26+
<tr class="${isValid ? "positive" : "negative"}">
27+
<td title="${filename}">
28+
<a style="color: inherit;" href="${pathToFile}">${filename}</a>
29+
</td>
30+
<td>${percentageCoverage}</td>
31+
<td>${totalCount}</td>
32+
<td>${correctCount}</td>
33+
<td>${totalCount - correctCount}</td>
34+
</tr>
35+
`;
36+
};
37+
838
export const generateSummaryPage = ({
939
fileCounts,
1040
percentage,
@@ -16,63 +46,53 @@ export const generateSummaryPage = ({
1646
const isSummaryValid = percentage >= threshold;
1747

1848
return `
19-
<div style="margin-top: 3em;" class="ui container">
20-
<h1 class="ui header">TypeScript coverage report</h1>
21-
<h2 class="ui header">Summary</h2>
22-
<table class="ui table celled fixed">
23-
<thead>
24-
<tr>
25-
<th>Percent</th>
26-
<th>Threshold</th>
27-
<th>Total</th>
28-
<th>Covered</th>
29-
<th>Uncovered</th>
30-
</tr>
31-
</thead>
32-
<tbody>
33-
<tr class="${isSummaryValid ? "positive" : "negative"}">
34-
<td>${percentage.toFixed(2) + "%"}</td>
35-
<td>${threshold}%</td>
36-
<td>${total}</td>
37-
<td>${covered}</td>
38-
<td>${uncovered}</td>
39-
</tr>
40-
</tbody>
41-
</table>
42-
<h2 class="ui header">Files</h2>
43-
<table style="margin-top: 2em" id="coverage-table" class="ui table celled fixed sortable">
44-
<thead>
45-
<tr>
46-
<th class="ten wide">Filename</th>
47-
<th>Percent</th>
48-
<th>Total</th>
49-
<th>Covered</th>
50-
<th>Uncovered</th>
51-
</tr>
52-
</thead>
53-
<tbody>
54-
${Array.from(fileCounts)
55-
.map(([filename, { correctCount, totalCount }]) => {
56-
const percentage =
57-
totalCount === 0 ? 100 : (correctCount * 100) / totalCount;
58-
const percentageCoverage = percentage.toFixed(2) + "%";
59-
const isValid = percentage >= threshold;
60-
61-
const pathToFile = path.join("files", `${filename}.html`);
62-
63-
return `
64-
<tr class="${isValid ? "positive" : "negative"}">
65-
<td title="${filename}">
66-
<a style="color: inherit;" href="${pathToFile}">${filename}</a>
67-
</td>
68-
<td>${percentageCoverage}</td>
69-
<td>${totalCount}</td>
70-
<td>${correctCount}</td>
71-
<td>${totalCount - correctCount}</td>
72-
</tr>`;
73-
})
74-
.join("\n")}
75-
</tbody>
76-
</table>
77-
</section>`;
49+
<div style="margin-top: 3em;" class="ui container">
50+
<h1 class="ui header">TypeScript coverage report</h1>
51+
<h2 class="ui header">Summary</h2>
52+
<table class="ui table celled fixed">
53+
<thead>
54+
<tr>
55+
<th>Percent</th>
56+
<th>Threshold</th>
57+
<th>Total</th>
58+
<th>Covered</th>
59+
<th>Uncovered</th>
60+
</tr>
61+
</thead>
62+
<tbody>
63+
<tr class="${isSummaryValid ? "positive" : "negative"}">
64+
<td>${percentage.toFixed(2) + "%"}</td>
65+
<td>${threshold}%</td>
66+
<td>${total}</td>
67+
<td>${covered}</td>
68+
<td>${uncovered}</td>
69+
</tr>
70+
</tbody>
71+
</table>
72+
<h2 class="ui header">Files</h2>
73+
<table style="margin-top: 2em" id="coverage-table" class="ui table celled fixed sortable">
74+
<thead>
75+
<tr>
76+
<th class="ten wide">Filename</th>
77+
<th>Percent</th>
78+
<th>Total</th>
79+
<th>Covered</th>
80+
<th>Uncovered</th>
81+
</tr>
82+
</thead>
83+
<tbody>
84+
${Array.from(fileCounts)
85+
.map(([filename, { correctCount, totalCount }]) =>
86+
generateSummaryTableRow({
87+
filename,
88+
correctCount,
89+
totalCount,
90+
threshold
91+
})
92+
)
93+
.join("\n")}
94+
</tbody>
95+
</table>
96+
</div>
97+
`;
7898
};

0 commit comments

Comments
 (0)