Skip to content

Commit cc5321f

Browse files
authored
feat: show hint how many lines to cover to reach threshold (#44)
1 parent 1d70494 commit cc5321f

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/cli/reporters/pretty.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,23 @@ test.describe('only --min-line-coverage', () => {
164164

165165
test('failure', () => {
166166
const report = {
167-
...context_empty,
167+
context: {
168+
coverage: {
169+
total_lines: 10_000,
170+
covered_lines: 5022,
171+
} as CoverageResult,
172+
},
168173
report: {
169174
ok: false,
170175
...min_line_coverage_failure,
171176
...min_file_line_coverage_unset,
172177
},
173178
} satisfies Report
174179
let result = print(report, show_none, dependencies)
175-
expect(result).toEqual(['Failed: line coverage is 50.22%% which is lower than the threshold of 1'])
180+
expect(result).toEqual([
181+
'Failed: line coverage is 50.22%% which is lower than the threshold of 1',
182+
'Tip: cover 4978 more lines to meet the threshold of 100%',
183+
])
176184
})
177185
})
178186

src/cli/reporters/pretty.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ export function print_lines({ report, context }: Report, params: CliArguments, {
2929
if (report.min_line_coverage.ok) {
3030
output.push(`${styleText(['bold', 'green'], 'Success')}: total line coverage is ${percentage(report.min_line_coverage.actual)}`)
3131
} else {
32+
let { actual, expected } = report.min_line_coverage
3233
output.push(
33-
`${styleText(['bold', 'red'], 'Failed')}: line coverage is ${percentage(
34-
report.min_line_coverage.actual,
35-
)}% which is lower than the threshold of ${report.min_line_coverage.expected}`,
34+
`${styleText(['bold', 'red'], 'Failed')}: line coverage is ${percentage(actual)}% which is lower than the threshold of ${expected}`,
35+
)
36+
let lines_to_cover = expected * context.coverage.total_lines - context.coverage.covered_lines
37+
output.push(
38+
`Tip: cover ${Math.ceil(lines_to_cover)} more ${lines_to_cover === 1 ? 'line' : 'lines'} to meet the threshold of ${percentage(
39+
expected,
40+
)}`,
3641
)
3742
}
3843

@@ -60,6 +65,9 @@ export function print_lines({ report, context }: Report, params: CliArguments, {
6065
print_width = print_width ?? 80
6166
let min_file_line_coverage = report.min_file_line_coverage.expected
6267

68+
// Show empty line between report header and chunks output
69+
output.push()
70+
6371
for (let sheet of context.coverage.coverage_per_stylesheet.sort((a, b) => a.line_coverage_ratio - b.line_coverage_ratio)) {
6472
if (
6573
(sheet.line_coverage_ratio !== 1 && params['show-uncovered'] === 'all') ||

0 commit comments

Comments
 (0)