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