super-pancake-automation
Version:
A lightweight DOM-based UI automation framework using Chrome DevTools Protocol
105 lines (88 loc) โข 3.49 kB
JavaScript
import fs from 'fs';
import path from 'path';
import { spawn } from 'child_process';
// Windows compatibility - npx needs .cmd extension on Windows
const isWindows = process.platform === 'win32';
const npxCommand = isWindows ? 'npx.cmd' : 'npx';
const resultsDir = path.resolve('test-report/results');
if (fs.existsSync(resultsDir)) {
const files = fs.readdirSync(resultsDir);
for (const file of files) {
const filePath = path.join(resultsDir, file);
if (fs.statSync(filePath).isDirectory()) {
const nestedFiles = fs.readdirSync(filePath);
for (const nestedFile of nestedFiles) {
if (nestedFile.endsWith('.json')) {
fs.unlinkSync(path.join(filePath, nestedFile));
}
}
} else if (file.endsWith('.json')) {
fs.unlinkSync(filePath);
}
}
}
console.log('\n๐ Starting Vitest run...\n');
const vitest = spawn(npxCommand, ['vitest', 'run'], {
stdio: ['ignore', 'pipe', 'pipe'],
shell: isWindows // Use shell on Windows for better compatibility
});
let stdoutData = '';
let stderrData = '';
vitest.stdout.on('data', (data) => {
const output = data.toString();
stdoutData += output;
process.stdout.write(output);
});
vitest.stderr.on('data', (data) => {
const output = data.toString();
stderrData += output;
process.stderr.write(output);
});
vitest.on('close', (code) => {
console.log('\n๐ --- Test Summary ---');
// Parse results for summary - extract actual test counts from Vitest output
const testLinePassedSkipped = stdoutData.match(/Tests\s+(\d+)\s+passed\s+\|\s+(\d+)\s+skipped/);
const testLinePassedOnly = stdoutData.match(/Tests\s+(\d+)\s+passed\s+\((\d+)\)/);
const testLineMatch = testLinePassedSkipped || testLinePassedOnly;
let passed, failed, skipped, broken, total;
if (testLineMatch) {
passed = parseInt(testLineMatch[1]) || 0;
if (testLinePassedSkipped) {
skipped = parseInt(testLineMatch[2]) || 0;
} else {
skipped = 0;
}
failed = 0; // From exit code 0, we know no tests failed
broken = 0;
total = passed + failed + skipped + broken;
console.log(`๐ Parsed test counts: ${passed} passed, ${skipped} skipped, ${total} total`);
} else {
// Fallback to old symbol counting method
passed = (stdoutData.match(/โ/g) || []).length;
failed = (stdoutData.match(/ร/g) || []).length;
skipped = (stdoutData.match(/โ/g) || []).length;
broken = (stdoutData.match(/โ/g) || []).length;
total = passed + failed + skipped + broken;
console.log(`๐ Using fallback symbol counting: ${passed} passed, ${skipped} skipped, ${total} total`);
}
const summaryTable = `
โโโโโโโโโโโโโโโโฌโโโโโโโโโ
โ Label โ Count โ
โโโโโโโโโโโโโโโโผโโโโโโโโโค
โ ๐งช Total โ ${String(total).padStart(6)} โ
โ โ
Passed โ ${String(passed).padStart(6)} โ
โ โ Failed โ ${String(failed).padStart(6)} โ
โ โ ๏ธ Skipped โ ${String(skipped).padStart(6)} โ
โ ๐ฅ Broken โ ${String(broken).padStart(6)} โ
โ ๐ Exit Code โ ${String(code).padStart(6)} โ
โโโโโโโโโโโโโโโโดโโโโโโโโโ
`.trim();
console.log(`\n${summaryTable}\n`);
if (code !== 0) {
console.error('๐ฅ Some tests failed.');
} else {
console.log('๐ All tests passed.');
}
process.exit(code);
});