UNPKG

super-pancake-automation

Version:

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

122 lines (104 loc) โ€ข 3.96 kB
#!/usr/bin/env node import fs from 'fs'; import path from 'path'; import { exec } from 'child_process'; import { promisify } from 'util'; const execAsync = promisify(exec); // Clean previous results 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'); try { // Use exec instead of spawn for better Windows compatibility const { stdout, stderr } = await execAsync('npx vitest run', { encoding: 'utf8', maxBuffer: 1024 * 1024 * 10 // 10MB buffer }); // Output the results if (stdout) { console.log(stdout); } if (stderr) { console.error(stderr); } // Parse results for summary - extract actual test counts from Vitest output const testLinePassedSkipped = stdout.match(/Tests\s+(\d+)\s+passed\s+\|\s+(\d+)\s+skipped/); const testLinePassedOnly = stdout.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; // No skipped tests in this format } 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 = (stdout.match(/โœ“/g) || []).length; failed = (stdout.match(/ร—/g) || []).length; skipped = (stdout.match(/โ†“/g) || []).length; broken = (stdout.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 โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ `.trim(); console.log('\n๐Ÿ“„ --- Test Summary ---'); console.log(`\n${summaryTable}\n`); if (failed > 0 || broken > 0) { console.error('๐Ÿ’ฅ Some tests failed.'); process.exit(1); } else { console.log('๐ŸŽ‰ All tests completed successfully.'); process.exit(0); } } catch (error) { console.error('\nโŒ Error running tests:'); console.error(error.message); if (error.code === 'ENOENT') { console.error('\n๐Ÿ”ง Troubleshooting:'); console.error('1. Make sure Node.js and npm are installed'); console.error('2. Try running: npm install -g npx'); console.error('3. Verify vitest is available: npx vitest --version'); console.error('4. Check if you have test files in your project'); } if (error.stdout) { console.log('\n๐Ÿ“ค Standard Output:'); console.log(error.stdout); } if (error.stderr) { console.error('\n๐Ÿ“ฅ Standard Error:'); console.error(error.stderr); } process.exit(1); }