const fs = require('fs'); const path = require('path'); const reportDir = 'test-results'; const mockResults = [ { testId: 'test-1', file: 'smoke/navigation.smoke.spec.ts', title: '应该成功加载首页', status: 'passed', duration: 15000, tier: 'fast', tags: ['@smoke', '@critical'], }, { testId: 'test-2', file: 'admin/news-management.spec.ts', title: '应该能够创建新闻', status: 'passed', duration: 45000, tier: 'standard', tags: ['@admin', '@regression'], }, { testId: 'test-3', file: 'api/admin.api.spec.ts', title: '应该能够获取内容列表', status: 'failed', duration: 5000, tier: 'fast', tags: ['@api', '@critical'], }, { testId: 'test-4', file: 'visual/homepage-visual.spec.ts', title: '首页视觉回归测试', status: 'passed', duration: 150000, tier: 'deep', tags: ['@visual', '@regression'], }, ]; console.log('📊 Testing test reporter...'); if (!fs.existsSync(reportDir)) { fs.mkdirSync(reportDir, { recursive: true }); } const report = { timestamp: new Date().toISOString(), tiers: { fast: { name: 'fast', total: 2, passed: 1, failed: 1, skipped: 0, duration: 20000, avgDuration: 10000, }, standard: { name: 'standard', total: 1, passed: 1, failed: 0, skipped: 0, duration: 45000, avgDuration: 45000, }, deep: { name: 'deep', total: 1, passed: 1, failed: 0, skipped: 0, duration: 150000, avgDuration: 150000, }, }, total: { name: 'total', total: 4, passed: 3, failed: 1, skipped: 0, duration: 215000, avgDuration: 53750, }, failedTests: mockResults.filter(r => r.status === 'failed'), slowTests: mockResults.filter(r => r.duration > 120000), flakyTests: [], }; const jsonPath = path.join(reportDir, `test-report-${Date.now()}.json`); fs.writeFileSync(jsonPath, JSON.stringify(report, null, 2)); console.log(`✅ JSON报告已保存: ${jsonPath}`); console.log('✅ Report generated:'); console.log(` Total tests: ${report.total.total}`); console.log(` Passed: ${report.total.passed}`); console.log(` Failed: ${report.total.failed}`); console.log(` Duration: ${(report.total.duration / 1000).toFixed(2)}s`); console.log('✅ Test reporter completed');