-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-summary-reporter.js
More file actions
60 lines (50 loc) · 2.27 KB
/
test-summary-reporter.js
File metadata and controls
60 lines (50 loc) · 2.27 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
class TestSummaryReporter {
constructor(globalConfig, options) {
this._globalConfig = globalConfig;
this._options = options;
this.suiteStats = {};
}
onTestResult(test, testResult) {
testResult.testResults.forEach((result) => {
const suiteName = this.getSuiteName(result.ancestorTitles);
if (!this.suiteStats[suiteName]) {
this.suiteStats[suiteName] = { passed: 0, failed: 0, total: 0 };
}
this.suiteStats[suiteName].total++;
if (result.status === 'passed') {
this.suiteStats[suiteName].passed++;
} else if (result.status === 'failed') {
this.suiteStats[suiteName].failed++;
}
});
}
getSuiteName(ancestors) {
// Get the top-level suite name (first ancestor)
return ancestors.length > 0 ? ancestors[0] : 'Other';
}
onRunComplete(contexts, results) {
let totalPassed = 0;
let totalFailed = 0;
let totalTests = 0;
const sortedSuites = Object.keys(this.suiteStats).sort();
sortedSuites.forEach((suiteName) => {
const stats = this.suiteStats[suiteName];
totalPassed += stats.passed;
totalFailed += stats.failed;
totalTests += stats.total;
});
console.log('\n┌─ Test Summary ────────────────────────────────┐');
sortedSuites.forEach((suiteName) => {
const stats = this.suiteStats[suiteName];
const status = stats.failed === 0 ? '✓' : '✗';
const name = suiteName.replace('phantom.', '');
const pct = ((stats.passed / stats.total) * 100).toFixed(0);
console.log(`│ ${status} ${name.padEnd(22)} ${String(stats.passed).padStart(2)}/${stats.total} (${pct}%) │`);
});
const status = totalFailed === 0 ? '✓' : '✗';
console.log(`├───────────────────────────────────────────────┤`);
console.log(`│ ${status} Total: ${totalPassed}/${totalTests}${totalFailed > 0 ? ` (${totalFailed} failed)` : ''}${' '.repeat(25)}│`);
console.log('└───────────────────────────────────────────────┘\n');
}
}
module.exports = TestSummaryReporter;