compile.test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const fs = require('fs');
  2. const path = require('path');
  3. // Simple test to verify TypeScript compilation
  4. function runTests() {
  5. console.log('Running compilation tests...');
  6. const outDir = path.join(__dirname, '../out');
  7. // Check if main output files exist
  8. const mainFiles = [
  9. 'extension.js',
  10. 'xmake.js',
  11. 'terminal.js',
  12. 'process.js'
  13. ];
  14. let allTestsPassed = true;
  15. mainFiles.forEach(file => {
  16. const filePath = path.join(outDir, file);
  17. if (!fs.existsSync(filePath)) {
  18. console.error(`❌ Missing file: ${file}`);
  19. allTestsPassed = false;
  20. return;
  21. }
  22. // Check file is not empty
  23. const content = fs.readFileSync(filePath, 'utf8');
  24. if (content.length === 0) {
  25. console.error(`❌ Empty file: ${file}`);
  26. allTestsPassed = false;
  27. return;
  28. }
  29. console.log(`✅ ${file} - OK`);
  30. });
  31. // Test specific content
  32. try {
  33. const extensionPath = path.join(outDir, 'extension.js');
  34. const extensionContent = fs.readFileSync(extensionPath, 'utf8');
  35. if (extensionContent.includes('activate') && extensionContent.includes('deactivate')) {
  36. console.log('✅ extension.js exports - OK');
  37. } else {
  38. console.error('❌ extension.js missing required exports');
  39. allTestsPassed = false;
  40. }
  41. } catch (e) {
  42. console.error('❌ Error reading extension.js:', e.message);
  43. allTestsPassed = false;
  44. }
  45. // Test XMake class
  46. try {
  47. const xmakePath = path.join(outDir, 'xmake.js');
  48. const xmakeContent = fs.readFileSync(xmakePath, 'utf8');
  49. if (xmakeContent.includes('execCommandsSequentially') && xmakeContent.includes('getConfigureArgs')) {
  50. console.log('✅ xmake.js new methods - OK');
  51. } else {
  52. console.error('❌ xmake.js missing new methods');
  53. allTestsPassed = false;
  54. }
  55. } catch (e) {
  56. console.error('❌ Error reading xmake.js:', e.message);
  57. allTestsPassed = false;
  58. }
  59. // Test Terminal class
  60. try {
  61. const terminalPath = path.join(outDir, 'terminal.js');
  62. const terminalContent = fs.readFileSync(terminalPath, 'utf8');
  63. const hasPromise = terminalContent.includes('return new Promise((resolve) =>');
  64. const hasEvent = terminalContent.includes('onDidEndTaskProcess');
  65. const hasExitCode = terminalContent.includes('e.exitCode') && terminalContent.includes('resolve');
  66. if (hasPromise && hasEvent && hasExitCode) {
  67. console.log('✅ terminal.js updated methods - OK');
  68. } else {
  69. console.error('❌ terminal.js missing updated methods');
  70. allTestsPassed = false;
  71. }
  72. } catch (e) {
  73. console.error('❌ Error reading terminal.js:', e.message);
  74. allTestsPassed = false;
  75. }
  76. if (allTestsPassed) {
  77. console.log('\n🎉 All tests passed!');
  78. process.exit(0);
  79. } else {
  80. console.log('\n❌ Some tests failed!');
  81. process.exit(1);
  82. }
  83. }
  84. runTests();