analyze-test-results.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env node
  2. const fs = require('fs');
  3. const path = require('path');
  4. function analyzeTestResults() {
  5. const resultsDir = path.join(__dirname, '..', 'test-results');
  6. const reportDir = path.join(__dirname, '..', 'tests', 'e2e', 'playwright-report');
  7. console.log('🔍 Analyzing test results...\n');
  8. // 检查测试结果目录
  9. if (!fs.existsSync(resultsDir)) {
  10. console.log('❌ No test results found');
  11. return;
  12. }
  13. // 读取 JUnit 报告
  14. const junitFile = path.join(resultsDir, 'junit.xml');
  15. if (fs.existsSync(junitFile)) {
  16. const junitContent = fs.readFileSync(junitFile, 'utf8');
  17. // 简单的 XML 解析来获取测试统计
  18. const testsMatch = junitContent.match(/tests="(\d+)"/);
  19. const failuresMatch = junitContent.match(/failures="(\d+)"/);
  20. const errorsMatch = junitContent.match(/errors="(\d+)"/);
  21. const totalTests = testsMatch ? parseInt(testsMatch[1]) : 0;
  22. const failures = failuresMatch ? parseInt(failuresMatch[1]) : 0;
  23. const errors = errorsMatch ? parseInt(errorsMatch[1]) : 0;
  24. const passed = totalTests - failures - errors;
  25. console.log('📊 Test Results Summary:');
  26. console.log(`✅ Passed: ${passed}`);
  27. console.log(`❌ Failed: ${failures}`);
  28. console.log(`⚠️ Errors: ${errors}`);
  29. console.log(`📋 Total: ${totalTests}`);
  30. console.log(`🎯 Success Rate: ${((passed / totalTests) * 100).toFixed(1)}%\n`);
  31. if (failures > 0 || errors > 0) {
  32. console.log('🔴 Test failures detected!');
  33. process.exit(1);
  34. } else {
  35. console.log('🟢 All tests passed!');
  36. }
  37. }
  38. // 检查 HTML 报告
  39. if (fs.existsSync(reportDir)) {
  40. console.log('📈 HTML report available at:');
  41. console.log(` file://${path.resolve(reportDir, 'index.html')}\n`);
  42. }
  43. }
  44. // 运行分析
  45. analyzeTestResults();