UNPKG

@chtsinc/ch-playwright-report

Version:

Custom Playwright Reporter that logs test and execution results to MongoDB

42 lines 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VideoUploadUtil = 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(); /** * Uploads the given video file to Azure Blob and returns its URL. * @throws {Error} if upload fails or config is invalid. */ class VideoUploadUtil { static async uploadVideoFile(filePath, serviceConfig, report) { let url = null; try { const sasUrl = serviceConfig.chAZRVideoBlobSasUrl; if (!sasUrl) { throw new Error("CHPlaywrightReporter: VideoUploadUtil: missing SAS URL"); } const config = { ch_azure_blob_sas_url: serviceConfig.chAZRVideoBlobSasUrl, }; const blobName = this.createBlobName(filePath, report, serviceConfig.reportTimezone); url = await uploader.upload(filePath, config, blobName); } catch (error) { logger.error(`CHPlaywrightReporter: Video upload failed for: ${filePath}`, error); } return url; } static createBlobName(filePath, report, timeZone) { const extension = (0, file_util_1.getExtension)(filePath) || "webm"; const timestamp = (0, date_fns_tz_1.format)(new Date(), "yyyy-MM-dd_HH-mm-ss", { timeZone: timeZone || "UTC", }); return `report-${report.sessionInfo.sessionId}-${report.site}-${timestamp}${extension.startsWith(".") ? extension : "." + extension}`; } } exports.VideoUploadUtil = VideoUploadUtil; //# sourceMappingURL=video-upload-util.js.map