UNPKG

super-pancake-automation

Version:

A lightweight DOM-based UI automation framework using Chrome DevTools Protocol

105 lines (88 loc) โ€ข 3.49 kB
#!/usr/bin/env node 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); });