UNPKG

@playwright-mocks/reporters

Version:

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

67 lines 2.6 kB
export class LoggingService { options; constructor(options) { this.options = options; } logBegin(totalTests) { if (!this.options.logs) return; console.log('\n--- Playwright Mocks Reporter ---'); console.log(`Total tests: ${totalTests}`); if (this.options.verbose) { console.log(`Configuration:`, { logs: this.options.logs, verbose: this.options.verbose, generateHtml: this.options.generateHtml, htmlOutputDir: this.options.htmlOutputDir, htmlTitle: this.options.htmlTitle }); } } logTestEnd(test) { if (!this.options.logs) return; console.log(`Test: ${test.title} | Status: ${test.status} | Duration: ${test.duration}ms`); if (this.options.verbose) { console.log(` File: ${test.file}`); console.log(` Attachments: ${test.attachments?.length || 0}`); // Log mock-related attachments if any const mockAttachments = test.attachments?.filter(att => att.name?.includes('mock') || att.contentType?.includes('json')) || []; if (mockAttachments.length > 0) { console.log(` Mock attachments: ${mockAttachments.length}`); mockAttachments.forEach(att => { console.log(` - ${att.name} (${att.contentType})`); }); } } } logSummary(tests) { if (!this.options.logs) return; console.log('\n--- Test Summary ---'); for (const test of tests) { console.log(`- ${test.title} [${test.status}] (${test.duration}ms)`); } if (this.options.verbose) { console.log(`\nDetailed Summary:`); console.log(`Total tests: ${tests.length}`); console.log(`Passed: ${tests.filter(t => t.status === 'passed').length}`); console.log(`Failed: ${tests.filter(t => t.status === 'failed').length}`); console.log(`Skipped: ${tests.filter(t => t.status === 'skipped').length}`); } } logHtmlReportGenerated(outputDir) { if (!this.options.logs) return; console.log(`HTML report generated at: ${outputDir}/index.html`); } logHtmlReportError(error) { if (!this.options.logs) return; console.error('Failed to generate HTML report:', error); } shouldPrintToStdio() { return this.options.logs; } } //# sourceMappingURL=logging.service.js.map