run-tests.js 4.4 KB

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