qa360 2.2.7 → 2.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of qa360 might be problematic. Click here for more details.
- package/cli/dist/core/pack/validator.js +9 -1
- package/cli/dist/core/pack-v2/migrator.d.ts +1 -0
- package/cli/dist/core/pack-v2/migrator.js +25 -0
- package/cli/dist/core/pack-v2/validator.js +4 -3
- package/cli/package.json +1 -1
- package/package.json +1 -1
- package/cli/dist/core/core/coverage/analyzer.d.ts +0 -101
- package/cli/dist/core/core/coverage/analyzer.js +0 -415
- package/cli/dist/core/core/coverage/collector.d.ts +0 -74
- package/cli/dist/core/core/coverage/collector.js +0 -459
- package/cli/dist/core/core/coverage/config.d.ts +0 -37
- package/cli/dist/core/core/coverage/config.js +0 -156
- package/cli/dist/core/core/coverage/index.d.ts +0 -11
- package/cli/dist/core/core/coverage/index.js +0 -15
- package/cli/dist/core/core/coverage/types.d.ts +0 -267
- package/cli/dist/core/core/coverage/types.js +0 -6
- package/cli/dist/core/core/coverage/vault.d.ts +0 -95
- package/cli/dist/core/core/coverage/vault.js +0 -405
- package/cli/dist/core/schemas/pack.schema.json +0 -236
- package/cli/dist/schemas/pack.schema.json +0 -236
|
@@ -20,7 +20,15 @@ export class PackValidator {
|
|
|
20
20
|
// Load schema (ES modules compatible)
|
|
21
21
|
const __filename = fileURLToPath(import.meta.url);
|
|
22
22
|
const __dirname = dirname(__filename);
|
|
23
|
-
|
|
23
|
+
// Try multiple paths to handle both development and bundled environments
|
|
24
|
+
let schemaPath = join(__dirname, '../../schemas/pack.schema.json');
|
|
25
|
+
try {
|
|
26
|
+
readFileSync(schemaPath, 'utf8');
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Fallback for bundled environment (cli/dist/core/pack/*.js)
|
|
30
|
+
schemaPath = join(__dirname, '../schemas/pack.schema.json');
|
|
31
|
+
}
|
|
24
32
|
this.schema = JSON.parse(readFileSync(schemaPath, 'utf8'));
|
|
25
33
|
this.ajv.addSchema(this.schema, 'pack-v1');
|
|
26
34
|
}
|
|
@@ -424,8 +424,33 @@ export class PackMigrator {
|
|
|
424
424
|
}
|
|
425
425
|
/**
|
|
426
426
|
* Sanitize gate name for v2 format
|
|
427
|
+
* Handles both strings and objects (from YAML parsing edge cases)
|
|
427
428
|
*/
|
|
428
429
|
sanitizeGateName(gate) {
|
|
430
|
+
// Handle edge case where gate might be an object from YAML parsing
|
|
431
|
+
if (typeof gate !== 'string') {
|
|
432
|
+
// If gate is an object, try to extract a name
|
|
433
|
+
if (gate && typeof gate === 'object') {
|
|
434
|
+
// Try common property names
|
|
435
|
+
const possibleName = gate.name || gate.id || gate.gate;
|
|
436
|
+
if (typeof possibleName === 'string') {
|
|
437
|
+
gate = possibleName;
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
// Fallback: stringify the object keys
|
|
441
|
+
const keys = Object.keys(gate);
|
|
442
|
+
if (keys.length === 1) {
|
|
443
|
+
gate = keys[0];
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
throw new Error(`Invalid gate format: expected string, got object with keys: ${keys.join(', ')}`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
throw new Error(`Invalid gate format: expected string, got ${typeof gate}`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
429
454
|
// Map v1 gate names to v2 conventions
|
|
430
455
|
const nameMap = {
|
|
431
456
|
'api_smoke': 'smoke',
|
|
@@ -370,7 +370,8 @@ export class PackValidatorV2 {
|
|
|
370
370
|
// Validate auth profile reference
|
|
371
371
|
if (gate.auth) {
|
|
372
372
|
// Will be validated against profiles in auth section
|
|
373
|
-
|
|
373
|
+
const adapter = typeof gate.adapter === 'string' ? gate.adapter : '';
|
|
374
|
+
if (adapter && !adapter.includes('api') && !adapter.includes('ui')) {
|
|
374
375
|
warnings.push({
|
|
375
376
|
code: 'QP2V019',
|
|
376
377
|
message: `Auth profile specified but adapter may not support auth`,
|
|
@@ -593,7 +594,7 @@ export class PackValidatorV2 {
|
|
|
593
594
|
return { errors, warnings };
|
|
594
595
|
}
|
|
595
596
|
// Check for API gate with api auth but no auth profile
|
|
596
|
-
const apiGates = Object.entries(pack.gates).filter(([_, g]) => g.adapter
|
|
597
|
+
const apiGates = Object.entries(pack.gates).filter(([_, g]) => typeof g.adapter === 'string' && g.adapter.includes('api'));
|
|
597
598
|
if (apiGates.length > 0 && !pack.auth?.api && !pack.auth?.profiles) {
|
|
598
599
|
warnings.push({
|
|
599
600
|
code: 'QP2V034',
|
|
@@ -603,7 +604,7 @@ export class PackValidatorV2 {
|
|
|
603
604
|
});
|
|
604
605
|
}
|
|
605
606
|
// Check for UI gate with ui auth but no auth profile
|
|
606
|
-
const uiGates = Object.entries(pack.gates).filter(([_, g]) => g.adapter
|
|
607
|
+
const uiGates = Object.entries(pack.gates).filter(([_, g]) => typeof g.adapter === 'string' && g.adapter.includes('ui'));
|
|
607
608
|
if (uiGates.length > 0 && !pack.auth?.ui && !pack.auth?.profiles) {
|
|
608
609
|
warnings.push({
|
|
609
610
|
code: 'QP2V035',
|
package/cli/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coverage Analyzer
|
|
3
|
-
*
|
|
4
|
-
* Analyzes coverage data to provide insights, trends, and recommendations.
|
|
5
|
-
*/
|
|
6
|
-
import type { FileCoverage, CoverageMetrics, CoverageResult, CoverageTrend, CoverageGap, CoverageComparison, CoverageThreshold, CoverageType, CoverageReport } from './types.js';
|
|
7
|
-
/**
|
|
8
|
-
* Historical coverage data point
|
|
9
|
-
*/
|
|
10
|
-
interface HistoricalCoverage {
|
|
11
|
-
runId: string;
|
|
12
|
-
timestamp: number;
|
|
13
|
-
metrics: CoverageMetrics;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Coverage Analyzer class
|
|
17
|
-
*/
|
|
18
|
-
export declare class CoverageAnalyzer {
|
|
19
|
-
private history;
|
|
20
|
-
/**
|
|
21
|
-
* Analyze coverage and generate insights
|
|
22
|
-
*/
|
|
23
|
-
analyze(result: CoverageResult, threshold?: CoverageThreshold): CoverageReport;
|
|
24
|
-
/**
|
|
25
|
-
* Check if coverage meets thresholds
|
|
26
|
-
*/
|
|
27
|
-
checkThresholds(metrics: CoverageMetrics, threshold?: CoverageThreshold): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Check if a single file meets thresholds
|
|
30
|
-
*/
|
|
31
|
-
checkFileThresholds(file: FileCoverage, threshold?: CoverageThreshold): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Find coverage gaps
|
|
34
|
-
*/
|
|
35
|
-
findGaps(files: Record<string, FileCoverage>, threshold?: CoverageThreshold): CoverageGap[];
|
|
36
|
-
/**
|
|
37
|
-
* Calculate priority for covering a file
|
|
38
|
-
*/
|
|
39
|
-
private calculatePriority;
|
|
40
|
-
/**
|
|
41
|
-
* Estimate effort to cover a file
|
|
42
|
-
*/
|
|
43
|
-
private estimateEffort;
|
|
44
|
-
/**
|
|
45
|
-
* Generate test suggestions for a file
|
|
46
|
-
*/
|
|
47
|
-
private generateSuggestions;
|
|
48
|
-
/**
|
|
49
|
-
* Group consecutive numbers into ranges
|
|
50
|
-
*/
|
|
51
|
-
private groupConsecutiveNumbers;
|
|
52
|
-
/**
|
|
53
|
-
* Get top and bottom files by coverage
|
|
54
|
-
*/
|
|
55
|
-
getTopFiles(files: Record<string, FileCoverage>, limit?: number): Array<{
|
|
56
|
-
path: string;
|
|
57
|
-
coverage: number;
|
|
58
|
-
type: 'best' | 'worst';
|
|
59
|
-
}>;
|
|
60
|
-
/**
|
|
61
|
-
* Compare two coverage results
|
|
62
|
-
*/
|
|
63
|
-
compare(baseResult: CoverageResult, compareResult: CoverageResult): CoverageComparison;
|
|
64
|
-
/**
|
|
65
|
-
* Add historical coverage data
|
|
66
|
-
*/
|
|
67
|
-
addHistory(key: string, data: HistoricalCoverage): void;
|
|
68
|
-
/**
|
|
69
|
-
* Get coverage trends
|
|
70
|
-
*/
|
|
71
|
-
getTrends(key: string, type?: CoverageType, limit?: number): CoverageTrend[];
|
|
72
|
-
/**
|
|
73
|
-
* Calculate trend direction
|
|
74
|
-
*/
|
|
75
|
-
getTrendDirection(trends: CoverageTrend[]): 'improving' | 'stable' | 'declining';
|
|
76
|
-
/**
|
|
77
|
-
* Predict future coverage based on trends
|
|
78
|
-
*/
|
|
79
|
-
predictCoverage(key: string, type: CoverageType | undefined, targetCoverage: number): {
|
|
80
|
-
predictedReach: number | null;
|
|
81
|
-
projectedCoverage: number;
|
|
82
|
-
confidence: 'high' | 'medium' | 'low';
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Generate coverage summary text
|
|
86
|
-
*/
|
|
87
|
-
generateSummary(metrics: CoverageMetrics): string;
|
|
88
|
-
/**
|
|
89
|
-
* Format coverage percentage with color indicator
|
|
90
|
-
*/
|
|
91
|
-
formatCoverage(percentage: number, threshold?: number): string;
|
|
92
|
-
/**
|
|
93
|
-
* Clear history
|
|
94
|
-
*/
|
|
95
|
-
clearHistory(key?: string): void;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Create a coverage analyzer
|
|
99
|
-
*/
|
|
100
|
-
export declare function createCoverageAnalyzer(): CoverageAnalyzer;
|
|
101
|
-
export {};
|
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coverage Analyzer
|
|
3
|
-
*
|
|
4
|
-
* Analyzes coverage data to provide insights, trends, and recommendations.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Coverage Analyzer class
|
|
8
|
-
*/
|
|
9
|
-
export class CoverageAnalyzer {
|
|
10
|
-
history = new Map();
|
|
11
|
-
/**
|
|
12
|
-
* Analyze coverage and generate insights
|
|
13
|
-
*/
|
|
14
|
-
analyze(result, threshold) {
|
|
15
|
-
const thresholdsMet = this.checkThresholds(result.metrics, threshold);
|
|
16
|
-
const gaps = this.findGaps(result.files, threshold);
|
|
17
|
-
const topFiles = this.getTopFiles(result.files);
|
|
18
|
-
return {
|
|
19
|
-
runId: `run_${Date.now()}`,
|
|
20
|
-
timestamp: Date.now(),
|
|
21
|
-
metrics: result.metrics,
|
|
22
|
-
byGate: { [result.gate]: result.metrics },
|
|
23
|
-
topFiles,
|
|
24
|
-
gaps: gaps.slice(0, 10), // Top 10 gaps
|
|
25
|
-
thresholdsMet,
|
|
26
|
-
thresholdViolations: gaps.map(g => g.path)
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Check if coverage meets thresholds
|
|
31
|
-
*/
|
|
32
|
-
checkThresholds(metrics, threshold) {
|
|
33
|
-
if (!threshold) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
if (threshold.scope === 'per-file') {
|
|
37
|
-
// Per-file thresholds checked separately
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
if (threshold.line !== undefined && metrics.lineCoverage < threshold.line) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (threshold.branch !== undefined && metrics.branchCoverage < threshold.branch) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (threshold.function !== undefined && metrics.functionCoverage < threshold.function) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
if (threshold.statement !== undefined && metrics.statementCoverage < threshold.statement) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Check if a single file meets thresholds
|
|
56
|
-
*/
|
|
57
|
-
checkFileThresholds(file, threshold) {
|
|
58
|
-
if (!threshold) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
if (threshold.line !== undefined && file.lineCoverage < threshold.line) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
if (threshold.branch !== undefined && file.branchCoverage < threshold.branch) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
if (threshold.function !== undefined && file.functionCoverage < threshold.function) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
if (threshold.statement !== undefined && file.statementCoverage < threshold.statement) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Find coverage gaps
|
|
77
|
-
*/
|
|
78
|
-
findGaps(files, threshold) {
|
|
79
|
-
const gaps = [];
|
|
80
|
-
const targetLine = threshold?.line ?? 80;
|
|
81
|
-
const targetBranch = threshold?.branch ?? 70;
|
|
82
|
-
const targetFunction = threshold?.function ?? 75;
|
|
83
|
-
for (const [path, file] of Object.entries(files)) {
|
|
84
|
-
const minTarget = Math.min(targetLine, targetBranch, targetFunction);
|
|
85
|
-
const avgCoverage = (file.lineCoverage + file.branchCoverage + file.functionCoverage) / 3;
|
|
86
|
-
if (avgCoverage < minTarget) {
|
|
87
|
-
gaps.push({
|
|
88
|
-
path,
|
|
89
|
-
currentCoverage: avgCoverage,
|
|
90
|
-
targetCoverage: minTarget,
|
|
91
|
-
gap: minTarget - avgCoverage,
|
|
92
|
-
priority: this.calculatePriority(file, minTarget),
|
|
93
|
-
effort: this.estimateEffort(file),
|
|
94
|
-
uncoveredCount: file.uncoveredLines.length,
|
|
95
|
-
suggestions: this.generateSuggestions(file)
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
// Sort by gap size, then priority
|
|
100
|
-
gaps.sort((a, b) => {
|
|
101
|
-
if (a.priority !== b.priority) {
|
|
102
|
-
const priorityOrder = { high: 0, medium: 1, low: 2 };
|
|
103
|
-
return priorityOrder[a.priority] - priorityOrder[b.priority];
|
|
104
|
-
}
|
|
105
|
-
return b.gap - a.gap;
|
|
106
|
-
});
|
|
107
|
-
return gaps;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Calculate priority for covering a file
|
|
111
|
-
*/
|
|
112
|
-
calculatePriority(file, target) {
|
|
113
|
-
const gap = target - file.lineCoverage;
|
|
114
|
-
// High priority: large gap in important files
|
|
115
|
-
if (gap > 30) {
|
|
116
|
-
return 'high';
|
|
117
|
-
}
|
|
118
|
-
// Medium priority: moderate gap
|
|
119
|
-
if (gap > 10) {
|
|
120
|
-
return 'medium';
|
|
121
|
-
}
|
|
122
|
-
return 'low';
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Estimate effort to cover a file
|
|
126
|
-
*/
|
|
127
|
-
estimateEffort(file) {
|
|
128
|
-
const complexity = file.totalBranches + file.totalFunctions;
|
|
129
|
-
const uncoveredRatio = file.uncoveredLines.length / Math.max(file.totalLines, 1);
|
|
130
|
-
if (complexity > 100 || uncoveredRatio > 0.5) {
|
|
131
|
-
return 'high';
|
|
132
|
-
}
|
|
133
|
-
if (complexity > 30 || uncoveredRatio > 0.2) {
|
|
134
|
-
return 'medium';
|
|
135
|
-
}
|
|
136
|
-
return 'low';
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Generate test suggestions for a file
|
|
140
|
-
*/
|
|
141
|
-
generateSuggestions(file) {
|
|
142
|
-
const suggestions = [];
|
|
143
|
-
if (file.uncoveredLines.length > 0) {
|
|
144
|
-
const lineRanges = this.groupConsecutiveNumbers(file.uncoveredLines);
|
|
145
|
-
suggestions.push(`Add tests covering lines: ${lineRanges.slice(0, 3).join(', ')}`);
|
|
146
|
-
}
|
|
147
|
-
if (file.branchCoverage < file.lineCoverage) {
|
|
148
|
-
suggestions.push('Add tests for all branch conditions (true/false paths)');
|
|
149
|
-
}
|
|
150
|
-
if (file.functionCoverage < 100) {
|
|
151
|
-
suggestions.push('Add tests for uncovered functions');
|
|
152
|
-
}
|
|
153
|
-
if (file.totalFunctions === 0) {
|
|
154
|
-
suggestions.push('Consider splitting large functions into smaller, testable units');
|
|
155
|
-
}
|
|
156
|
-
return suggestions;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Group consecutive numbers into ranges
|
|
160
|
-
*/
|
|
161
|
-
groupConsecutiveNumbers(numbers) {
|
|
162
|
-
if (numbers.length === 0)
|
|
163
|
-
return [];
|
|
164
|
-
const sorted = [...numbers].sort((a, b) => a - b);
|
|
165
|
-
const ranges = [];
|
|
166
|
-
let start = sorted[0];
|
|
167
|
-
let prev = sorted[0];
|
|
168
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
169
|
-
if (sorted[i] === prev + 1) {
|
|
170
|
-
prev = sorted[i];
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
ranges.push(start === prev ? `${start}` : `${start}-${prev}`);
|
|
174
|
-
start = sorted[i];
|
|
175
|
-
prev = sorted[i];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
ranges.push(start === prev ? `${start}` : `${start}-${prev}`);
|
|
179
|
-
return ranges;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Get top and bottom files by coverage
|
|
183
|
-
*/
|
|
184
|
-
getTopFiles(files, limit = 5) {
|
|
185
|
-
const fileArray = Object.entries(files).map(([path, file]) => ({
|
|
186
|
-
path,
|
|
187
|
-
coverage: file.lineCoverage,
|
|
188
|
-
type: 'best'
|
|
189
|
-
}));
|
|
190
|
-
// Sort by coverage
|
|
191
|
-
fileArray.sort((a, b) => b.coverage - a.coverage);
|
|
192
|
-
const result = [];
|
|
193
|
-
// Best files
|
|
194
|
-
for (let i = 0; i < Math.min(limit, fileArray.length); i++) {
|
|
195
|
-
result.push({ ...fileArray[i], type: 'best' });
|
|
196
|
-
}
|
|
197
|
-
// Worst files
|
|
198
|
-
for (let i = fileArray.length - 1; i >= Math.max(fileArray.length - limit, 0); i--) {
|
|
199
|
-
result.push({ path: fileArray[i].path, coverage: fileArray[i].coverage, type: 'worst' });
|
|
200
|
-
}
|
|
201
|
-
return result;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Compare two coverage results
|
|
205
|
-
*/
|
|
206
|
-
compare(baseResult, compareResult) {
|
|
207
|
-
const baseFiles = baseResult.files;
|
|
208
|
-
const compareFiles = compareResult.files;
|
|
209
|
-
const improved = [];
|
|
210
|
-
const regressed = [];
|
|
211
|
-
const newFiles = [];
|
|
212
|
-
const removedFiles = [];
|
|
213
|
-
// Check all files in base
|
|
214
|
-
for (const [path, baseFile] of Object.entries(baseFiles)) {
|
|
215
|
-
const compareFile = compareFiles[path];
|
|
216
|
-
if (!compareFile) {
|
|
217
|
-
removedFiles.push(path);
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
const delta = compareFile.lineCoverage - baseFile.lineCoverage;
|
|
221
|
-
if (delta > 0.5) {
|
|
222
|
-
improved.push({
|
|
223
|
-
path,
|
|
224
|
-
before: baseFile.lineCoverage,
|
|
225
|
-
after: compareFile.lineCoverage,
|
|
226
|
-
delta
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
else if (delta < -0.5) {
|
|
230
|
-
regressed.push({
|
|
231
|
-
path,
|
|
232
|
-
before: baseFile.lineCoverage,
|
|
233
|
-
after: compareFile.lineCoverage,
|
|
234
|
-
delta
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
// Find new files
|
|
239
|
-
for (const path of Object.keys(compareFiles)) {
|
|
240
|
-
if (!baseFiles[path]) {
|
|
241
|
-
newFiles.push(path);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
// Calculate overall change
|
|
245
|
-
const overallChange = compareResult.metrics.lineCoverage - baseResult.metrics.lineCoverage;
|
|
246
|
-
return {
|
|
247
|
-
baseRunId: `base_${baseResult.timestamp}`,
|
|
248
|
-
compareRunId: `compare_${compareResult.timestamp}`,
|
|
249
|
-
improved,
|
|
250
|
-
regressed,
|
|
251
|
-
newFiles,
|
|
252
|
-
removedFiles,
|
|
253
|
-
overallChange
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Add historical coverage data
|
|
258
|
-
*/
|
|
259
|
-
addHistory(key, data) {
|
|
260
|
-
if (!this.history.has(key)) {
|
|
261
|
-
this.history.set(key, []);
|
|
262
|
-
}
|
|
263
|
-
const history = this.history.get(key);
|
|
264
|
-
history.push(data);
|
|
265
|
-
// Keep only last 100 entries
|
|
266
|
-
if (history.length > 100) {
|
|
267
|
-
history.shift();
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Get coverage trends
|
|
272
|
-
*/
|
|
273
|
-
getTrends(key, type = 'line', limit = 30) {
|
|
274
|
-
const history = this.history.get(key) || [];
|
|
275
|
-
const sorted = history
|
|
276
|
-
.sort((a, b) => a.timestamp - b.timestamp)
|
|
277
|
-
.slice(-limit);
|
|
278
|
-
const trends = [];
|
|
279
|
-
let previousValue = 0;
|
|
280
|
-
for (const entry of sorted) {
|
|
281
|
-
let value;
|
|
282
|
-
switch (type) {
|
|
283
|
-
case 'line':
|
|
284
|
-
value = entry.metrics.lineCoverage;
|
|
285
|
-
break;
|
|
286
|
-
case 'branch':
|
|
287
|
-
value = entry.metrics.branchCoverage;
|
|
288
|
-
break;
|
|
289
|
-
case 'function':
|
|
290
|
-
value = entry.metrics.functionCoverage;
|
|
291
|
-
break;
|
|
292
|
-
case 'statement':
|
|
293
|
-
value = entry.metrics.statementCoverage;
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
trends.push({
|
|
297
|
-
runId: entry.runId,
|
|
298
|
-
timestamp: entry.timestamp,
|
|
299
|
-
coverage: value,
|
|
300
|
-
type,
|
|
301
|
-
change: value - previousValue
|
|
302
|
-
});
|
|
303
|
-
previousValue = value;
|
|
304
|
-
}
|
|
305
|
-
return trends;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Calculate trend direction
|
|
309
|
-
*/
|
|
310
|
-
getTrendDirection(trends) {
|
|
311
|
-
if (trends.length < 3) {
|
|
312
|
-
return 'stable';
|
|
313
|
-
}
|
|
314
|
-
const recent = trends.slice(-5);
|
|
315
|
-
const avgChange = recent.reduce((sum, t) => sum + t.change, 0) / recent.length;
|
|
316
|
-
if (avgChange > 1)
|
|
317
|
-
return 'improving';
|
|
318
|
-
if (avgChange < -1)
|
|
319
|
-
return 'declining';
|
|
320
|
-
return 'stable';
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Predict future coverage based on trends
|
|
324
|
-
*/
|
|
325
|
-
predictCoverage(key, type = 'line', targetCoverage) {
|
|
326
|
-
const trends = this.getTrends(key, type, 20);
|
|
327
|
-
if (trends.length < 5) {
|
|
328
|
-
return {
|
|
329
|
-
predictedReach: null,
|
|
330
|
-
projectedCoverage: trends[trends.length - 1]?.coverage || 0,
|
|
331
|
-
confidence: 'low'
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
// Simple linear regression
|
|
335
|
-
const n = trends.length;
|
|
336
|
-
let sumX = 0;
|
|
337
|
-
let sumY = 0;
|
|
338
|
-
let sumXY = 0;
|
|
339
|
-
let sumXX = 0;
|
|
340
|
-
for (let i = 0; i < n; i++) {
|
|
341
|
-
const x = i;
|
|
342
|
-
const y = trends[i].coverage;
|
|
343
|
-
sumX += x;
|
|
344
|
-
sumY += y;
|
|
345
|
-
sumXY += x * y;
|
|
346
|
-
sumXX += x * x;
|
|
347
|
-
}
|
|
348
|
-
const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
|
|
349
|
-
const intercept = (sumY - slope * sumX) / n;
|
|
350
|
-
const currentCoverage = trends[n - 1].coverage;
|
|
351
|
-
const avgCoverage = sumY / n;
|
|
352
|
-
const variance = trends.reduce((sum, t) => sum + Math.pow(t.coverage - avgCoverage, 2), 0) / n;
|
|
353
|
-
// Determine confidence based on variance
|
|
354
|
-
let confidence;
|
|
355
|
-
if (variance < 25)
|
|
356
|
-
confidence = 'high';
|
|
357
|
-
else if (variance < 100)
|
|
358
|
-
confidence = 'medium';
|
|
359
|
-
else
|
|
360
|
-
confidence = 'low';
|
|
361
|
-
// Project coverage for next run
|
|
362
|
-
const projectedCoverage = currentCoverage + slope;
|
|
363
|
-
// Predict when target will be reached
|
|
364
|
-
let predictedReach = null;
|
|
365
|
-
if (slope > 0.1) {
|
|
366
|
-
const runsNeeded = (targetCoverage - currentCoverage) / slope;
|
|
367
|
-
if (runsNeeded > 0 && runsNeeded < 100) {
|
|
368
|
-
predictedReach = Date.now() + runsNeeded * 24 * 60 * 60 * 1000; // Assume daily runs
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return { predictedReach, projectedCoverage, confidence };
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Generate coverage summary text
|
|
375
|
-
*/
|
|
376
|
-
generateSummary(metrics) {
|
|
377
|
-
const parts = [];
|
|
378
|
-
parts.push(`Line Coverage: ${metrics.lineCoverage.toFixed(1)}%`);
|
|
379
|
-
parts.push(`Branch Coverage: ${metrics.branchCoverage.toFixed(1)}%`);
|
|
380
|
-
parts.push(`Function Coverage: ${metrics.functionCoverage.toFixed(1)}%`);
|
|
381
|
-
if (metrics.totalFiles > 0) {
|
|
382
|
-
parts.push(`Files: ${metrics.filesWithCoverage}/${metrics.totalFiles}`);
|
|
383
|
-
}
|
|
384
|
-
return parts.join(' | ');
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Format coverage percentage with color indicator
|
|
388
|
-
*/
|
|
389
|
-
formatCoverage(percentage, threshold = 80) {
|
|
390
|
-
if (percentage >= threshold) {
|
|
391
|
-
return `✓ ${percentage.toFixed(1)}%`;
|
|
392
|
-
}
|
|
393
|
-
else if (percentage >= threshold - 10) {
|
|
394
|
-
return `⚠ ${percentage.toFixed(1)}%`;
|
|
395
|
-
}
|
|
396
|
-
return `✗ ${percentage.toFixed(1)}%`;
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Clear history
|
|
400
|
-
*/
|
|
401
|
-
clearHistory(key) {
|
|
402
|
-
if (key) {
|
|
403
|
-
this.history.delete(key);
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
this.history.clear();
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Create a coverage analyzer
|
|
412
|
-
*/
|
|
413
|
-
export function createCoverageAnalyzer() {
|
|
414
|
-
return new CoverageAnalyzer();
|
|
415
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coverage Collector
|
|
3
|
-
*
|
|
4
|
-
* Collects coverage data from various test sources.
|
|
5
|
-
* Supports Jest, Vitest, Cypress, Playwright, and LCOV formats.
|
|
6
|
-
*/
|
|
7
|
-
import type { FileCoverage, CoverageMetrics, CoverageResult, CoverageConfig } from './types.js';
|
|
8
|
-
/**
|
|
9
|
-
* Coverage Collector class
|
|
10
|
-
*/
|
|
11
|
-
export declare class CoverageCollector {
|
|
12
|
-
private config;
|
|
13
|
-
constructor(config?: Partial<CoverageConfig>);
|
|
14
|
-
/**
|
|
15
|
-
* Collect coverage from a file path (auto-detect format)
|
|
16
|
-
*/
|
|
17
|
-
collectFromFile(filePath: string): Promise<CoverageResult | null>;
|
|
18
|
-
/**
|
|
19
|
-
* Collect coverage from LCOV format
|
|
20
|
-
*/
|
|
21
|
-
collectFromLcov(filePath: string): Promise<CoverageResult | null>;
|
|
22
|
-
/**
|
|
23
|
-
* Collect coverage from JSON format (Vitest/Istanbul)
|
|
24
|
-
*/
|
|
25
|
-
collectFromJson(filePath: string): Promise<CoverageResult | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Collect coverage from Istanbul format
|
|
28
|
-
*/
|
|
29
|
-
collectFromIstanbul(filePath: string): Promise<CoverageResult | null>;
|
|
30
|
-
/**
|
|
31
|
-
* Parse LCOV format content
|
|
32
|
-
*/
|
|
33
|
-
private parseLcov;
|
|
34
|
-
/**
|
|
35
|
-
* Convert LCOV record to FileCoverage
|
|
36
|
-
*/
|
|
37
|
-
private convertLcovToFileCoverage;
|
|
38
|
-
/**
|
|
39
|
-
* Convert Vitest coverage data to FileCoverage
|
|
40
|
-
*/
|
|
41
|
-
private convertVitestToFileCoverage;
|
|
42
|
-
/**
|
|
43
|
-
* Convert Istanbul coverage data to FileCoverage
|
|
44
|
-
*/
|
|
45
|
-
private convertIstanbulToFileCoverage;
|
|
46
|
-
/**
|
|
47
|
-
* Calculate aggregate metrics from file coverage data
|
|
48
|
-
*/
|
|
49
|
-
calculateMetrics(files: Record<string, FileCoverage>): CoverageMetrics;
|
|
50
|
-
/**
|
|
51
|
-
* Detect coverage format from file path
|
|
52
|
-
*/
|
|
53
|
-
private detectFormat;
|
|
54
|
-
/**
|
|
55
|
-
* Filter files based on include/exclude patterns
|
|
56
|
-
*/
|
|
57
|
-
filterFiles(files: Record<string, FileCoverage>): Record<string, FileCoverage>;
|
|
58
|
-
/**
|
|
59
|
-
* Match path against glob pattern
|
|
60
|
-
*/
|
|
61
|
-
private matchPattern;
|
|
62
|
-
/**
|
|
63
|
-
* Merge multiple coverage results
|
|
64
|
-
*/
|
|
65
|
-
mergeCoverageResults(results: CoverageResult[]): CoverageResult;
|
|
66
|
-
/**
|
|
67
|
-
* Update configuration
|
|
68
|
-
*/
|
|
69
|
-
updateConfig(updates: Partial<CoverageConfig>): void;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Create a coverage collector with default config
|
|
73
|
-
*/
|
|
74
|
-
export declare function createCoverageCollector(config?: Partial<CoverageConfig>): CoverageCollector;
|