@devicecloud.dev/dcd
Version:
Better cloud maestro testing
114 lines (113 loc) • 4.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportDownloadService = void 0;
const path = require("node:path");
const api_gateway_1 = require("../gateways/api-gateway");
/**
* Service for downloading test artifacts and reports
*/
class ReportDownloadService {
/**
* Download test artifacts as a zip file
* @param options Download configuration
* @returns Promise that resolves when download is complete
*/
async downloadArtifacts(options) {
const { apiUrl, apiKey, uploadId, downloadType, artifactsPath = './artifacts.zip', debug = false, logger, warnLogger, } = options;
try {
if (debug && logger) {
logger(`[DEBUG] Downloading artifacts: ${downloadType}`);
}
await api_gateway_1.ApiGateway.downloadArtifactsZip(apiUrl, apiKey, uploadId, downloadType, artifactsPath);
if (logger) {
logger('\n');
logger(`Test artifacts have been downloaded to ${artifactsPath}`);
}
}
catch (error) {
if (debug && logger) {
logger(`[DEBUG] Error downloading artifacts: ${error}`);
}
if (warnLogger) {
warnLogger('Failed to download artifacts');
}
}
}
/**
* Handle downloading reports based on the report type specified
* @param options Report download configuration
* @returns Promise that resolves when download is complete
*/
async downloadReports(options) {
const { reportType, junitPath, allurePath, htmlPath, warnLogger, ...downloadOptions } = options;
switch (reportType) {
case 'junit': {
const reportPath = path.resolve(process.cwd(), junitPath || 'report.xml');
await this.downloadReport('junit', reportPath, {
...downloadOptions,
warnLogger,
});
break;
}
case 'allure': {
const reportPath = path.resolve(process.cwd(), allurePath || 'report.html');
await this.downloadReport('allure', reportPath, {
...downloadOptions,
warnLogger,
});
break;
}
case 'html': {
const htmlReportPath = path.resolve(process.cwd(), htmlPath || 'report.html');
await this.downloadReport('html', htmlReportPath, {
...downloadOptions,
warnLogger,
});
break;
}
default: {
if (warnLogger) {
warnLogger(`Unknown report type: ${reportType}`);
}
}
}
}
/**
* Download a specific report type
* @param type Report type to download
* @param filePath Path where report should be saved
* @param options Download configuration
* @returns Promise that resolves when download is complete
*/
async downloadReport(type, filePath, options) {
const { apiUrl, apiKey, uploadId, debug = false, logger, warnLogger } = options;
try {
if (debug && logger) {
logger(`[DEBUG] Downloading ${type.toUpperCase()} report`);
}
await api_gateway_1.ApiGateway.downloadReportGeneric(apiUrl, apiKey, uploadId, type, filePath);
if (logger) {
logger(`${type.toUpperCase()} test report has been downloaded to ${filePath}`);
}
}
catch (error) {
if (debug && logger) {
logger(`[DEBUG] Error downloading ${type.toUpperCase()} report: ${error}`);
}
const errorMessage = error instanceof Error ? error.message : String(error);
if (warnLogger) {
warnLogger(`Failed to download ${type.toUpperCase()} report: ${errorMessage}`);
if (errorMessage.includes('404')) {
warnLogger(`No ${type.toUpperCase()} reports found for this upload. Make sure your tests generated results.`);
}
else if (errorMessage.includes('EACCES') || errorMessage.includes('EPERM')) {
warnLogger('Permission denied. Check write permissions for the current directory.');
}
else if (errorMessage.includes('ENOENT')) {
warnLogger('Directory does not exist. Make sure you have write access to the current directory.');
}
}
}
}
}
exports.ReportDownloadService = ReportDownloadService;