From 6cc0f4775d4f5923b5fdfe8b9dc25dfb3d0eb189 Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Mon, 3 Nov 2025 23:35:06 +0100 Subject: [PATCH] feat: show hint how many lines to cover to reach threshold --- src/cli/reporters/pretty.test.ts | 12 ++++++++++-- src/cli/reporters/pretty.ts | 14 +++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/cli/reporters/pretty.test.ts b/src/cli/reporters/pretty.test.ts index 00db910..0d6c8bd 100644 --- a/src/cli/reporters/pretty.test.ts +++ b/src/cli/reporters/pretty.test.ts @@ -164,7 +164,12 @@ test.describe('only --min-line-coverage', () => { test('failure', () => { const report = { - ...context_empty, + context: { + coverage: { + total_lines: 10_000, + covered_lines: 5022, + } as CoverageResult, + }, report: { ok: false, ...min_line_coverage_failure, @@ -172,7 +177,10 @@ test.describe('only --min-line-coverage', () => { }, } satisfies Report let result = print(report, show_none, dependencies) - expect(result).toEqual(['Failed: line coverage is 50.22%% which is lower than the threshold of 1']) + expect(result).toEqual([ + 'Failed: line coverage is 50.22%% which is lower than the threshold of 1', + 'Tip: cover 4978 more lines to meet the threshold of 100%', + ]) }) }) diff --git a/src/cli/reporters/pretty.ts b/src/cli/reporters/pretty.ts index d38f081..6147216 100644 --- a/src/cli/reporters/pretty.ts +++ b/src/cli/reporters/pretty.ts @@ -29,10 +29,15 @@ export function print_lines({ report, context }: Report, params: CliArguments, { if (report.min_line_coverage.ok) { output.push(`${styleText(['bold', 'green'], 'Success')}: total line coverage is ${percentage(report.min_line_coverage.actual)}`) } else { + let { actual, expected } = report.min_line_coverage output.push( - `${styleText(['bold', 'red'], 'Failed')}: line coverage is ${percentage( - report.min_line_coverage.actual, - )}% which is lower than the threshold of ${report.min_line_coverage.expected}`, + `${styleText(['bold', 'red'], 'Failed')}: line coverage is ${percentage(actual)}% which is lower than the threshold of ${expected}`, + ) + let lines_to_cover = expected * context.coverage.total_lines - context.coverage.covered_lines + output.push( + `Tip: cover ${Math.ceil(lines_to_cover)} more ${lines_to_cover === 1 ? 'line' : 'lines'} to meet the threshold of ${percentage( + expected, + )}`, ) } @@ -60,6 +65,9 @@ export function print_lines({ report, context }: Report, params: CliArguments, { print_width = print_width ?? 80 let min_file_line_coverage = report.min_file_line_coverage.expected + // Show empty line between report header and chunks output + output.push() + for (let sheet of context.coverage.coverage_per_stylesheet.sort((a, b) => a.line_coverage_ratio - b.line_coverage_ratio)) { if ( (sheet.line_coverage_ratio !== 1 && params['show-uncovered'] === 'all') ||