Skip to content

Commit 0f65f1a

Browse files
MishaKavclaude
andcommitted
fix: keep text-badge fraction statement-only for text reports
The branch-aware fraction assumed `brpart` is the count of missing branches, which is only true for XML totals. Text reports expose coverage.py's `BrPart` (partial branches), so gate the branch math on the XML path to avoid overstating covered branches. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e6b549a commit 0f65f1a

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

__tests__/parse.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,17 @@ describe('toHtml', () => {
260260
expect(html).toContain('(');
261261
});
262262

263+
test('text badge fraction stays statement-only for text reports with branches', () => {
264+
// In coverage.py text reports BrPart is partial branches, not missing
265+
// arcs, so the fraction must not use branch counts (TOTAL: 1345 1002 386 1 22%).
266+
const content = getContentFile(
267+
path.join(dataPath, 'pytest-coverage_6.txt'),
268+
);
269+
const options = { ...baseOptions, textInsteadBadge: true };
270+
const html = toHtml(content, options);
271+
expect(html).toContain('22% (343/1345)');
272+
});
273+
263274
test('should remove link from badge when removeLinkFromBadge is true', () => {
264275
const content = getContentFile(
265276
path.join(dataPath, 'pytest-coverage_4.txt'),

dist/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39727,9 +39727,10 @@ const toHtml = (data, options, dataFromXml = null) => {
3972739727
: `<a href="${readmeHref}">${badge}</a>`;
3972839728
const stmts = typeof total.stmts === 'number' ? total.stmts : parseInt(total.stmts);
3972939729
const miss = typeof total.miss === 'number' ? total.miss : parseInt(total.miss);
39730-
// include branches so the fraction matches the branch-aware %
39731-
const branch = total.branch ? parseInt(total.branch) : 0;
39732-
const brpart = total.brpart ? parseInt(total.brpart) : 0;
39730+
// brpart only means "missing branches" for XML totals; text reports use
39731+
// BrPart (partial branches), so keep the statement-only fraction there
39732+
const branch = dataFromXml && total.branch ? parseInt(total.branch) : 0;
39733+
const brpart = dataFromXml && total.brpart ? parseInt(total.brpart) : 0;
3973339734
const covered = stmts - miss + (branch - brpart);
3973439735
const totalCount = stmts + branch;
3973539736
const textBadge = `${total.cover} (${covered}/${totalCount})`;

src/parse.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,10 @@ export const toHtml = (
268268
typeof total.stmts === 'number' ? total.stmts : parseInt(total.stmts);
269269
const miss =
270270
typeof total.miss === 'number' ? total.miss : parseInt(total.miss);
271-
// include branches so the fraction matches the branch-aware %
272-
const branch = total.branch ? parseInt(total.branch) : 0;
273-
const brpart = total.brpart ? parseInt(total.brpart) : 0;
271+
// brpart only means "missing branches" for XML totals; text reports use
272+
// BrPart (partial branches), so keep the statement-only fraction there
273+
const branch = dataFromXml && total.branch ? parseInt(total.branch) : 0;
274+
const brpart = dataFromXml && total.brpart ? parseInt(total.brpart) : 0;
274275
const covered = stmts - miss + (branch - brpart);
275276
const totalCount = stmts + branch;
276277
const textBadge = `${total.cover} (${covered}/${totalCount})`;

0 commit comments

Comments
 (0)