Skip to content

Commit

Permalink
fix: fix jsonPath issue. #32 #31
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 13, 2023
1 parent 69fc857 commit e99b39a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export function badge(option: BadgeOption, summary: object) {
const { label = 'coverage', style = 'classic', jsonPath = 'total.statements.pct' } = option || {}
let pct: any = summary;
pct = get(summary, jsonPath, 0);

if (!isNaN(Number(pct))) {
pct = Number(pct);
}

if (typeof pct !== 'number') {
throw new Error(`${jsonPath} evaluates to ${JSON.stringify(pct)} and is not a suitable path in the JSON coverage data`);
}
Expand Down

0 comments on commit e99b39a

Please sign in to comment.