106 lines
2.7 KiB
JavaScript
106 lines
2.7 KiB
JavaScript
|
|
#!/usr/bin/env bun
|
||
|
|
/**
|
||
|
|
* MASTER TEST RUNNER
|
||
|
|
* ==================
|
||
|
|
* Runs all systematic tests in sequence
|
||
|
|
* Tests are numbered 0-9 for execution order
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { spawn } from 'child_process';
|
||
|
|
import { readdirSync } from 'fs';
|
||
|
|
import { join } from 'path';
|
||
|
|
|
||
|
|
const TESTS_DIR = join(import.meta.dir, 'mjs');
|
||
|
|
const TEST_PATTERN = /^\d+-.*\.test\.mjs$/;
|
||
|
|
|
||
|
|
console.log('🧪 MASTER TEST RUNNER\n');
|
||
|
|
console.log('='.repeat(70));
|
||
|
|
|
||
|
|
// Find all numbered tests
|
||
|
|
const testFiles = readdirSync(TESTS_DIR)
|
||
|
|
.filter(file => TEST_PATTERN.test(file))
|
||
|
|
.sort(); // Numeric sort by prefix
|
||
|
|
|
||
|
|
console.log(`\nFound ${testFiles.length} tests to run:\n`);
|
||
|
|
testFiles.forEach((file, i) => {
|
||
|
|
console.log(` ${i + 1}. ${file}`);
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('\n' + '='.repeat(70));
|
||
|
|
|
||
|
|
const results = [];
|
||
|
|
let currentTest = 0;
|
||
|
|
|
||
|
|
async function runTest(testFile) {
|
||
|
|
return new Promise((resolve) => {
|
||
|
|
currentTest++;
|
||
|
|
const testPath = join(TESTS_DIR, testFile);
|
||
|
|
const testNum = testFile.match(/^(\d+)-/)[1];
|
||
|
|
const testName = testFile.replace(/^\d+-/, '').replace('.test.mjs', '');
|
||
|
|
|
||
|
|
console.log(`\n\n${'='.repeat(70)}`);
|
||
|
|
console.log(`TEST ${currentTest}/${testFiles.length}: ${testName.toUpperCase()}`);
|
||
|
|
console.log(`File: ${testFile}`);
|
||
|
|
console.log('='.repeat(70) + '\n');
|
||
|
|
|
||
|
|
const startTime = Date.now();
|
||
|
|
const child = spawn('bun', [testPath], {
|
||
|
|
stdio: 'inherit',
|
||
|
|
shell: true
|
||
|
|
});
|
||
|
|
|
||
|
|
child.on('close', (code) => {
|
||
|
|
const duration = ((Date.now() - startTime) / 1000).toFixed(2);
|
||
|
|
const passed = code === 0;
|
||
|
|
|
||
|
|
results.push({
|
||
|
|
num: testNum,
|
||
|
|
name: testName,
|
||
|
|
file: testFile,
|
||
|
|
passed,
|
||
|
|
duration
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log(`\n${passed ? '✅ PASSED' : '❌ FAILED'} in ${duration}s`);
|
||
|
|
resolve();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
async function runAllTests() {
|
||
|
|
for (const testFile of testFiles) {
|
||
|
|
await runTest(testFile);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Print summary
|
||
|
|
console.log('\n\n' + '='.repeat(70));
|
||
|
|
console.log('📊 TEST SUMMARY');
|
||
|
|
console.log('='.repeat(70) + '\n');
|
||
|
|
|
||
|
|
const passed = results.filter(r => r.passed).length;
|
||
|
|
const failed = results.length - passed;
|
||
|
|
const totalDuration = results.reduce((sum, r) => sum + parseFloat(r.duration), 0).toFixed(2);
|
||
|
|
|
||
|
|
results.forEach(r => {
|
||
|
|
console.log(` ${r.passed ? '✅' : '❌'} ${r.num}-${r.name} (${r.duration}s)`);
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log(`\n Total: ${passed}/${results.length} passed`);
|
||
|
|
console.log(` Duration: ${totalDuration}s`);
|
||
|
|
|
||
|
|
console.log('\n' + '='.repeat(70));
|
||
|
|
|
||
|
|
if (failed === 0) {
|
||
|
|
console.log('\n🎉 ALL TESTS PASSED!\n');
|
||
|
|
process.exit(0);
|
||
|
|
} else {
|
||
|
|
console.log(`\n❌ ${failed} TEST(S) FAILED\n`);
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
runAllTests().catch(err => {
|
||
|
|
console.error('Error running tests:', err);
|
||
|
|
process.exit(1);
|
||
|
|
});
|