diff --git a/e2e/src/tests/utils/mobile-test-reporter.spec.ts b/e2e/src/tests/utils/mobile-test-reporter.spec.ts new file mode 100644 index 0000000..26ab4fd --- /dev/null +++ b/e2e/src/tests/utils/mobile-test-reporter.spec.ts @@ -0,0 +1,16 @@ +import { test, expect } from '@playwright/test'; +import { MobileTestReporter } from '../../utils/MobileTestReporter'; + +test('MobileTestReporter should generate HTML report', async () => { + const reporter = new MobileTestReporter({} as any); + const html = reporter.generateHtmlReport({ + suites: [], + duration: 10000, + status: 'passed', + } as any); + + expect(html).toContain('移动端测试报告'); + expect(html).toContain('总测试数'); + expect(html).toContain('通过'); + expect(html).toContain('失败'); +}); \ No newline at end of file diff --git a/e2e/src/utils/MobileTestReporter.ts b/e2e/src/utils/MobileTestReporter.ts index 29aa742..6ea7811 100644 --- a/e2e/src/utils/MobileTestReporter.ts +++ b/e2e/src/utils/MobileTestReporter.ts @@ -45,4 +45,54 @@ export class MobileTestReporter { duration: results.duration, }; } + + generateHtmlReport(results: FullResult): string { + const overview = this.generateOverview(results); + + return ` + + + + + + 移动端测试报告 + + + +

移动端测试报告

+
+
+
${overview.total}
+
总测试数
+
+
+
${overview.passed}
+
通过
+
+
+
${overview.failed}
+
失败
+
+
+
${(overview.duration / 1000).toFixed(2)}s
+
执行时间
+
+
+ + + `; + } + + async saveReport(report: string, outputPath: string): Promise { + const fs = await import('fs/promises'); + await fs.writeFile(outputPath, report, 'utf-8'); + } } \ No newline at end of file