Skip to content

Commit

Permalink
feat: ignore empty totals in coverage pct
Browse files Browse the repository at this point in the history
  • Loading branch information
katywings committed Jun 6, 2020
1 parent 1d1e536 commit 7c5c202
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions scripts/badges.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,26 @@ fs.writeFileSync(
})
);

const coverage = require("./../coverage/coverage-summary");
let pcts = [];
for (const [k, v] of Object.entries(coverage.total)) {
pcts.push(v.pct);
}
const totalPct = pcts.length
? pcts.reduce((acc, pct) => acc + pct, 0) / pcts.length
: 0;
const getCoveragePct = function () {
const coverage = require("./../coverage/coverage-summary");

let pcts = [];
for (const v of Object.values(coverage.total)) {
if (v.total === 0) {
continue;
}
pcts.push(v.pct);
}

return pcts.length
? pcts.reduce((acc, pct) => acc + pct, 0) / pcts.length
: 100;
};

fs.writeFileSync(
assetsDir("badge.coverage.svg"),
badgen({
label: "coverage",
status: Math.round(totalPct) + "%",
status: Math.round(getCoveragePct()) + "%",
})
);

0 comments on commit 7c5c202

Please sign in to comment.