UNPKG

@playwright-mocks/reporters

Version:

Single Playwright reporter for mock interceptor with configurable logging and HTML report generation utility

66 lines 2.52 kB
import { LoggingService } from './logging.service.js'; import { TestsRunOutputService, HtmlReportGenerator } from './services/index.js'; export class PwMocksReporter { testsRunOutput; htmlReportGenerator; options; loggingService; constructor(options = {}) { this.options = { logs: options.logs ?? false, verbose: options.verbose ?? false, generateHtml: options.generateHtml ?? false, htmlOutputDir: options.htmlOutputDir ?? './mocks-report', htmlTitle: options.htmlTitle ?? 'Playwright Mocks Report', runOutputDir: options.runOutputDir ?? './test-runs', saveAttachments: options.saveAttachments ?? true }; this.loggingService = new LoggingService(this.options); // Initialize the tests run output service this.testsRunOutput = new TestsRunOutputService({ outputDir: this.options.runOutputDir, saveAttachments: this.options.saveAttachments }); // Initialize the HTML report generator this.htmlReportGenerator = new HtmlReportGenerator(this.loggingService); } onBegin(config, suite) { this.loggingService.logBegin(suite.allTests().length); } onTestEnd(test, result) { const testInfo = { id: test.id, title: test.title, file: test.location.file, status: result.status, duration: result.duration || 0, attachments: result.attachments || [] }; // Add test to the run output service this.testsRunOutput.addTest(testInfo); this.loggingService.logTestEnd(testInfo); } onEnd() { // Finalize the run data this.testsRunOutput.finalize(); const runData = this.testsRunOutput.getRunData(); this.loggingService.logSummary(runData.tests); // Generate HTML report if requested if (this.options.generateHtml) { try { const htmlOptions = { outputDir: this.options.htmlOutputDir, title: this.options.htmlTitle }; this.htmlReportGenerator.generateHtmlReport(runData.tests, htmlOptions); } catch (error) { this.loggingService.logHtmlReportError(error); } } } printsToStdio() { return this.loggingService.shouldPrintToStdio(); } } //# sourceMappingURL=pw-mocks-reporter.js.map