ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / reporters / teleEmitter.js
Source Blame History 317 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 teleEmitter_exports = {};
f7eb47b… lmata 30 __export(teleEmitter_exports, {
f7eb47b… lmata 31 TeleReporterEmitter: () => TeleReporterEmitter
f7eb47b… lmata 32 });
f7eb47b… lmata 33 module.exports = __toCommonJS(teleEmitter_exports);
f7eb47b… lmata 34 var import_path = __toESM(require("path"));
f7eb47b… lmata 35 var import_utils = require("playwright-core/lib/utils");
f7eb47b… lmata 36 var import_teleReceiver = require("../isomorphic/teleReceiver");
f7eb47b… lmata 37 class TeleReporterEmitter {
f7eb47b… lmata 38 constructor(messageSink, options = {}) {
f7eb47b… lmata 39 this._resultKnownAttachmentCounts = /* @__PURE__ */ new Map();
f7eb47b… lmata 40 this._resultKnownErrorCounts = /* @__PURE__ */ new Map();
f7eb47b… lmata 41 // In case there is blob reporter and UI mode, make sure one doesn't override
f7eb47b… lmata 42 // the id assigned by the other.
f7eb47b… lmata 43 this._idSymbol = Symbol("id");
f7eb47b… lmata 44 this._messageSink = messageSink;
f7eb47b… lmata 45 this._emitterOptions = options;
f7eb47b… lmata 46 }
f7eb47b… lmata 47 version() {
f7eb47b… lmata 48 return "v2";
f7eb47b… lmata 49 }
f7eb47b… lmata 50 onConfigure(config) {
f7eb47b… lmata 51 this._rootDir = config.rootDir;
f7eb47b… lmata 52 this._messageSink({ method: "onConfigure", params: { config: this._serializeConfig(config) } });
f7eb47b… lmata 53 }
f7eb47b… lmata 54 onBegin(suite) {
f7eb47b… lmata 55 const projects = suite.suites.map((projectSuite) => this._serializeProject(projectSuite));
f7eb47b… lmata 56 for (const project of projects)
f7eb47b… lmata 57 this._messageSink({ method: "onProject", params: { project } });
f7eb47b… lmata 58 this._messageSink({ method: "onBegin", params: void 0 });
f7eb47b… lmata 59 }
f7eb47b… lmata 60 onTestBegin(test, result) {
f7eb47b… lmata 61 result[this._idSymbol] = (0, import_utils.createGuid)();
f7eb47b… lmata 62 this._messageSink({
f7eb47b… lmata 63 method: "onTestBegin",
f7eb47b… lmata 64 params: {
f7eb47b… lmata 65 testId: test.id,
f7eb47b… lmata 66 result: this._serializeResultStart(result)
f7eb47b… lmata 67 }
f7eb47b… lmata 68 });
f7eb47b… lmata 69 }
f7eb47b… lmata 70 async onTestPaused(test, result) {
f7eb47b… lmata 71 const resultId = result[this._idSymbol];
f7eb47b… lmata 72 this._resultKnownErrorCounts.set(resultId, result.errors.length);
f7eb47b… lmata 73 this._messageSink({
f7eb47b… lmata 74 method: "onTestPaused",
f7eb47b… lmata 75 params: {
f7eb47b… lmata 76 testId: test.id,
f7eb47b… lmata 77 resultId,
f7eb47b… lmata 78 errors: result.errors
f7eb47b… lmata 79 }
f7eb47b… lmata 80 });
f7eb47b… lmata 81 await new Promise(() => {
f7eb47b… lmata 82 });
f7eb47b… lmata 83 }
f7eb47b… lmata 84 onTestEnd(test, result) {
f7eb47b… lmata 85 const testEnd = {
f7eb47b… lmata 86 testId: test.id,
f7eb47b… lmata 87 expectedStatus: test.expectedStatus,
f7eb47b… lmata 88 timeout: test.timeout,
f7eb47b… lmata 89 annotations: []
f7eb47b… lmata 90 };
f7eb47b… lmata 91 this._sendNewAttachments(result, test.id);
f7eb47b… lmata 92 this._messageSink({
f7eb47b… lmata 93 method: "onTestEnd",
f7eb47b… lmata 94 params: {
f7eb47b… lmata 95 test: testEnd,
f7eb47b… lmata 96 result: this._serializeResultEnd(result)
f7eb47b… lmata 97 }
f7eb47b… lmata 98 });
f7eb47b… lmata 99 const resultId = result[this._idSymbol];
f7eb47b… lmata 100 this._resultKnownAttachmentCounts.delete(resultId);
f7eb47b… lmata 101 this._resultKnownErrorCounts.delete(resultId);
f7eb47b… lmata 102 }
f7eb47b… lmata 103 onStepBegin(test, result, step) {
f7eb47b… lmata 104 step[this._idSymbol] = (0, import_utils.createGuid)();
f7eb47b… lmata 105 this._messageSink({
f7eb47b… lmata 106 method: "onStepBegin",
f7eb47b… lmata 107 params: {
f7eb47b… lmata 108 testId: test.id,
f7eb47b… lmata 109 resultId: result[this._idSymbol],
f7eb47b… lmata 110 step: this._serializeStepStart(step)
f7eb47b… lmata 111 }
f7eb47b… lmata 112 });
f7eb47b… lmata 113 }
f7eb47b… lmata 114 onStepEnd(test, result, step) {
f7eb47b… lmata 115 const resultId = result[this._idSymbol];
f7eb47b… lmata 116 this._sendNewAttachments(result, test.id);
f7eb47b… lmata 117 this._messageSink({
f7eb47b… lmata 118 method: "onStepEnd",
f7eb47b… lmata 119 params: {
f7eb47b… lmata 120 testId: test.id,
f7eb47b… lmata 121 resultId,
f7eb47b… lmata 122 step: this._serializeStepEnd(step, result)
f7eb47b… lmata 123 }
f7eb47b… lmata 124 });
f7eb47b… lmata 125 }
f7eb47b… lmata 126 onError(error) {
f7eb47b… lmata 127 this._messageSink({
f7eb47b… lmata 128 method: "onError",
f7eb47b… lmata 129 params: { error }
f7eb47b… lmata 130 });
f7eb47b… lmata 131 }
f7eb47b… lmata 132 onStdOut(chunk, test, result) {
f7eb47b… lmata 133 this._onStdIO("stdout", chunk, test, result);
f7eb47b… lmata 134 }
f7eb47b… lmata 135 onStdErr(chunk, test, result) {
f7eb47b… lmata 136 this._onStdIO("stderr", chunk, test, result);
f7eb47b… lmata 137 }
f7eb47b… lmata 138 _onStdIO(type, chunk, test, result) {
f7eb47b… lmata 139 if (this._emitterOptions.omitOutput)
f7eb47b… lmata 140 return;
f7eb47b… lmata 141 const isBase64 = typeof chunk !== "string";
f7eb47b… lmata 142 const data = isBase64 ? chunk.toString("base64") : chunk;
f7eb47b… lmata 143 this._messageSink({
f7eb47b… lmata 144 method: "onStdIO",
f7eb47b… lmata 145 params: { testId: test?.id, resultId: result ? result[this._idSymbol] : void 0, type, data, isBase64 }
f7eb47b… lmata 146 });
f7eb47b… lmata 147 }
f7eb47b… lmata 148 async onEnd(result) {
f7eb47b… lmata 149 const resultPayload = {
f7eb47b… lmata 150 status: result.status,
f7eb47b… lmata 151 startTime: result.startTime.getTime(),
f7eb47b… lmata 152 duration: result.duration
f7eb47b… lmata 153 };
f7eb47b… lmata 154 this._messageSink({
f7eb47b… lmata 155 method: "onEnd",
f7eb47b… lmata 156 params: {
f7eb47b… lmata 157 result: resultPayload
f7eb47b… lmata 158 }
f7eb47b… lmata 159 });
f7eb47b… lmata 160 }
f7eb47b… lmata 161 printsToStdio() {
f7eb47b… lmata 162 return false;
f7eb47b… lmata 163 }
f7eb47b… lmata 164 _serializeConfig(config) {
f7eb47b… lmata 165 return {
f7eb47b… lmata 166 configFile: this._relativePath(config.configFile),
f7eb47b… lmata 167 globalTimeout: config.globalTimeout,
f7eb47b… lmata 168 maxFailures: config.maxFailures,
f7eb47b… lmata 169 metadata: config.metadata,
f7eb47b… lmata 170 rootDir: config.rootDir,
f7eb47b… lmata 171 version: config.version,
f7eb47b… lmata 172 workers: config.workers,
f7eb47b… lmata 173 globalSetup: config.globalSetup,
f7eb47b… lmata 174 globalTeardown: config.globalTeardown,
f7eb47b… lmata 175 tags: config.tags,
f7eb47b… lmata 176 webServer: config.webServer
f7eb47b… lmata 177 };
f7eb47b… lmata 178 }
f7eb47b… lmata 179 _serializeProject(suite) {
f7eb47b… lmata 180 const project = suite.project();
f7eb47b… lmata 181 const report = {
f7eb47b… lmata 182 metadata: project.metadata,
f7eb47b… lmata 183 name: project.name,
f7eb47b… lmata 184 outputDir: this._relativePath(project.outputDir),
f7eb47b… lmata 185 repeatEach: project.repeatEach,
f7eb47b… lmata 186 retries: project.retries,
f7eb47b… lmata 187 testDir: this._relativePath(project.testDir),
f7eb47b… lmata 188 testIgnore: (0, import_teleReceiver.serializeRegexPatterns)(project.testIgnore),
f7eb47b… lmata 189 testMatch: (0, import_teleReceiver.serializeRegexPatterns)(project.testMatch),
f7eb47b… lmata 190 timeout: project.timeout,
f7eb47b… lmata 191 suites: suite.suites.map((fileSuite) => {
f7eb47b… lmata 192 return this._serializeSuite(fileSuite);
f7eb47b… lmata 193 }),
f7eb47b… lmata 194 grep: (0, import_teleReceiver.serializeRegexPatterns)(project.grep),
f7eb47b… lmata 195 grepInvert: (0, import_teleReceiver.serializeRegexPatterns)(project.grepInvert || []),
f7eb47b… lmata 196 dependencies: project.dependencies,
f7eb47b… lmata 197 snapshotDir: this._relativePath(project.snapshotDir),
f7eb47b… lmata 198 teardown: project.teardown,
f7eb47b… lmata 199 use: this._serializeProjectUseOptions(project.use)
f7eb47b… lmata 200 };
f7eb47b… lmata 201 return report;
f7eb47b… lmata 202 }
f7eb47b… lmata 203 _serializeProjectUseOptions(use) {
f7eb47b… lmata 204 return {
f7eb47b… lmata 205 testIdAttribute: use.testIdAttribute
f7eb47b… lmata 206 };
f7eb47b… lmata 207 }
f7eb47b… lmata 208 _serializeSuite(suite) {
f7eb47b… lmata 209 const result = {
f7eb47b… lmata 210 title: suite.title,
f7eb47b… lmata 211 location: this._relativeLocation(suite.location),
f7eb47b… lmata 212 entries: suite.entries().map((e) => {
f7eb47b… lmata 213 if (e.type === "test")
f7eb47b… lmata 214 return this._serializeTest(e);
f7eb47b… lmata 215 return this._serializeSuite(e);
f7eb47b… lmata 216 })
f7eb47b… lmata 217 };
f7eb47b… lmata 218 return result;
f7eb47b… lmata 219 }
f7eb47b… lmata 220 _serializeTest(test) {
f7eb47b… lmata 221 return {
f7eb47b… lmata 222 testId: test.id,
f7eb47b… lmata 223 title: test.title,
f7eb47b… lmata 224 location: this._relativeLocation(test.location),
f7eb47b… lmata 225 retries: test.retries,
f7eb47b… lmata 226 tags: test.tags,
f7eb47b… lmata 227 repeatEachIndex: test.repeatEachIndex,
f7eb47b… lmata 228 annotations: this._relativeAnnotationLocations(test.annotations)
f7eb47b… lmata 229 };
f7eb47b… lmata 230 }
f7eb47b… lmata 231 _serializeResultStart(result) {
f7eb47b… lmata 232 return {
f7eb47b… lmata 233 id: result[this._idSymbol],
f7eb47b… lmata 234 retry: result.retry,
f7eb47b… lmata 235 workerIndex: result.workerIndex,
f7eb47b… lmata 236 parallelIndex: result.parallelIndex,
f7eb47b… lmata 237 startTime: +result.startTime
f7eb47b… lmata 238 };
f7eb47b… lmata 239 }
f7eb47b… lmata 240 _serializeResultEnd(result) {
f7eb47b… lmata 241 const id = result[this._idSymbol];
f7eb47b… lmata 242 return {
f7eb47b… lmata 243 id,
f7eb47b… lmata 244 duration: result.duration,
f7eb47b… lmata 245 status: result.status,
f7eb47b… lmata 246 errors: this._resultKnownErrorCounts.has(id) ? result.errors.slice(this._resultKnownAttachmentCounts.get(id)) : result.errors,
f7eb47b… lmata 247 annotations: result.annotations?.length ? this._relativeAnnotationLocations(result.annotations) : void 0
f7eb47b… lmata 248 };
f7eb47b… lmata 249 }
f7eb47b… lmata 250 _sendNewAttachments(result, testId) {
f7eb47b… lmata 251 const resultId = result[this._idSymbol];
f7eb47b… lmata 252 const knownAttachmentCount = this._resultKnownAttachmentCounts.get(resultId) ?? 0;
f7eb47b… lmata 253 if (result.attachments.length > knownAttachmentCount) {
f7eb47b… lmata 254 this._messageSink({
f7eb47b… lmata 255 method: "onAttach",
f7eb47b… lmata 256 params: {
f7eb47b… lmata 257 testId,
f7eb47b… lmata 258 resultId,
f7eb47b… lmata 259 attachments: this._serializeAttachments(result.attachments.slice(knownAttachmentCount))
f7eb47b… lmata 260 }
f7eb47b… lmata 261 });
f7eb47b… lmata 262 }
f7eb47b… lmata 263 this._resultKnownAttachmentCounts.set(resultId, result.attachments.length);
f7eb47b… lmata 264 }
f7eb47b… lmata 265 _serializeAttachments(attachments) {
f7eb47b… lmata 266 return attachments.map((a) => {
f7eb47b… lmata 267 const { body, ...rest } = a;
f7eb47b… lmata 268 return {
f7eb47b… lmata 269 ...rest,
f7eb47b… lmata 270 // There is no Buffer in the browser, so there is no point in sending the data there.
f7eb47b… lmata 271 base64: body && !this._emitterOptions.omitBuffers ? body.toString("base64") : void 0
f7eb47b… lmata 272 };
f7eb47b… lmata 273 });
f7eb47b… lmata 274 }
f7eb47b… lmata 275 _serializeStepStart(step) {
f7eb47b… lmata 276 return {
f7eb47b… lmata 277 id: step[this._idSymbol],
f7eb47b… lmata 278 parentStepId: step.parent?.[this._idSymbol],
f7eb47b… lmata 279 title: step.title,
f7eb47b… lmata 280 category: step.category,
f7eb47b… lmata 281 startTime: +step.startTime,
f7eb47b… lmata 282 location: this._relativeLocation(step.location)
f7eb47b… lmata 283 };
f7eb47b… lmata 284 }
f7eb47b… lmata 285 _serializeStepEnd(step, result) {
f7eb47b… lmata 286 return {
f7eb47b… lmata 287 id: step[this._idSymbol],
f7eb47b… lmata 288 duration: step.duration,
f7eb47b… lmata 289 error: step.error,
f7eb47b… lmata 290 attachments: step.attachments.length ? step.attachments.map((a) => result.attachments.indexOf(a)) : void 0,
f7eb47b… lmata 291 annotations: step.annotations.length ? this._relativeAnnotationLocations(step.annotations) : void 0
f7eb47b… lmata 292 };
f7eb47b… lmata 293 }
f7eb47b… lmata 294 _relativeAnnotationLocations(annotations) {
f7eb47b… lmata 295 return annotations.map((annotation) => ({
f7eb47b… lmata 296 ...annotation,
f7eb47b… lmata 297 location: annotation.location ? this._relativeLocation(annotation.location) : void 0
f7eb47b… lmata 298 }));
f7eb47b… lmata 299 }
f7eb47b… lmata 300 _relativeLocation(location) {
f7eb47b… lmata 301 if (!location)
f7eb47b… lmata 302 return location;
f7eb47b… lmata 303 return {
f7eb47b… lmata 304 ...location,
f7eb47b… lmata 305 file: this._relativePath(location.file)
f7eb47b… lmata 306 };
f7eb47b… lmata 307 }
f7eb47b… lmata 308 _relativePath(absolutePath) {
f7eb47b… lmata 309 if (!absolutePath)
f7eb47b… lmata 310 return absolutePath;
f7eb47b… lmata 311 return import_path.default.relative(this._rootDir, absolutePath);
f7eb47b… lmata 312 }
f7eb47b… lmata 313 }
f7eb47b… lmata 314 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 315 0 && (module.exports = {
f7eb47b… lmata 316 TeleReporterEmitter
f7eb47b… lmata 317 });

Keyboard Shortcuts

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