From b7d400ea4498779640acefe5d726781aa9e54786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Sat, 7 Mar 2026 07:17:34 +0800 Subject: [PATCH] test: add test results analysis script --- e2e/analyze-results.js | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 e2e/analyze-results.js diff --git a/e2e/analyze-results.js b/e2e/analyze-results.js new file mode 100644 index 0000000..11f3e10 --- /dev/null +++ b/e2e/analyze-results.js @@ -0,0 +1,72 @@ +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}%`); + }); \ No newline at end of file