Skip to content

Commit

Permalink
feat: Adds coverage percentage to report
Browse files Browse the repository at this point in the history
  • Loading branch information
davelosert committed Jun 10, 2022
1 parent 7af8e43 commit 8253128
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ This is a work in progress project. Currently, it will only take an already crea
- [ ] Make summary file configurable
- [ ] Invoke 'vitest' directly from the action
- [ ] Also provide test results (failed tests etc.) in the generated markdown reports
- [ ] Add option to let the action fail if coverage thresholds are not met
- [ ] Also report test results themselves
10 changes: 10 additions & 0 deletions src/generateSummaryTableData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ describe('generateTableData', () => {

expect(result).toContain('8 / 10');
});

it('if threshold is given, provides the threshold in the percentage column.', async (): Promise<void> => {
const data = generateSummaryTableData(mockReport, {
lines: 100
});

const result = stringifyTableData(data);

expect(result).toContain('80% / 100%');
});
});
5 changes: 4 additions & 1 deletion src/generateSummaryTableData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ type TableData = Parameters<typeof core.summary.addTable>[0];
const generateTableLine = ({ reportNumbers, category, threshold }: { reportNumbers: ReportNumbers; category: string; threshold?: number; }): string[] => {

let status = ':large_blue_circle:';
let percent = `${reportNumbers.pct}%`;

if(threshold) {
status = reportNumbers.pct >= threshold ? ':white_check_mark:' : ':x:';
percent = `${percent} / ${threshold}%`;
}

return [
status,
category,
`${reportNumbers.pct}%`,
`${percent}`,
`${reportNumbers.covered} / ${reportNumbers.total}`,
]
}
Expand Down

0 comments on commit 8253128

Please sign in to comment.