-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathanalyze-coverage-detailed.js
More file actions
101 lines (81 loc) · 3.32 KB
/
Copy pathanalyze-coverage-detailed.js
File metadata and controls
101 lines (81 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Detailed Coverage Attribution Analysis for mcp-debugger
* Run manually with: npm run test:coverage:analyze
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
try {
const summaryPath = path.join(__dirname, 'coverage', 'coverage-summary.json');
if (!fs.existsSync(summaryPath)) {
console.log('No coverage data found. Run: npm run test:coverage');
process.exit(1);
}
const coverage = JSON.parse(fs.readFileSync(summaryPath, 'utf8'));
const overall = coverage.total ? coverage.total.lines.pct : 0;
let totalUncovered = 0;
let totalLines = 0;
const files = [];
for (const [filePath, data] of Object.entries(coverage)) {
if (filePath === 'total') continue;
const uncovered = data.lines.total - data.lines.covered;
totalUncovered += uncovered;
totalLines += data.lines.total;
// Extract relative path for cleaner display
let cleanPath = filePath.replace(process.cwd(), '').replace(/^[/\\]/, '');
cleanPath = cleanPath.replace(/\\/g, '/');
files.push({
path: cleanPath,
coverage: data.lines.pct,
uncovered,
total: data.lines.total
});
}
// Calculate impact on overall coverage
files.forEach(f => {
f.impact = totalLines > 0 ? (f.uncovered / totalLines) * 100 : 0;
});
// Sort by uncovered lines (descending)
files.sort((a, b) => b.uncovered - a.uncovered);
console.log('\nMCP-DEBUGGER DETAILED COVERAGE ANALYSIS');
console.log('═'.repeat(80));
console.log(`Overall Coverage: ${overall.toFixed(1)}%`);
console.log(`Total Lines: ${totalLines.toLocaleString()}`);
console.log(`Uncovered Lines: ${totalUncovered.toLocaleString()}`);
console.log('═'.repeat(80));
console.log('\nFiles sorted by number of uncovered lines (highest impact first):\n');
console.log('Uncovered Coverage Impact File');
console.log('─'.repeat(80));
// Show all files with uncovered lines
files.forEach(f => {
if (f.uncovered > 0) {
console.log(
f.uncovered.toString().padStart(9) +
f.coverage.toFixed(1).padStart(9) + '%' +
('+' + f.impact.toFixed(1) + '%').padStart(8) +
' ' + f.path
);
}
});
console.log('\n' + '─'.repeat(80));
console.log('Impact: Percentage points overall coverage would increase if file reaches 100%');
// Summary insights
console.log('\n' + '═'.repeat(80));
console.log('INSIGHTS:');
console.log('─'.repeat(80));
const top5 = files.slice(0, 5);
const top5Impact = top5.reduce((sum, f) => sum + f.impact, 0);
console.log(`• Top 5 files contain ${top5.reduce((sum, f) => sum + f.uncovered, 0)} uncovered lines`);
console.log(`• Fixing top 5 files would improve coverage by ${top5Impact.toFixed(1)} percentage points`);
console.log(`• This would bring overall coverage from ${overall.toFixed(1)}% to ${(overall + top5Impact).toFixed(1)}%`);
if (files[0] && files[0].uncovered > 50) {
console.log(`\n• Priority: Focus on ${files[0].path.split('/').pop()}`);
console.log(` ${files[0].uncovered} uncovered lines, currently ${files[0].coverage.toFixed(1)}% covered`);
}
console.log('═'.repeat(80) + '\n');
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}