| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import type { UIRendererCoverageSummary } from "./e2e-ui-coverage.js";
- export function renderUICoverageMarkdownSection(
- coverage: UIRendererCoverageSummary,
- ) {
- const sourceFiles = coverage.sourceFiles ?? [];
- const lines = [
- "## Coverage",
- "",
- "### UI Renderer",
- "",
- `- Report kind: \`${coverage.reportKind ?? "bundle-byte"}\``,
- `- Pages: \`${coverage.pageCount}\``,
- `- Instrumented files: \`${coverage.rawEntryCount}\``,
- `- Source files: \`${coverage.sourceFileCount ?? sourceFiles.length}\``,
- `- Line coverage: \`${formatCoverageTotal(coverage.totals.lines)}\``,
- `- Statement coverage: \`${formatCoverageTotal(coverage.totals.statements)}\``,
- `- Function coverage: \`${formatCoverageTotal(coverage.totals.functions)}\``,
- `- Branch coverage: \`${formatCoverageTotal(coverage.totals.branches)}\``,
- ...(coverage.totals.totalBytes > 0
- ? [
- `- Bundle byte coverage: \`${coverage.totals.percent}% (${coverage.totals.coveredBytes}/${coverage.totals.totalBytes})\``,
- `- Renderer scripts: \`${coverage.rendererEntryCount}\``,
- ]
- : []),
- `- Istanbul HTML: \`${coverage.files.htmlIndex ?? "n/a"}\``,
- `- LCOV: \`${coverage.files.lcov ?? "n/a"}\``,
- `- Coverage JSON: \`${coverage.files.coverageFinalJson ?? "n/a"}\``,
- "",
- ];
- if (sourceFiles.length > 0) {
- lines.push(
- "| Lines | Statements | Functions | Branches | Uncovered lines | File |",
- "| ---: | ---: | ---: | ---: | --- | --- |",
- ...sourceFiles.map(
- (file) =>
- `| ${formatCoverageTotal(file.lines)} | ${formatCoverageTotal(file.statements)} | ${formatCoverageTotal(file.functions)} | ${formatCoverageTotal(file.branches)} | ${formatUncoveredLines(file.uncoveredLines)} | \`${escapeTableCell(file.relativePath)}\` |`,
- ),
- "",
- );
- return lines;
- }
- lines.push(
- "| Coverage | Covered bytes | Total bytes | Script |",
- "| ---: | ---: | ---: | --- |",
- ...coverage.scripts.map((script) => {
- const scriptName = script.url.split("/").at(-1) ?? script.url;
- return `| ${script.percent}% | ${script.coveredBytes} | ${script.totalBytes} | \`${escapeTableCell(scriptName)}\` |`;
- }),
- "",
- );
- return lines;
- }
- function formatCoverageTotal(
- total:
- | {
- covered: number;
- pct: number;
- total: number;
- }
- | undefined,
- ) {
- if (!total) {
- return "n/a";
- }
- return `${total.pct}% (${total.covered}/${total.total})`;
- }
- function formatUncoveredLines(lines: number[]) {
- if (lines.length === 0) {
- return "-";
- }
- if (lines.length <= 12) {
- return lines.join(", ");
- }
- return `${lines.slice(0, 12).join(", ")} ... +${lines.length - 12}`;
- }
- function escapeTableCell(value: string) {
- return value.replace(/\|/g, "\\|");
- }
|