const fs = require('fs'); const data = JSON.parse(fs.readFileSync('./test-results/results.json', 'utf8')); console.log('=== 测试结果分析 ===\n'); console.log('总测试数:', data.stats.expected + data.stats.unexpected); console.log('通过:', data.stats.expected); console.log('失败:', data.stats.unexpected); console.log('跳过:', data.stats.skipped); console.log('通过率:', ((data.stats.expected / (data.stats.expected + data.stats.unexpected)) * 100).toFixed(2) + '%'); console.log('执行时间:', (data.stats.duration / 1000 / 60).toFixed(2), '分钟\n'); console.log('=== 失败测试分类 ===\n'); const errorTypes = {}; const failures = []; data.suites.forEach(suite => { if (suite.suites) { suite.suites.forEach(subSuite => { if (subSuite.specs) { subSuite.specs.forEach(spec => { if (!spec.ok) { failures.push({ title: spec.title, file: spec.file, line: spec.line }); errorTypes[spec.title] = (errorTypes[spec.title] || 0) + 1; } }); } }); } }); console.log('失败测试总数:', failures.length); console.log('\n主要失败类型:'); Object.entries(errorTypes) .sort((a, b) => b[1] - a[1]) .slice(0, 15) .forEach(([name, count]) => { console.log(` ${name}: ${count}`); }); console.log('\n=== 按测试套件分类 ===\n'); const suiteFailures = {}; data.suites.forEach(suite => { if (suite.suites) { suite.suites.forEach(subSuite => { const suiteName = subSuite.title || 'Unknown'; if (subSuite.specs) { const failed = subSuite.specs.filter(s => !s.ok).length; const total = subSuite.specs.length; if (failed > 0) { suiteFailures[suiteName] = { failed, total, rate: ((total - failed) / total * 100).toFixed(2) }; } } }); } }); Object.entries(suiteFailures) .sort((a, b) => b[1].failed - a[1].failed) .slice(0, 10) .forEach(([name, stats]) => { console.log(`${name}:`); console.log(` 失败: ${stats.failed}/${stats.total}`); console.log(` 通过率: ${stats.rate}%`); });