Skip to content

Commit 1ca22e4

Browse files
committed
PFM-TASK-6308 refactor: enhance coverage reporting to show individual thresholds even when data is missing
1 parent dd056ea commit 1ca22e4

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

tools/scripts/run-many/coverage-evaluator.spec.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('coverage-evaluator', () => {
6666

6767
it('should count as one failure when coverage report is missing', () => {
6868
const mockGetProjectThresholds = getProjectThresholds as jest.Mock;
69-
mockGetProjectThresholds.mockReturnValue({ lines: 80 });
69+
mockGetProjectThresholds.mockReturnValue({ lines: 80, statements: 75 });
7070

7171
const mockExistsSync = fs.existsSync as jest.Mock;
7272
mockExistsSync.mockReturnValue(false);
@@ -76,11 +76,11 @@ describe('coverage-evaluator', () => {
7676
expect(result).toBe(1);
7777
expect(core.warning).toHaveBeenCalledWith('No coverage report found for project-a at coverage/project-a/coverage-summary.json');
7878

79-
// Verify that the comment indicates the project failed due to missing report
79+
// Verify that the comment shows individual thresholds with "No Data"
8080
const writeFileSyncMock = fs.writeFileSync as jest.Mock;
8181
const comment = writeFileSyncMock.mock.calls[0][1];
82-
expect(comment).toContain('❌ FAILED');
83-
expect(comment).toContain('No Data');
82+
expect(comment).toContain('| project-a | lines | 80% | No Data | ❌ FAILED |');
83+
expect(comment).toContain('| | statements | 75% | No Data | ❌ FAILED |');
8484
expect(comment).toContain('⚠️ WARNING (1 project failing)');
8585
});
8686

@@ -181,11 +181,13 @@ describe('coverage-evaluator', () => {
181181
expect(result).toBe(1);
182182
expect(core.error).toHaveBeenCalledWith('Error processing coverage for project-a: Test error');
183183

184-
// Verify that the comment shows an error status
184+
// Verify that the comment shows individual thresholds with "No Data"
185185
const writeFileSyncMock = fs.writeFileSync as jest.Mock;
186186
const comment = writeFileSyncMock.mock.calls[0][1];
187-
expect(comment).toContain('❌ FAILED');
188-
expect(comment).toContain('No Data');
187+
expect(comment).toContain('| project-a | lines | 80% | No Data | ❌ FAILED |');
188+
expect(comment).toContain('| | statements | 80% | No Data | ❌ FAILED |');
189+
expect(comment).toContain('| | functions | 75% | No Data | ❌ FAILED |');
190+
expect(comment).toContain('| | branches | 70% | No Data | ❌ FAILED |');
189191
expect(comment).toContain('### Overall Status: ⚠️ WARNING (1 project failing)');
190192
});
191193

@@ -328,7 +330,10 @@ describe('coverage-evaluator', () => {
328330
expect(comment).toContain('| project-c | lines | 70% | 65.00% | ❌ FAILED |');
329331

330332
// Project D has no coverage data
331-
expect(comment).toContain('| project-d | All | Defined | No Data | ❌ FAILED |');
333+
expect(comment).toContain('| project-d | lines | 90% | No Data | ❌ FAILED |');
334+
expect(comment).toContain('| | statements | 90% | No Data | ❌ FAILED |');
335+
expect(comment).toContain('| | functions | 90% | No Data | ❌ FAILED |');
336+
expect(comment).toContain('| | branches | 90% | No Data | ❌ FAILED |');
332337

333338
// Overall status is failed with multiple projects
334339
expect(comment).toContain('### Overall Status: ❌ FAILED (2 projects failing)');

tools/scripts/run-many/coverage-evaluator.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,27 @@ function formatCoverageComment(results: ProjectCoverageResult[], artifactUrl: st
147147
if (result.status === 'SKIPPED') {
148148
comment += `| ${result.project} | All | N/A | N/A | ⏩ SKIPPED |\n`;
149149
} else if (result.actual === null) {
150-
comment += `| ${result.project} | All | Defined | No Data | ❌ FAILED |\n`;
150+
// Show individual thresholds even when coverage data is missing
151+
const metrics = ['lines', 'statements', 'functions', 'branches'];
152+
let hasAnyThreshold = false;
153+
154+
metrics.forEach((metric, index) => {
155+
// Skip metrics that don't have a threshold
156+
if (!result.thresholds[metric]) return;
157+
158+
hasAnyThreshold = true;
159+
const threshold = result.thresholds[metric];
160+
161+
// Only include project name in the first row for this project
162+
const projectCell = index === 0 ? result.project : '';
163+
164+
comment += `| ${projectCell} | ${metric} | ${threshold}% | No Data | ❌ FAILED |\n`;
165+
});
166+
167+
// Fallback if no specific thresholds are defined
168+
if (!hasAnyThreshold) {
169+
comment += `| ${result.project} | All | Defined | No Data | ❌ FAILED |\n`;
170+
}
151171
} else {
152172
const metrics = ['lines', 'statements', 'functions', 'branches'];
153173
metrics.forEach((metric, index) => {

0 commit comments

Comments
 (0)