Repository navigation
Expand file tree
/
Copy pathrun-all-tests.js
More file actions
163 lines (131 loc) · 4.81 KB
/
Copy pathrun-all-tests.js
File metadata and controls
163 lines (131 loc) · 4.81 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env node
/**
* Run all test suites and display aggregate results
*/
const { spawn } = require('child_process');
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const os = require('os');
const tests = [
{ name: 'Special Commands', script: 'npm run test-special-commands', color: 'cyan' },
{ name: 'Environment Issue Detection', script: 'npm run test-env-issue', color: 'yellow' },
{ name: 'Main CLI Tasks', script: 'node test-cli.js', color: 'green' }
];
const results = [];
let totalPassed = 0;
let totalFailed = 0;
let totalSkipped = 0;
let totalTests = 0;
console.log(chalk.bold.cyan('\n========================================'));
console.log(chalk.bold.cyan('Running All Test Suites'));
console.log(chalk.bold.cyan('========================================\n'));
async function runTest(test) {
return new Promise((resolve) => {
console.log(chalk.bold[test.color](`\n▶ Running: ${test.name}...`));
console.log(chalk.gray('─'.repeat(60)) + '\n');
let output = '';
// Parse the script to get command and args
const [cmd, ...args] = test.script.split(' ');
const child = spawn(cmd, args, {
shell: true,
stdio: ['inherit', 'pipe', 'pipe']
});
// Capture and display output in real-time
child.stdout.on('data', (data) => {
const str = data.toString();
output += str;
process.stdout.write(str);
});
child.stderr.on('data', (data) => {
const str = data.toString();
output += str;
process.stderr.write(str);
});
child.on('close', (code) => {
// Parse results from output
let passed = 0;
let failed = 0;
let skipped = 0;
let total = 0;
// Match different test output formats
const passedMatch = output.match(/(?:Passed|✅ Passed):\s*(\d+)/i);
const failedMatch = output.match(/(?:Failed|❌ Failed):\s*(\d+)/i);
const skippedMatch = output.match(/(?:Skipped|⏭️\s*Skipped):\s*(\d+)/i);
const totalMatch = output.match(/(?:Total|📝 Total):\s*(\d+)/i);
if (passedMatch) passed = parseInt(passedMatch[1]);
if (failedMatch) failed = parseInt(failedMatch[1]);
if (skippedMatch) skipped = parseInt(skippedMatch[1]);
if (totalMatch) total = parseInt(totalMatch[1]);
// If no explicit total, calculate it
if (!total && (passed || failed || skipped)) {
total = passed + failed + skipped;
}
const success = code === 0 && failed === 0;
const result = {
name: test.name,
passed,
failed,
skipped,
total,
success
};
results.push(result);
totalPassed += passed;
totalFailed += failed;
totalSkipped += skipped;
totalTests += total;
resolve(result);
});
child.on('error', (error) => {
console.error(chalk.red(`Error running ${test.name}: ${error.message}`));
const result = {
name: test.name,
passed: 0,
failed: 1,
skipped: 0,
total: 1,
success: false
};
results.push(result);
totalFailed += 1;
totalTests += 1;
resolve(result);
});
});
}
async function runAllTests() {
for (const test of tests) {
await runTest(test);
}
// Display aggregate summary
console.log('\n');
console.log(chalk.bold.cyan('========================================'));
console.log(chalk.bold.cyan('AGGREGATE TEST RESULTS'));
console.log(chalk.bold.cyan('========================================\n'));
// Individual suite results
results.forEach(result => {
const icon = result.success ? '✓' : '✗';
const color = result.success ? 'green' : 'red';
console.log(chalk[color].bold(`${icon} ${result.name}`));
console.log(chalk.gray(` Total: ${result.total} | Passed: ${chalk.green(result.passed)} | Failed: ${chalk.red(result.failed)} | Skipped: ${chalk.yellow(result.skipped)}`));
});
console.log('\n' + chalk.gray('─'.repeat(60)));
// Overall totals
console.log(chalk.bold('\n📊 Overall Results:'));
console.log(chalk.gray(` Total Tests: ${totalTests}`));
console.log(chalk.green(` ✓ Passed: ${totalPassed}`));
console.log(chalk.red(` ✗ Failed: ${totalFailed}`));
console.log(chalk.yellow(` ⊘ Skipped: ${totalSkipped}`));
// Success rate
const successRate = totalTests > 0 ? ((totalPassed / totalTests) * 100).toFixed(1) : 0;
console.log(chalk.cyan(` Success Rate: ${successRate}%`));
console.log('\n' + chalk.bold.cyan('========================================\n'));
// Exit with appropriate code
const exitCode = totalFailed > 0 ? 1 : 0;
process.exit(exitCode);
}
runAllTests().catch(error => {
console.error(chalk.red('Fatal error running tests:'), error);
process.exit(1);
});