run-tests.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env node
  2. /**
  3. * Simple Test Runner to Avoid Memory Issues
  4. * Runs tests sequentially with memory cleanup
  5. */
  6. const { spawn } = require('child_process');
  7. const path = require('path');
  8. const testSuites = [
  9. {
  10. name: 'Core Unit Tests',
  11. command: 'npx',
  12. args: ['vitest', 'run', 'tests/video-model.test.js', 'tests/state-management.test.js', 'tests/ipc-integration.test.js'],
  13. timeout: 60000
  14. },
  15. {
  16. name: 'Component Tests',
  17. command: 'npx',
  18. args: ['vitest', 'run', 'tests/status-components.test.js', 'tests/ffmpeg-conversion.test.js'],
  19. timeout: 60000
  20. },
  21. {
  22. name: 'Validation Tests',
  23. command: 'npx',
  24. args: ['vitest', 'run', 'tests/url-validation.test.js'],
  25. timeout: 60000
  26. },
  27. {
  28. name: 'System Tests',
  29. command: 'npx',
  30. args: ['vitest', 'run', 'tests/cross-platform.test.js', 'tests/error-handling.test.js'],
  31. timeout: 60000
  32. },
  33. {
  34. name: 'Accessibility Tests',
  35. command: 'npx',
  36. args: ['vitest', 'run', 'tests/accessibility.test.js'],
  37. timeout: 60000
  38. }
  39. ];
  40. async function runTest(suite) {
  41. return new Promise((resolve) => {
  42. console.log(`\n🧪 Running ${suite.name}...`);
  43. const childProcess = spawn(suite.command, suite.args, {
  44. stdio: 'inherit',
  45. shell: true,
  46. env: {
  47. ...process.env,
  48. NODE_OPTIONS: '--max-old-space-size=2048'
  49. }
  50. });
  51. const timeout = setTimeout(() => {
  52. console.log(`⏰ Test suite ${suite.name} timed out`);
  53. childProcess.kill('SIGTERM');
  54. resolve({ success: false, timeout: true });
  55. }, suite.timeout);
  56. childProcess.on('close', (code) => {
  57. clearTimeout(timeout);
  58. const success = code === 0;
  59. console.log(`${success ? '✅' : '❌'} ${suite.name} ${success ? 'passed' : 'failed'}`);
  60. resolve({ success, code });
  61. });
  62. childProcess.on('error', (error) => {
  63. clearTimeout(timeout);
  64. console.error(`💥 Error running ${suite.name}:`, error.message);
  65. resolve({ success: false, error: error.message });
  66. });
  67. });
  68. }
  69. async function runAllTests() {
  70. console.log('🚀 Starting GrabZilla Test Suite');
  71. console.log(`📅 ${new Date().toISOString()}`);
  72. console.log(`🖥️ Platform: ${process.platform} (${process.arch})`);
  73. console.log(`📦 Node.js: ${process.version}`);
  74. const results = [];
  75. for (const suite of testSuites) {
  76. const result = await runTest(suite);
  77. results.push({ ...suite, ...result });
  78. // Force garbage collection between tests if available
  79. if (global.gc) {
  80. global.gc();
  81. }
  82. // Small delay between test suites
  83. await new Promise(resolve => setTimeout(resolve, 1000));
  84. }
  85. // Generate report
  86. console.log('\n' + '='.repeat(60));
  87. console.log('📊 TEST EXECUTION REPORT');
  88. console.log('='.repeat(60));
  89. let passed = 0;
  90. let failed = 0;
  91. results.forEach(result => {
  92. const status = result.success ? 'PASSED' : 'FAILED';
  93. const icon = result.success ? '✅' : '❌';
  94. console.log(`${icon} ${result.name.padEnd(25)} ${status}`);
  95. if (result.success) {
  96. passed++;
  97. } else {
  98. failed++;
  99. }
  100. });
  101. console.log('-'.repeat(60));
  102. console.log(`📈 Summary: ${passed} passed, ${failed} failed`);
  103. if (failed > 0) {
  104. console.log('\n❌ Some tests failed. Check the output above for details.');
  105. process.exit(1);
  106. } else {
  107. console.log('\n🎉 All tests completed successfully!');
  108. process.exit(0);
  109. }
  110. }
  111. // Handle CLI arguments
  112. const args = process.argv.slice(2);
  113. if (args.includes('--help') || args.includes('-h')) {
  114. console.log('Usage: node run-tests.js');
  115. console.log('Runs all test suites sequentially to avoid memory issues');
  116. process.exit(0);
  117. }
  118. runAllTests().catch(error => {
  119. console.error('💥 Test runner failed:', error);
  120. process.exit(1);
  121. });