* @param {string} dir * @param {FileCoverageInfo} info * @returns {Promise }
(dir, info)
| 93 | * @returns {Promise<void>} |
| 94 | */ |
| 95 | async function generateHTMLCoverageReport(dir, info) { |
| 96 | const {name, coverage, parts} = info; |
| 97 | |
| 98 | /** @type {string[]} */ |
| 99 | const lines = []; |
| 100 | lines.push('<!DOCTYPE html>'); |
| 101 | lines.push('<html>'); |
| 102 | lines.push('<head>'); |
| 103 | const title = `Coverage report: ${name}`; |
| 104 | lines.push(` <title>${title}</title>`); |
| 105 | lines.push(' <style>'); |
| 106 | lines.push(' body { background: #111; color: #ccc; }'); |
| 107 | lines.push(' code { background: #222; display: inline-block; white-space: pre-wrap; }'); |
| 108 | lines.push(' .uncovered { background: #934; color: white; }'); |
| 109 | lines.push(' </style>'); |
| 110 | lines.push('</head>'); |
| 111 | lines.push('<body>'); |
| 112 | lines.push(` <h1>${title}</h1>`); |
| 113 | lines.push(` <h3>Covered ${(coverage * 100).toFixed(0)}%</h3>`); |
| 114 | lines.push(` <code>${parts.map((p) => `<span${p.covered ? '' : ' class="uncovered"'}>${escapeHTML(p.text)}</span>`).join('')}</code>`); |
| 115 | lines.push('</body>'); |
| 116 | lines.push('</html>'); |
| 117 | |
| 118 | await writeFile(path.join(dir, `${name}.html`), lines.join('\n')); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @param {string} dir |
no test coverage detected