UNPKG

@puberty-labs/clits

Version:

CLiTS (Chrome Logging and Inspection Tool Suite) is a powerful Node.js library for automated Chrome browser testing, logging, and inspection. It provides a comprehensive suite of tools for monitoring network requests, console logs, DOM mutations, and more

72 lines (71 loc) 2.98 kB
// BSD: Handles the formatting and generation of debug reports from extracted data. export class ReportGenerator { static generateReport(options) { const report = { timestamp: new Date().toISOString(), logs: options.logs, options: options.extractionOptions || {}, summary: { totalLogs: options.logs.length, fileTypes: this.analyzeFileTypes(options.logs), } }; // Generate error summary if requested if (options.includeErrorSummary !== false) { report.summary.errors = this.generateErrorSummary(options.logs); } return report; } static analyzeFileTypes(logs) { const fileTypes = {}; logs.forEach(log => { const extension = log.filePath.split('.').pop()?.toLowerCase() || 'unknown'; fileTypes[extension] = (fileTypes[extension] || 0) + 1; }); return fileTypes; } static generateErrorSummary(logs) { // Error pattern matching const errorPatterns = [ { regex: /TypeError:?\s*([^:;\n]+)/i, type: 'TypeError' }, { regex: /ReferenceError:?\s*([^:;\n]+)/i, type: 'ReferenceError' }, { regex: /SyntaxError:?\s*([^:;\n]+)/i, type: 'SyntaxError' }, { regex: /RangeError:?\s*([^:;\n]+)/i, type: 'RangeError' }, { regex: /EvalError:?\s*([^:;\n]+)/i, type: 'EvalError' }, { regex: /URIError:?\s*([^:;\n]+)/i, type: 'URIError' }, { regex: /(\d{3}) error/i, type: 'HTTP Error' }, { regex: /Uncaught exception/i, type: 'Uncaught Exception' }, { regex: /Error:?\s*([^:;\n]+)/i, type: 'General Error' }, { regex: /Failed to/i, type: 'Failure' }, { regex: /warning:?\s*([^:;\n]+)/i, type: 'Warning' }, ]; const errorCounts = {}; let totalErrors = 0; // Analyze each log for errors logs.forEach(log => { const content = log.content || ''; // Check against each error pattern for (const pattern of errorPatterns) { const matches = content.match(new RegExp(pattern.regex, 'g')); if (matches) { errorCounts[pattern.type] = (errorCounts[pattern.type] || 0) + matches.length; totalErrors += matches.length; } } }); // Sort errors by frequency const sortedErrors = Object.entries(errorCounts) .sort(([, countA], [, countB]) => countB - countA) .map(([type, count]) => ({ type, count, percentage: totalErrors > 0 ? Math.round((count / totalErrors) * 100) : 0 })) .slice(0, 10); // Top 10 most common errors return { totalErrors, errorTypes: errorCounts, mostCommonErrors: sortedErrors }; } }