From d52a1f120418f1293817760d6e7b73dfdebc003e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Tue, 7 Apr 2026 13:30:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(e2e):=20=E4=BF=AE=E5=A4=8D=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=8A=A5=E5=91=8A=E7=BB=9F=E8=AE=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 测试报告显示所有统计数据为0或NaN - calculateStats方法使用了错误的数据源 修复: - 使用testResults数组代替result.suites - 添加空数组检查避免除零错误 - 修复duration字段访问方式 优势: - 测试报告正确显示统计数据 - 避免NaN错误 - 提供准确的测试执行信息 --- novalon-manage-web/e2e/customReporter.ts | 29 ++++++++++++++----- novalon-manage-web/playwright/.auth/user.json | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/novalon-manage-web/e2e/customReporter.ts b/novalon-manage-web/e2e/customReporter.ts index 4cb7bd2..c57a971 100644 --- a/novalon-manage-web/e2e/customReporter.ts +++ b/novalon-manage-web/e2e/customReporter.ts @@ -36,17 +36,32 @@ class CustomReporter implements Reporter { } private calculateStats(result: FullResult): TestStats { - const suites = result.suites || []; - const allTests = suites.flatMap(suite => - suite.specs.flatMap(spec => spec.tests) - ); + const allTests = this.testResults; + + if (allTests.length === 0) { + return { + total: 0, + passed: 0, + failed: 0, + skipped: 0, + flaky: 0, + passRate: 0, + failRate: 0, + skipRate: 0, + flakyRate: 0, + totalDuration: 0, + avgDuration: 0, + slowestTests: [], + failedTests: [], + }; + } const passed = allTests.filter(t => t.status === 'passed'); const failed = allTests.filter(t => t.status === 'failed'); const skipped = allTests.filter(t => t.status === 'skipped'); const flaky = allTests.filter(t => t.status === 'passed' && t.retry >= 1); - const totalDuration = allTests.reduce((sum, t) => sum + (t.duration || 0), 0); + const totalDuration = allTests.reduce((sum, t) => sum + t.duration, 0); const avgDuration = totalDuration / allTests.length; const passRate = (passed.length / allTests.length) * 100; @@ -67,8 +82,8 @@ class CustomReporter implements Reporter { totalDuration, avgDuration, slowestTests: allTests - .filter(t => t.duration) - .sort((a, b) => (b.duration || 0) - (a.duration || 0)) + .filter(t => t.duration > 0) + .sort((a, b) => b.duration - a.duration) .slice(0, 10), failedTests: failed, }; diff --git a/novalon-manage-web/playwright/.auth/user.json b/novalon-manage-web/playwright/.auth/user.json index 3886289..37ad976 100644 --- a/novalon-manage-web/playwright/.auth/user.json +++ b/novalon-manage-web/playwright/.auth/user.json @@ -14,7 +14,7 @@ }, { "name": "token", - "value": "eyJhbGciOiJIUzM4NCJ9.eyJyb2xlcyI6W10sInVzZXJJZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsInN1YiI6ImFkbWluIiwiaWF0IjoxNzc1NTM4MjAxLCJleHAiOjE3NzU2MjQ2MDF9.2Nnu8oTldNpyqZ-6CsgxAFrK5KpVfv0m97Zbe1uxXnShxRQkQwdSxnY3lY9xk0A4" + "value": "eyJhbGciOiJIUzM4NCJ9.eyJyb2xlcyI6W10sInVzZXJJZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsInN1YiI6ImFkbWluIiwiaWF0IjoxNzc1NTM4NzgxLCJleHAiOjE3NzU2MjUxODF9.-YWMX8Fdyt8-W0rppNP5QT6t2KI2HMj95LTijW209EBAav4u1lNuZZvBLUp0mbhT" } ] }