ScuttleBot

Source Blame History 138 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __create = Object.create;
f7eb47b… lmata 3 var __defProp = Object.defineProperty;
f7eb47b… lmata 4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 5 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 6 var __getProtoOf = Object.getPrototypeOf;
f7eb47b… lmata 7 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 8 var __export = (target, all) => {
f7eb47b… lmata 9 for (var name in all)
f7eb47b… lmata 10 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 11 };
f7eb47b… lmata 12 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 13 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 14 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 15 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 17 }
f7eb47b… lmata 18 return to;
f7eb47b… lmata 19 };
f7eb47b… lmata 20 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
f7eb47b… lmata 21 // If the importer is in node compatibility mode or this is not an ESM
f7eb47b… lmata 22 // file that has been converted to a CommonJS file using a Babel-
f7eb47b… lmata 23 // compatible transform (i.e. "__esModule" has not been set), then set
f7eb47b… lmata 24 // "default" to the CommonJS "module.exports" for node compatibility.
f7eb47b… lmata 25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
f7eb47b… lmata 26 mod
f7eb47b… lmata 27 ));
f7eb47b… lmata 28 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 29 var blob_exports = {};
f7eb47b… lmata 30 __export(blob_exports, {
f7eb47b… lmata 31 BlobReporter: () => BlobReporter,
f7eb47b… lmata 32 currentBlobReportVersion: () => currentBlobReportVersion
f7eb47b… lmata 33 });
f7eb47b… lmata 34 module.exports = __toCommonJS(blob_exports);
f7eb47b… lmata 35 var import_fs = __toESM(require("fs"));
f7eb47b… lmata 36 var import_path = __toESM(require("path"));
f7eb47b… lmata 37 var import_stream = require("stream");
f7eb47b… lmata 38 var import_utils = require("playwright-core/lib/utils");
f7eb47b… lmata 39 var import_utils2 = require("playwright-core/lib/utils");
f7eb47b… lmata 40 var import_utilsBundle = require("playwright-core/lib/utilsBundle");
f7eb47b… lmata 41 var import_zipBundle = require("playwright-core/lib/zipBundle");
f7eb47b… lmata 42 var import_base = require("./base");
f7eb47b… lmata 43 var import_teleEmitter = require("./teleEmitter");
f7eb47b… lmata 44 const currentBlobReportVersion = 2;
f7eb47b… lmata 45 class BlobReporter extends import_teleEmitter.TeleReporterEmitter {
f7eb47b… lmata 46 constructor(options) {
f7eb47b… lmata 47 super((message) => this._messages.push(message));
f7eb47b… lmata 48 this._messages = [];
f7eb47b… lmata 49 this._attachments = [];
f7eb47b… lmata 50 this._options = options;
f7eb47b… lmata 51 if (this._options.fileName && !this._options.fileName.endsWith(".zip"))
f7eb47b… lmata 52 throw new Error(`Blob report file name must end with .zip extension: ${this._options.fileName}`);
f7eb47b… lmata 53 this._salt = (0, import_utils2.createGuid)();
f7eb47b… lmata 54 }
f7eb47b… lmata 55 onConfigure(config) {
f7eb47b… lmata 56 const metadata = {
f7eb47b… lmata 57 version: currentBlobReportVersion,
f7eb47b… lmata 58 userAgent: (0, import_utils2.getUserAgent)(),
f7eb47b… lmata 59 // TODO: remove after some time, recommend config.tag instead.
f7eb47b… lmata 60 name: process.env.PWTEST_BOT_NAME,
f7eb47b… lmata 61 shard: config.shard ?? void 0,
f7eb47b… lmata 62 pathSeparator: import_path.default.sep
f7eb47b… lmata 63 };
f7eb47b… lmata 64 this._messages.push({
f7eb47b… lmata 65 method: "onBlobReportMetadata",
f7eb47b… lmata 66 params: metadata
f7eb47b… lmata 67 });
f7eb47b… lmata 68 this._config = config;
f7eb47b… lmata 69 super.onConfigure(config);
f7eb47b… lmata 70 }
f7eb47b… lmata 71 async onTestPaused(test, result) {
f7eb47b… lmata 72 }
f7eb47b… lmata 73 async onEnd(result) {
f7eb47b… lmata 74 await super.onEnd(result);
f7eb47b… lmata 75 const zipFileName = await this._prepareOutputFile();
f7eb47b… lmata 76 const zipFile = new import_zipBundle.yazl.ZipFile();
f7eb47b… lmata 77 const zipFinishPromise = new import_utils2.ManualPromise();
f7eb47b… lmata 78 const finishPromise = zipFinishPromise.catch((e) => {
f7eb47b… lmata 79 throw new Error(`Failed to write report ${zipFileName}: ` + e.message);
f7eb47b… lmata 80 });
f7eb47b… lmata 81 zipFile.on("error", (error) => zipFinishPromise.reject(error));
f7eb47b… lmata 82 zipFile.outputStream.pipe(import_fs.default.createWriteStream(zipFileName)).on("close", () => {
f7eb47b… lmata 83 zipFinishPromise.resolve(void 0);
f7eb47b… lmata 84 }).on("error", (error) => zipFinishPromise.reject(error));
f7eb47b… lmata 85 for (const { originalPath, zipEntryPath } of this._attachments) {
f7eb47b… lmata 86 if (!import_fs.default.statSync(originalPath, { throwIfNoEntry: false })?.isFile())
f7eb47b… lmata 87 continue;
f7eb47b… lmata 88 zipFile.addFile(originalPath, zipEntryPath);
f7eb47b… lmata 89 }
f7eb47b… lmata 90 const lines = this._messages.map((m) => JSON.stringify(m) + "\n");
f7eb47b… lmata 91 const content = import_stream.Readable.from(lines);
f7eb47b… lmata 92 zipFile.addReadStream(content, "report.jsonl");
f7eb47b… lmata 93 zipFile.end();
f7eb47b… lmata 94 await finishPromise;
f7eb47b… lmata 95 }
f7eb47b… lmata 96 async _prepareOutputFile() {
f7eb47b… lmata 97 const { outputFile, outputDir } = (0, import_base.resolveOutputFile)("BLOB", {
f7eb47b… lmata 98 ...this._options,
f7eb47b… lmata 99 default: {
f7eb47b… lmata 100 fileName: this._defaultReportName(this._config),
f7eb47b… lmata 101 outputDir: "blob-report"
f7eb47b… lmata 102 }
f7eb47b… lmata 103 });
f7eb47b… lmata 104 if (!process.env.PWTEST_BLOB_DO_NOT_REMOVE)
f7eb47b… lmata 105 await (0, import_utils.removeFolders)([outputDir]);
f7eb47b… lmata 106 await import_fs.default.promises.mkdir(import_path.default.dirname(outputFile), { recursive: true });
f7eb47b… lmata 107 return outputFile;
f7eb47b… lmata 108 }
f7eb47b… lmata 109 _defaultReportName(config) {
f7eb47b… lmata 110 let reportName = "report";
f7eb47b… lmata 111 if (this._options._commandHash)
f7eb47b… lmata 112 reportName += "-" + (0, import_utils.sanitizeForFilePath)(this._options._commandHash);
f7eb47b… lmata 113 if (config.shard) {
f7eb47b… lmata 114 const paddedNumber = `${config.shard.current}`.padStart(`${config.shard.total}`.length, "0");
f7eb47b… lmata 115 reportName = `${reportName}-${paddedNumber}`;
f7eb47b… lmata 116 }
f7eb47b… lmata 117 return `${reportName}.zip`;
f7eb47b… lmata 118 }
f7eb47b… lmata 119 _serializeAttachments(attachments) {
f7eb47b… lmata 120 return super._serializeAttachments(attachments).map((attachment) => {
f7eb47b… lmata 121 if (!attachment.path)
f7eb47b… lmata 122 return attachment;
f7eb47b… lmata 123 const sha1 = (0, import_utils2.calculateSha1)(attachment.path + this._salt);
f7eb47b… lmata 124 const extension = import_utilsBundle.mime.getExtension(attachment.contentType) || "dat";
f7eb47b… lmata 125 const newPath = `resources/${sha1}.${extension}`;
f7eb47b… lmata 126 this._attachments.push({ originalPath: attachment.path, zipEntryPath: newPath });
f7eb47b… lmata 127 return {
f7eb47b… lmata 128 ...attachment,
f7eb47b… lmata 129 path: newPath
f7eb47b… lmata 130 };
f7eb47b… lmata 131 });
f7eb47b… lmata 132 }
f7eb47b… lmata 133 }
f7eb47b… lmata 134 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 135 0 && (module.exports = {
f7eb47b… lmata 136 BlobReporter,
f7eb47b… lmata 137 currentBlobReportVersion
f7eb47b… lmata 138 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button