UNPKG

tdpw

Version:

CLI tool for uploading Playwright test reports to TestDino platform with TestDino storage support

154 lines • 7.81 kB
"use strict"; /** * Enhanced Upload command implementation with progress tracking */ Object.defineProperty(exports, "__esModule", { value: true }); exports.UploadCommand = void 0; const types_1 = require("../../types"); const config_1 = require("../../config"); const discovery_1 = require("../../core/discovery"); const upload_1 = require("../../services/upload"); const progress_1 = require("../../utils/progress"); const env_1 = require("../../utils/env"); const version_1 = require("../../version"); /** * Main upload command that orchestrates the entire upload process */ class UploadCommand { name = 'upload'; description = 'Upload Playwright test reports to TestDino'; /** * Execute the upload command with enhanced progress tracking */ async execute(options) { const tracker = (0, progress_1.createProgressTracker)(); try { // Create configuration from CLI options tracker.start('Validating configuration...'); const config = config_1.configLoader.createConfig(options); tracker.succeed('Configuration validated'); // Discover report files tracker.start('Discovering report files...'); const discoveryService = new discovery_1.ReportDiscoveryService(options.reportDirectory); const discoveryResult = await discoveryService.discover(options); const discoveredFiles = []; discoveredFiles.push(`JSON: ${discoveryResult.jsonReport}`); if (discoveryResult.htmlReport) discoveredFiles.push(`HTML: ${discoveryResult.htmlReport}`); if (discoveryResult.traceDir) discoveredFiles.push(`Traces: ${discoveryResult.traceDir}`); const reportTypeText = discoveredFiles.length === 1 ? 'report type' : 'report types'; tracker.succeed(`Found ${discoveredFiles.length} ${reportTypeText}`); // Show verbose configuration if requested if (config.verbose) { this.logVerboseInfo(config, options, discoveryResult); } // Perform actual upload with progress tracking const uploadService = new upload_1.UploadService(config); // Use fallback method for graceful degradation const uploadResponse = await uploadService.uploadWithFallback(discoveryResult.jsonReport, discoveryResult.htmlReport, discoveryResult.traceDir); let testdinoUrl = ''; const environmentType = env_1.EnvironmentUtils.detectEnvironmentType(); if (environmentType === env_1.EnvironmentType.PRODUCTION) { testdinoUrl = `https://app.testdino.com/${uploadResponse.organizationId}/projects/${uploadResponse.projectId}/test-runs/${uploadResponse.testRunId}`; } else if (environmentType === env_1.EnvironmentType.STAGING) { testdinoUrl = `https://staging.testdino.com/${uploadResponse.organizationId}/projects/${uploadResponse.projectId}/test-runs/${uploadResponse.testRunId}`; } else { testdinoUrl = `http://localhost:3001/${uploadResponse.organizationId}/projects/${uploadResponse.projectId}/test-runs/${uploadResponse.testRunId}`; } // Display warnings from server response if present if (uploadResponse.warnings && Array.isArray(uploadResponse.warnings) && uploadResponse.warnings.length > 0) { console.log(); for (const warning of uploadResponse.warnings) { console.warn(`āš ļø ${warning}`); } } // Success output with actionable information console.log(); console.log('Upload completed successfully!'); console.log(); console.log(` TestDino URL: ${testdinoUrl}`); } catch (error) { this.handleUploadError(error, tracker); } } /** * Log verbose configuration information */ logVerboseInfo(config, options, discoveryResult) { console.log('\nšŸ“‹ Upload Configuration:'); console.log(` Report Directory: ${options.reportDirectory}`); console.log(` API Endpoint: ${config.apiUrl}`); console.log(` Upload Images: ${config.uploadImages ? 'Yes' : 'No'}`); console.log(` Upload Videos: ${config.uploadVideos ? 'Yes' : 'No'}`); console.log(` Upload HTML: ${config.uploadHtml ? 'Yes' : 'No'}`); console.log(` Upload Traces: ${config.uploadTraces ? 'Yes' : 'No'}`); console.log(` Verbose Mode: ${config.verbose ? 'Yes' : 'No'}`); console.log('\nšŸ“ Discovered Files:'); console.log(` JSON Report: ${discoveryResult.jsonReport}`); if (discoveryResult.htmlReport) { console.log(` HTML Report: ${discoveryResult.htmlReport}`); } if (discoveryResult.traceDir) { console.log(` Trace Directory: ${discoveryResult.traceDir}`); } const envInfo = config_1.EnvironmentDetector.getEnvironmentInfo(); console.log('\nšŸŒ Environment Info:'); console.log(` TDPW Version: ${version_1.VERSION}`); console.log(` Type: ${envInfo.type}`); console.log(` CI/CD: ${envInfo.isCI ? `Yes (${envInfo.ciProvider})` : 'No'}`); console.log(` Node.js: ${process.version}`); } /** * Enhanced error handling with actionable feedback */ handleUploadError(error, tracker) { tracker.fail('Upload failed'); if (error instanceof types_1.AuthenticationError) { console.error('\nAuthentication Failed'); console.error('Solutions:'); console.error(' Verify your API token is correct'); console.error(' Check that your token has upload permissions'); console.error(" Ensure you're using the right environment token"); console.error('\nGet help: https://docs.testdino.com/authentication'); process.exit(types_1.ExitCode.AUTHENTICATION_ERROR); } if (error instanceof types_1.NetworkError) { console.error('\nNetwork Error'); console.error(` ${error.message}`); console.error('\nTroubleshooting:'); console.error(' Check your internet connection'); console.error(' Verify the API endpoint is accessible'); console.error(' Verify your configuration and try again'); process.exit(types_1.ExitCode.NETWORK_ERROR); } if (error instanceof types_1.UsageLimitError) { console.error('\nUsage Limit Exceeded'); console.error(' Monthly test case limit reached. Upgrade to Pro (25,000), or Team (75,000) for higher limits.'); process.exit(types_1.ExitCode.USAGE_LIMIT_ERROR); } // Generic error handling const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; console.error(`\nUpload Error: ${errorMessage}`); // Show stack trace in development mode if (process.env.TESTDINO_RUNTIME === 'development') { console.error('\nDebug Information:'); console.error(error); } else { console.error('\nRun with --verbose for detailed error information'); } console.error('\nNeed help?'); console.error(' Documentation: https://docs.testdino.com'); console.error(' Support: support@testdino.com'); console.error(' Issues: https://github.com/testdino-inc/testdino-cli/issues'); process.exit(types_1.ExitCode.GENERAL_ERROR); } } exports.UploadCommand = UploadCommand; //# sourceMappingURL=upload.js.map