Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/cli/reporters/pretty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,23 @@ 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,
...min_file_line_coverage_unset,
},
} 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%',
])
})
})

Expand Down
14 changes: 11 additions & 3 deletions src/cli/reporters/pretty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)}`,
)
}

Expand Down Expand Up @@ -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') ||
Expand Down