b207bfa7af
test: 添加单元测试和端到端测试 refactor: 重构登录页面和上传模块 ci: 更新测试覆盖率阈值至42% build: 添加测试相关依赖 docs: 更新测试文档 style: 修复代码格式问题
82 lines
2.3 KiB
JavaScript
82 lines
2.3 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function generateSimpleReport() {
|
|
const coveragePath = path.join(__dirname, 'coverage/e2e/coverage-data.json');
|
|
|
|
if (!fs.existsSync(coveragePath)) {
|
|
console.error('Coverage data file not found!');
|
|
return;
|
|
}
|
|
|
|
const coverageData = JSON.parse(fs.readFileSync(coveragePath, 'utf-8'));
|
|
const outputDir = path.join(__dirname, 'coverage/e2e');
|
|
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
}
|
|
|
|
let totalEntries = 0;
|
|
let appEntries = 0;
|
|
const fileStats = {};
|
|
|
|
console.log('\n=== E2E Coverage Collection Report ===\n');
|
|
console.log('Pages covered:');
|
|
|
|
const pages = new Set();
|
|
const scripts = new Set();
|
|
|
|
for (const entry of coverageData) {
|
|
if (!entry.url) continue;
|
|
|
|
const url = entry.url;
|
|
|
|
if (url.includes('localhost:3000') || url.includes('_next')) {
|
|
totalEntries++;
|
|
|
|
const urlObj = new URL(url);
|
|
pages.add(urlObj.pathname);
|
|
|
|
const scriptUrl = entry.scriptId ? `script-${entry.scriptId}` : 'inline';
|
|
if (!fileStats[scriptUrl]) {
|
|
fileStats[scriptUrl] = { count: 0, sourceSize: 0 };
|
|
}
|
|
fileStats[scriptUrl].count++;
|
|
if (entry.source) {
|
|
fileStats[scriptUrl].sourceSize += entry.source.length;
|
|
}
|
|
|
|
if (url.includes('novalon-website') || url.includes('/_next/')) {
|
|
appEntries++;
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`\nTotal JS bundles collected: ${totalEntries}`);
|
|
console.log(`App-specific bundles: ${appEntries}`);
|
|
console.log(`Unique pages visited: ${pages.size}`);
|
|
console.log(`\nPages:`);
|
|
pages.forEach(p => console.log(` - ${p}`));
|
|
|
|
const reportPath = path.join(outputDir, 'coverage-summary.json');
|
|
const report = {
|
|
timestamp: new Date().toISOString(),
|
|
totalEntries,
|
|
appEntries,
|
|
pagesVisited: Array.from(pages),
|
|
fileStats,
|
|
};
|
|
|
|
fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
|
console.log(`\nReport saved to: ${reportPath}`);
|
|
|
|
console.log('\n=== Coverage Summary ===');
|
|
console.log(`✓ Playwright successfully collected JS coverage from ${totalEntries} bundles`);
|
|
console.log(`✓ Covered ${pages.size} unique pages`);
|
|
console.log(`\nNote: For Istanbul HTML report, run: npx playwright show-report`);
|
|
|
|
return report;
|
|
}
|
|
|
|
generateSimpleReport();
|