11import path from "node:path" ;
2- import { CoverageData } from "../../../getCoverage" ;
2+ import type { CoverageData } from "../../../getCoverage" ;
33
44type 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+
838export 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