UNPKG

@alphabin/trx

Version:

TRX reporter for Playwright tests with Azure Blob Storage upload support

181 lines (180 loc) 6.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConsoleFormatter = void 0; /** * Console output formatting utility for better user experience */ class ConsoleFormatter { /** * Formats the main TRX banner */ static formatBanner() { const banner = [ '', `${this.colors.cyan}${this.colors.bright}╭─────────────────────────────────────╮${this.colors.reset}`, `${this.colors.cyan}${this.colors.bright}│ @alphabin/trx │${this.colors.reset}`, `${this.colors.cyan}${this.colors.bright}╰─────────────────────────────────────╯${this.colors.reset}`, '' ].join('\n'); return banner; } /** * Formats upload status message */ static formatUploadStatus(status, fileCount) { switch (status.status) { case 'uploaded': const fileText = fileCount ? ` (${fileCount} files)` : ''; return `${this.icons.success} HTML report uploaded successfully${fileText}`; case 'failed': return `${this.icons.error} HTML report upload failed`; case 'not-found': return `${this.icons.warning} No HTML reports found to upload`; case 'disabled': return `${this.icons.info} HTML report upload is disabled`; default: return `${this.icons.info} Upload status: ${status.status}`; } } /** * Formats server response message */ static formatServerResponse(success) { if (success) { return `${this.icons.success} Test results sent to TRX server successfully`; } else { return `${this.icons.error} Failed to send test results to TRX server`; } } /** * Formats URL display */ static formatUrl(url, label, icon = this.icons.upload) { return `${icon} ${this.colors.bright}${label}:${this.colors.reset} ${this.colors.cyan}${url}${this.colors.reset}`; } /** * Formats error message for user display */ static formatError(message, details) { let output = `${this.icons.error} ${this.colors.red}${message}${this.colors.reset}`; if (details) { output += `\n${this.colors.dim} ${details}${this.colors.reset}`; } return output; } /** * Formats warning message */ static formatWarning(message, suggestion) { let output = `${this.icons.warning} ${this.colors.yellow}${message}${this.colors.reset}`; if (suggestion) { output += `\n${this.colors.dim} Suggestion: ${suggestion}${this.colors.reset}`; } return output; } /** * Formats info message */ static formatInfo(message) { return `${this.icons.info} ${this.colors.blue}${message}${this.colors.reset}`; } /** * Formats success message */ static formatSuccess(message) { return `${this.icons.success} ${this.colors.green}${message}${this.colors.reset}`; } /** * Formats progress message */ static formatProgress(message) { return `${this.icons.gear} ${this.colors.dim}${message}${this.colors.reset}`; } /** * Formats a divider line */ static formatDivider() { return `${this.colors.dim}${'─'.repeat(50)}${this.colors.reset}`; } /** * Formats the complete results summary */ static formatResultsSummary(serverSuccess, testRunId, serverUrl, azureStatus, fileCount) { const lines = []; // Add banner lines.push(this.formatBanner()); // Server response lines.push(this.formatServerResponse(serverSuccess)); if (serverSuccess && testRunId) { const analysisUrl = `${serverUrl}/test-runs/${testRunId}`; lines.push(this.formatUrl(analysisUrl, 'View test analysis', this.icons.analysis)); } // Upload status lines.push(this.formatUploadStatus(azureStatus, fileCount)); if (azureStatus.status === 'uploaded' && azureStatus.url) { lines.push(this.formatUrl(azureStatus.url, 'HTML Report', this.icons.upload)); } // Add spacing lines.push(''); return lines.join('\n'); } /** * Formats configuration warnings */ static formatConfigWarnings(warnings) { if (warnings.length === 0) return ''; const lines = []; lines.push(this.formatWarning('Configuration Issues:')); for (const warning of warnings) { lines.push(`${this.colors.dim}${warning}${this.colors.reset}`); } lines.push(''); return lines.join('\n'); } /** * Removes color codes for environments that don't support them */ static stripColors(text) { // eslint-disable-next-line no-control-regex return text.replace(/\x1b\[[0-9;]*m/g, ''); } /** * Checks if the current environment supports colors */ static supportsColor() { return !!(process.env.FORCE_COLOR || (process.stdout.isTTY && process.env.TERM !== 'dumb')); } /** * Formats text with color support detection */ static format(text) { return this.supportsColor() ? text : this.stripColors(text); } } exports.ConsoleFormatter = ConsoleFormatter; ConsoleFormatter.colors = { reset: '\x1b[0m', bright: '\x1b[1m', dim: '\x1b[2m', red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', blue: '\x1b[34m', magenta: '\x1b[35m', cyan: '\x1b[36m', white: '\x1b[37m' }; ConsoleFormatter.icons = { success: '✅', error: '❌', warning: '⚠️', info: 'ℹ️', upload: '🌐', analysis: '📊', rocket: '🚀', gear: '⚙️' }; exports.default = ConsoleFormatter;