mirror of
https://github.com/penpot/penpot.git
synced 2026-11-19 08:30:42 +00:00
Measure the coverage of the backend, common, frontend and render-wasm test suites in CI, and show it on the workflow run pages and in one "Coverage Report" comment on each pull request. - Backend and common run kaocha with the cloverage plugin through a new `:coverage` alias, which writes lcov, HTML and an EMMA report. The PR report shows lines and Clojure forms (as statements); cloverage measures no functions or branches. Plain local runs are unchanged. - Frontend runs the compiled test bundle with V8 coverage (`pnpm run test:coverage`, `frontend/scripts/coverage.js`) and maps it back to the ClojureScript sources through the source maps of the test build. UI namespaces (`app/main/ui`) are left out. - Render-wasm runs its native Rust tests under cargo-llvm-cov when `RENDER_WASM_COVERAGE` is set. The devenv image lacks the tool, so the workflow downloads a pinned release and checks its sha256. - `scripts/coverage-summary.mjs` renders an lcov file as a markdown table by source area for `$GITHUB_STEP_SUMMARY`; each workflow also uploads the HTML report as an artifact. - `scripts/coverage-comment.mjs` keeps a single PR comment, laid out like the Vitest Coverage Report Action, with a section per project and the coverage of the changed files. Each job updates its own section; the data of every project lives in a hidden block of the comment, and a job writes again when a concurrent one dropped its data. - Lines have targets that only colour the report: 70% backend and common, 50% frontend, 40% render-wasm. - The comment step only runs for PRs from branches of this repo: fork PRs get a read-only token and keep the summary on the run page. AI-assisted-by: claude-opus-5-5
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
// lcov parsing shared by the coverage scripts.
|
|
|
|
const COUNTERS = {
|
|
LF: "lines",
|
|
LH: "lines",
|
|
FNF: "functions",
|
|
FNH: "functions",
|
|
BRF: "branches",
|
|
BRH: "branches",
|
|
};
|
|
|
|
export function emptyTotals() {
|
|
return {
|
|
files: 0,
|
|
lines: { covered: 0, total: 0 },
|
|
functions: { covered: 0, total: 0 },
|
|
branches: { covered: 0, total: 0 },
|
|
};
|
|
}
|
|
|
|
// One record per source file: `{path, lines, functions, branches}`, each
|
|
// metric as `{covered, total}`.
|
|
export function parseLcov(text) {
|
|
const records = [];
|
|
let current = null;
|
|
for (const line of text.split("\n")) {
|
|
const sep = line.indexOf(":");
|
|
const tag = sep === -1 ? line.trim() : line.slice(0, sep);
|
|
const value = line.slice(sep + 1).trim();
|
|
if (tag === "SF") {
|
|
current = { path: value, ...emptyTotals() };
|
|
} else if (tag === "end_of_record" && current) {
|
|
records.push(current);
|
|
current = null;
|
|
} else if (current && tag in COUNTERS) {
|
|
const key = tag.endsWith("F") ? "total" : "covered";
|
|
current[COUNTERS[tag]][key] = Number(value);
|
|
}
|
|
}
|
|
return records;
|
|
}
|
|
|
|
export function addTotals(totals, record) {
|
|
totals.files += 1;
|
|
for (const key of ["lines", "functions", "branches"]) {
|
|
totals[key].covered += record[key].covered;
|
|
totals[key].total += record[key].total;
|
|
}
|
|
}
|