UNPKG

testgenius-ai

Version:

šŸš€ TestGenius AI - The Ultimate E2E Testing Framework for Everyone | No Coding Required • AI-Powered Automation • Beautiful Reports • Zero Complexity

59 lines • 2.95 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReportGenerator = void 0; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); class ReportGenerator { constructor() { this.reportsDir = path_1.default.join(process.cwd(), 'reports'); } async generate({ summary } = {}) { await fs_extra_1.default.ensureDir(this.reportsDir); const resultsDir = path_1.default.join(process.cwd(), 'test-results'); const sessionDirs = (await fs_extra_1.default.pathExists(resultsDir)) ? await fs_extra_1.default.readdir(resultsDir) : []; const results = []; for (const dir of sessionDirs) { const sessionFile = path_1.default.join(resultsDir, dir, 'session.json'); if (await fs_extra_1.default.pathExists(sessionFile)) { results.push(await fs_extra_1.default.readJson(sessionFile)); } } const html = this.renderHtml(results, summary); const fileName = `report-${Date.now()}.html`; const filePath = path_1.default.join(this.reportsDir, fileName); await fs_extra_1.default.writeFile(filePath, html, 'utf8'); console.log(`\nāœ… Report generated: ${filePath}`); } renderHtml(results, summary) { const total = results.length; const passed = results.filter(r => r.status === 'passed').length; const failed = results.filter(r => r.status === 'failed').length; const successRate = total > 0 ? (passed / total) * 100 : 0; return `<!DOCTYPE html><html><head><title>TestGenius Report</title></head><body> <h1>TestGenius Report</h1> <p>Total: ${total} | Passed: ${passed} | Failed: ${failed} | Success Rate: ${successRate.toFixed(1)}%</p> ${summary ? '' : `<ul>${results.map(r => `<li>${r.testId}: ${r.status}</li>`).join('')}</ul>`} </body></html>`; } async open(filename) { const file = filename ? path_1.default.join(this.reportsDir, filename) : (await this.getLatestReport()); if (!file || !(await fs_extra_1.default.pathExists(file))) { console.log('No report found.'); return; } console.log(`Report available at: ${file}`); console.log('Please open this file in your browser manually.'); } async getLatestReport() { const files = (await fs_extra_1.default.pathExists(this.reportsDir)) ? await fs_extra_1.default.readdir(this.reportsDir) : []; const htmls = files.filter(f => f.endsWith('.html')).sort(); return htmls.length ? path_1.default.join(this.reportsDir, htmls[htmls.length - 1]) : null; } } exports.ReportGenerator = ReportGenerator; //# sourceMappingURL=ReportGenerator.js.map