MCPcopy Index your code
hub / github.com/darkreader/darkreader / generateHTMLCoverageReport

Function generateHTMLCoverageReport

tests/browser/coverage.js:95–119  ·  view source on GitHub ↗

* @param {string} dir * @param {FileCoverageInfo} info * @returns {Promise }

(dir, info)

Source from the content-addressed store, hash-verified

93 * @returns {Promise<void>}
94 */
95async 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

Callers 1

Calls 2

writeFileFunction · 0.90
escapeHTMLFunction · 0.85

Tested by

no test coverage detected