@chtsinc/ch-playwright-report
Version:
Custom Playwright Reporter that logs test and execution results to MongoDB
39 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportUploadUtil = void 0;
const date_fns_tz_1 = require("date-fns-tz");
const ch_logger_1 = require("@chtsinc/ch-logger");
const ch_uploader_1 = require("@chtsinc/ch-uploader");
const file_util_1 = require("./file-util");
const logger = (0, ch_logger_1.getLogger)();
const uploader = new ch_uploader_1.AzureBlobStorageUploader();
class ReportUploadUtil {
static async uploadReportFile(filePath, serviceConfig, report) {
let url = null;
try {
const sasUrl = serviceConfig.chAZRReportBlobSasUrl;
if (!sasUrl) {
throw new Error("CHPlaywrightReporter: ReportUploadUtil: missing SAS URL");
}
const config = {
ch_azure_blob_sas_url: serviceConfig.chAZRReportBlobSasUrl,
};
const blobName = this.createBlobName(filePath, report, serviceConfig.reportTimezone);
url = await uploader.upload(filePath, config, blobName);
}
catch (error) {
logger.error(`CHPlaywrightReporter: Report upload failed for: ${filePath}`, error);
}
return url;
}
static createBlobName(filePath, report, timeZone) {
const extension = (0, file_util_1.getExtension)(filePath) || "zip";
const timestamp = (0, date_fns_tz_1.format)(new Date(), "yyyy-MM-dd_HH-mm-ss", {
timeZone: timeZone || "UTC",
});
const env = report.environmentInfo;
return `${report.site}-${env.environment}-${env.suite}-${timestamp}-${report.executionId}${extension.startsWith(".") ? extension : "." + extension}`;
}
}
exports.ReportUploadUtil = ReportUploadUtil;
//# sourceMappingURL=report-upload-util.js.map