* @param {string} dir * @param {FileCoverageInfo[]} info * @returns {Promise }
(dir, info)
| 124 | * @returns {Promise<void>} |
| 125 | */ |
| 126 | async function generateIndexHTMLCoveragePage(dir, info) { |
| 127 | /** @type {string[]} */ |
| 128 | const lines = []; |
| 129 | lines.push('<!DOCTYPE html>'); |
| 130 | lines.push('<html>'); |
| 131 | lines.push('<head>'); |
| 132 | lines.push(` <title>Code coverage reports</title>`); |
| 133 | lines.push(' <style>'); |
| 134 | lines.push(' body { background: #111; color: #ccc; }'); |
| 135 | lines.push(' a { color: #7ae; }'); |
| 136 | lines.push(' </style>'); |
| 137 | lines.push('</head>'); |
| 138 | lines.push('<body>'); |
| 139 | lines.push(` <h1>Code coverage reports</h1>`); |
| 140 | const totalCoverage = info.reduce((sum, i) => sum + i.coverage * i.length, 0); |
| 141 | const totalLength = info.reduce((sum, i) => sum + i.length, 0); |
| 142 | lines.push(` <h3>Total coverage ${(totalCoverage / totalLength * 100).toFixed(0)}%</h3>`); |
| 143 | lines.push(' <table>'); |
| 144 | info.forEach((i) => { |
| 145 | lines.push(' <tr>'); |
| 146 | lines.push(` <td>${(i.coverage * 100).toFixed(0)}%</td>`); |
| 147 | lines.push(` <td><a href="${i.name}.html">${i.name}</a></td>`); |
| 148 | lines.push(' </tr>'); |
| 149 | }); |
| 150 | lines.push(' </table>'); |
| 151 | lines.push('</body>'); |
| 152 | lines.push('</html>'); |
| 153 | |
| 154 | await writeFile(path.join(dir, 'index.html'), lines.join('\n')); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * @param {string} dir |
no test coverage detected