allure-playwright 3.7.1 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
3
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
4
2
  function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
5
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
4
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
5
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
6
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
7
7
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
8
8
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
9
9
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
@@ -54,8 +54,8 @@ export var AllureReporter = /*#__PURE__*/function () {
54
54
  _defineProperty(this, "attachmentTargets", new Map());
55
55
  _defineProperty(this, "beforeHooksStepsStack", new Map());
56
56
  _defineProperty(this, "afterHooksStepsStack", new Map());
57
- _defineProperty(this, "beforeHooksAttachmentsStack", new Map());
58
- _defineProperty(this, "afterHooksAttachmentsStack", new Map());
57
+ _defineProperty(this, "pendingAttachmentTasks", new Map());
58
+ _defineProperty(this, "attachmentTargetByStep", new WeakMap());
59
59
  _defineProperty(this, "pwStepUuid", new WeakMap());
60
60
  _defineProperty(this, "testPlan", parseTestPlan());
61
61
  this.options = _objectSpread({
@@ -252,6 +252,259 @@ export var AllureReporter = /*#__PURE__*/function () {
252
252
  this.allureResultsUuids.set(test.id, testUuid);
253
253
  this.startedTestCasesTitlesCache.push(metadata.titleMetadata.cleanTitle);
254
254
  }
255
+ }, {
256
+ key: "queueAttachmentTask",
257
+ value: function queueAttachmentTask(testId, task) {
258
+ var _this$pendingAttachme;
259
+ var tasks = (_this$pendingAttachme = this.pendingAttachmentTasks.get(testId)) !== null && _this$pendingAttachme !== void 0 ? _this$pendingAttachme : [];
260
+ tasks.push(task);
261
+ this.pendingAttachmentTasks.set(testId, tasks);
262
+ }
263
+ }, {
264
+ key: "flushAttachmentTasks",
265
+ value: function () {
266
+ var _flushAttachmentTasks = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(testId) {
267
+ var _this$pendingAttachme2;
268
+ var tasks;
269
+ return _regenerator().w(function (_context) {
270
+ while (1) switch (_context.n) {
271
+ case 0:
272
+ tasks = (_this$pendingAttachme2 = this.pendingAttachmentTasks.get(testId)) !== null && _this$pendingAttachme2 !== void 0 ? _this$pendingAttachme2 : [];
273
+ this.pendingAttachmentTasks["delete"](testId);
274
+ if (!(tasks.length > 0)) {
275
+ _context.n = 1;
276
+ break;
277
+ }
278
+ _context.n = 1;
279
+ return Promise.all(tasks);
280
+ case 1:
281
+ return _context.a(2);
282
+ }
283
+ }, _callee, this);
284
+ }));
285
+ function flushAttachmentTasks(_x) {
286
+ return _flushAttachmentTasks.apply(this, arguments);
287
+ }
288
+ return flushAttachmentTasks;
289
+ }()
290
+ }, {
291
+ key: "recordAttachmentTarget",
292
+ value: function recordAttachmentTarget(testId, target) {
293
+ var _this$attachmentTarge;
294
+ var targets = (_this$attachmentTarge = this.attachmentTargets.get(testId)) !== null && _this$attachmentTarge !== void 0 ? _this$attachmentTarge : [];
295
+ targets.push(target);
296
+ this.attachmentTargets.set(testId, targets);
297
+ }
298
+ }, {
299
+ key: "getHookStepsStack",
300
+ value: function getHookStepsStack(testId, hookStep) {
301
+ return hookStep.hookScope === "before" ? this.beforeHooksStepsStack.get(testId) : this.afterHooksStepsStack.get(testId);
302
+ }
303
+ }, {
304
+ key: "removeHookAttachmentPlaceholder",
305
+ value: function removeHookAttachmentPlaceholder(steps, stepUuid) {
306
+ var index = steps.findIndex(function (step) {
307
+ return step.uuid === stepUuid;
308
+ });
309
+ if (index !== -1) {
310
+ steps.splice(index, 1);
311
+ return true;
312
+ }
313
+ var _iterator2 = _createForOfIteratorHelper(steps),
314
+ _step2;
315
+ try {
316
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
317
+ var step = _step2.value;
318
+ if (this.removeHookAttachmentPlaceholder(step.steps, stepUuid)) {
319
+ return true;
320
+ }
321
+ }
322
+ } catch (err) {
323
+ _iterator2.e(err);
324
+ } finally {
325
+ _iterator2.f();
326
+ }
327
+ return false;
328
+ }
329
+ }, {
330
+ key: "addAttachmentToHookStep",
331
+ value: function addAttachmentToHookStep(test, hookStep, attachment) {
332
+ var targetStack = this.getHookStepsStack(test.id, hookStep);
333
+ if (!targetStack) {
334
+ return;
335
+ }
336
+ var stepResult = targetStack.findStepByUuid(hookStep.uuid);
337
+ if (!stepResult) {
338
+ return;
339
+ }
340
+ var fileName = targetStack.addAttachment(attachment, this.allureRuntime.writer);
341
+ stepResult.attachments.push({
342
+ name: attachment.name,
343
+ type: attachment.contentType,
344
+ source: fileName
345
+ });
346
+ }
347
+ }, {
348
+ key: "addRuntimeAttachmentToHookStack",
349
+ value: function addRuntimeAttachmentToHookStack(targetStack, attachment, options) {
350
+ var _this2 = this;
351
+ var currentStep = targetStack.currentStep();
352
+ if (!currentStep) {
353
+ return;
354
+ }
355
+ var addAttachment = function addAttachment(stepResult) {
356
+ var fileName = targetStack.addAttachment(attachment, _this2.allureRuntime.writer);
357
+ stepResult.attachments.push({
358
+ name: attachment.name,
359
+ type: attachment.contentType,
360
+ source: fileName
361
+ });
362
+ };
363
+ if (options !== null && options !== void 0 && options.wrapInStep) {
364
+ targetStack.startStep({
365
+ name: attachment.name,
366
+ start: options.timestamp
367
+ });
368
+ addAttachment(targetStack.currentStep());
369
+ targetStack.stopStep({
370
+ stop: options.timestamp
371
+ });
372
+ return;
373
+ }
374
+ addAttachment(currentStep);
375
+ }
376
+ }, {
377
+ key: "processHookRuntimeMessage",
378
+ value: function processHookRuntimeMessage(test, testUuid, hookStep, attachment) {
379
+ if (!attachment.body) {
380
+ return false;
381
+ }
382
+ var targetStack = this.getHookStepsStack(test.id, hookStep);
383
+ if (!targetStack) {
384
+ return false;
385
+ }
386
+ this.removeHookAttachmentPlaceholder(targetStack.steps, hookStep.uuid);
387
+ var message = JSON.parse(attachment.body.toString());
388
+ switch (message.type) {
389
+ case "step_start":
390
+ targetStack.startStep(_objectSpread({}, message.data));
391
+ return true;
392
+ case "step_stop":
393
+ {
394
+ var currentStep = targetStack.currentStep();
395
+ if (!currentStep) {
396
+ return false;
397
+ }
398
+ targetStack.updateStep(function (stepResult) {
399
+ if (message.data.status && !stepResult.status) {
400
+ stepResult.status = message.data.status;
401
+ }
402
+ if (message.data.statusDetails) {
403
+ stepResult.statusDetails = _objectSpread(_objectSpread({}, stepResult.statusDetails), message.data.statusDetails);
404
+ }
405
+ });
406
+ targetStack.stopStep({
407
+ stop: message.data.stop
408
+ });
409
+ return true;
410
+ }
411
+ case "step_metadata":
412
+ {
413
+ var _currentStep$paramete, _message$data$paramet;
414
+ var _currentStep = targetStack.currentStep();
415
+ if (!_currentStep) {
416
+ return false;
417
+ }
418
+ if (message.data.name) {
419
+ _currentStep.name = message.data.name;
420
+ }
421
+ (_currentStep$paramete = _currentStep.parameters).push.apply(_currentStep$paramete, _toConsumableArray((_message$data$paramet = message.data.parameters) !== null && _message$data$paramet !== void 0 ? _message$data$paramet : []));
422
+ return true;
423
+ }
424
+ case "attachment_content":
425
+ this.addRuntimeAttachmentToHookStack(targetStack, {
426
+ name: message.data.name,
427
+ body: Buffer.from(message.data.content, message.data.encoding),
428
+ contentType: message.data.contentType
429
+ }, {
430
+ wrapInStep: message.data.wrapInStep,
431
+ timestamp: message.data.timestamp
432
+ });
433
+ return true;
434
+ case "attachment_path":
435
+ this.addRuntimeAttachmentToHookStack(targetStack, {
436
+ name: message.data.name,
437
+ path: message.data.path,
438
+ contentType: message.data.contentType
439
+ }, {
440
+ wrapInStep: message.data.wrapInStep,
441
+ timestamp: message.data.timestamp
442
+ });
443
+ return true;
444
+ default:
445
+ this.queueAttachmentTask(test.id, this.processAttachment(testUuid, undefined, attachment));
446
+ return true;
447
+ }
448
+ }
449
+ }, {
450
+ key: "shouldProcessAttachmentAtTestEnd",
451
+ value: function shouldProcessAttachmentAtTestEnd(attachment) {
452
+ if (attachment.name.match(diffEndRegexp)) {
453
+ return true;
454
+ }
455
+ if (attachment.contentType === "application/vnd.allure.playwright-trace") {
456
+ return true;
457
+ }
458
+ return attachment.name === "trace" && attachment.contentType === "application/zip";
459
+ }
460
+ }, {
461
+ key: "processStepEndAttachments",
462
+ value: function processStepEndAttachments(test, step) {
463
+ var _step$attachments;
464
+ var testUuid = this.allureResultsUuids.get(test.id);
465
+ var stepAttachments = (_step$attachments = step.attachments) !== null && _step$attachments !== void 0 ? _step$attachments : [];
466
+ var stepInfo = this.attachmentTargetByStep.get(step);
467
+ var hasExplicitParent = Boolean((stepInfo === null || stepInfo === void 0 ? void 0 : stepInfo.hookStep) || (stepInfo === null || stepInfo === void 0 ? void 0 : stepInfo.stepUuid));
468
+ if (stepAttachments.length === 0) {
469
+ if (stepInfo) {
470
+ this.recordAttachmentTarget(test.id, stepInfo);
471
+ }
472
+ return;
473
+ }
474
+ var _iterator3 = _createForOfIteratorHelper(stepAttachments),
475
+ _step3;
476
+ try {
477
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
478
+ var _stepInfo$hookStep$uu, _stepInfo$hookStep;
479
+ var attachment = _step3.value;
480
+ var isRuntimeMessage = attachment.contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
481
+ var attachmentTarget = _objectSpread(_objectSpread({}, stepInfo), {}, {
482
+ name: attachment.name
483
+ });
484
+ this.recordAttachmentTarget(test.id, attachmentTarget);
485
+ if (this.shouldProcessAttachmentAtTestEnd(attachment) || !isRuntimeMessage && !hasExplicitParent) {
486
+ continue;
487
+ }
488
+ attachmentTarget.processedAtStepEnd = true;
489
+ if (stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep && isRuntimeMessage) {
490
+ if (!this.processHookRuntimeMessage(test, testUuid, stepInfo.hookStep, attachment)) {
491
+ attachmentTarget.processedAtStepEnd = false;
492
+ }
493
+ continue;
494
+ }
495
+ if (stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep) {
496
+ this.addAttachmentToHookStep(test, stepInfo.hookStep, attachment);
497
+ continue;
498
+ }
499
+ var attachmentStepUuid = (_stepInfo$hookStep$uu = stepInfo === null || stepInfo === void 0 || (_stepInfo$hookStep = stepInfo.hookStep) === null || _stepInfo$hookStep === void 0 ? void 0 : _stepInfo$hookStep.uuid) !== null && _stepInfo$hookStep$uu !== void 0 ? _stepInfo$hookStep$uu : stepInfo === null || stepInfo === void 0 ? void 0 : stepInfo.stepUuid;
500
+ this.queueAttachmentTask(test.id, this.processAttachment(testUuid, attachmentStepUuid, attachment));
501
+ }
502
+ } catch (err) {
503
+ _iterator3.e(err);
504
+ } finally {
505
+ _iterator3.f();
506
+ }
507
+ }
255
508
  }, {
256
509
  key: "onStepBegin",
257
510
  value: function onStepBegin(test, _result, step) {
@@ -273,67 +526,49 @@ export var AllureReporter = /*#__PURE__*/function () {
273
526
  uuid: randomUuid()
274
527
  });
275
528
  if (["test.attach", "attach"].includes(step.category) && !isHookStep) {
276
- var _this$pwStepUuid$get, _this$attachmentTarge;
529
+ var _this$pwStepUuid$get;
277
530
  var parent = step.parent ? (_this$pwStepUuid$get = this.pwStepUuid.get(step.parent)) !== null && _this$pwStepUuid$get !== void 0 ? _this$pwStepUuid$get : null : null;
278
- var targets = (_this$attachmentTarge = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge !== void 0 ? _this$attachmentTarge : [];
279
- targets.push({
531
+ this.attachmentTargetByStep.set(step, {
280
532
  name: normalizeAttachStepTitle(step.title),
281
533
  stepUuid: parent !== null && parent !== void 0 ? parent : undefined
282
534
  });
283
- this.attachmentTargets.set(test.id, targets);
284
535
  return;
285
536
  }
286
537
  if (isHookStep) {
287
- // Lazily initialize the hook stack if it doesn't exist (e.g., when detail: false and root hook was ignored)
288
- var stack = isBeforeHookDescendant ? this.beforeHooksStepsStack.get(test.id) : this.afterHooksStepsStack.get(test.id);
289
- if (!stack) {
290
- stack = new ShallowStepsStack();
291
- var rootHookStep = _objectSpread(_objectSpread({}, createStepResult()), {}, {
292
- name: isBeforeHookDescendant ? BEFORE_HOOKS_ROOT_STEP_TITLE : AFTER_HOOKS_ROOT_STEP_TITLE,
293
- start: step.startTime.getTime(),
294
- stage: Stage.RUNNING,
295
- uuid: randomUuid()
296
- });
297
- stack.startStep(rootHookStep);
298
- if (isBeforeHookDescendant) {
299
- this.beforeHooksStepsStack.set(test.id, stack);
300
- } else {
301
- this.afterHooksStepsStack.set(test.id, stack);
302
- }
303
- }
304
538
  if (["test.attach", "attach"].includes(step.category)) {
305
- var _this$attachmentTarge2;
539
+ var _stack$currentStep;
540
+ var attachmentName = normalizeAttachStepTitle(step.title);
541
+ var _stack = _assertClassBrand(_AllureReporter_brand, this, _getOrCreateHookStack).call(this, test.id, isBeforeHookDescendant, step.startTime);
306
542
  var hookStepWithUuid;
307
- stack.startStep(baseStep);
308
- var attachStack = isBeforeHookDescendant ? this.beforeHooksAttachmentsStack : this.afterHooksAttachmentsStack;
309
- stack.updateStep(function (stepResult) {
310
- var _attachStack$get;
543
+ var parentHookStepUuid = (_stack$currentStep = _stack.currentStep()) === null || _stack$currentStep === void 0 ? void 0 : _stack$currentStep.uuid;
544
+ _stack.startStep(baseStep);
545
+ _stack.updateStep(function (stepResult) {
311
546
  hookStepWithUuid = _objectSpread(_objectSpread({}, step), {}, {
312
- uuid: stepResult.uuid
547
+ uuid: stepResult.uuid,
548
+ hookScope: isBeforeHookDescendant ? "before" : "after"
313
549
  });
314
550
  stepResult.name = normalizeHookTitle(stepResult.name);
315
551
  stepResult.stage = Stage.FINISHED;
316
- attachStack.set(test.id, [].concat(_toConsumableArray((_attachStack$get = attachStack.get(test.id)) !== null && _attachStack$get !== void 0 ? _attachStack$get : []), [hookStepWithUuid]));
317
552
  });
318
- stack.stopStep();
319
- var _targets = (_this$attachmentTarge2 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge2 !== void 0 ? _this$attachmentTarge2 : [];
320
- _targets.push({
321
- name: normalizeAttachStepTitle(step.title),
322
- hookStep: hookStepWithUuid
553
+ _stack.stopStep();
554
+ this.attachmentTargetByStep.set(step, {
555
+ name: attachmentName,
556
+ hookStep: hookStepWithUuid,
557
+ stepUuid: attachmentName === "Allure Step Metadata" ? parentHookStepUuid : undefined
323
558
  });
324
- this.attachmentTargets.set(test.id, _targets);
325
559
  return;
326
560
  }
561
+ var stack = _assertClassBrand(_AllureReporter_brand, this, _getOrCreateHookStack).call(this, test.id, isBeforeHookDescendant, step.startTime);
327
562
  stack.startStep(baseStep);
328
563
  return;
329
564
  }
330
565
  if (isRootHook) {
331
- var _stack = new ShallowStepsStack();
332
- _stack.startStep(baseStep);
566
+ var _stack2 = new ShallowStepsStack();
567
+ _stack2.startStep(baseStep);
333
568
  if (isRootBeforeHook) {
334
- this.beforeHooksStepsStack.set(test.id, _stack);
569
+ this.beforeHooksStepsStack.set(test.id, _stack2);
335
570
  } else {
336
- this.afterHooksStepsStack.set(test.id, _stack);
571
+ this.afterHooksStepsStack.set(test.id, _stack2);
337
572
  }
338
573
  return;
339
574
  }
@@ -368,8 +603,8 @@ export var AllureReporter = /*#__PURE__*/function () {
368
603
  if (_assertClassBrand(_AllureReporter_brand, this, _shouldIgnoreStep).call(this, step)) {
369
604
  return;
370
605
  }
371
- // ignore test.attach steps since attachments are already in the report
372
606
  if (["test.attach", "attach"].includes(step.category)) {
607
+ this.processStepEndAttachments(test, step);
373
608
  return;
374
609
  }
375
610
  var testUuid = this.allureResultsUuids.get(test.id);
@@ -378,16 +613,16 @@ export var AllureReporter = /*#__PURE__*/function () {
378
613
  var isAfterHook = isAfterHookDescendant;
379
614
  var isHook = isBeforeHookDescendant || isAfterHookDescendant;
380
615
  if (isHook) {
381
- var _stack2 = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
616
+ var _stack3 = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
382
617
 
383
618
  // Stack might not exist if root hook was ignored (e.g., detail: false) and no test.step was called inside it
384
- if (!_stack2) {
619
+ if (!_stack3) {
385
620
  return;
386
621
  }
387
- _stack2.updateStep(function (stepResult) {
622
+ _stack3.updateStep(function (stepResult) {
388
623
  return finalizeStepResult(stepResult, step);
389
624
  });
390
- _stack2.stopStep({
625
+ _stack3.stopStep({
391
626
  duration: step.duration
392
627
  });
393
628
  return;
@@ -410,13 +645,12 @@ export var AllureReporter = /*#__PURE__*/function () {
410
645
  }, {
411
646
  key: "onTestEnd",
412
647
  value: function () {
413
- var _onTestEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(test, result) {
414
- var _this2 = this,
415
- _this$beforeHooksAtta,
416
- _this$attachmentTarge3;
417
- var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, beforeHooksStack, afterHooksStack, attachmentsInBeforeHooks, targets, targetsByName, _iterator2, _step2, _targetsByName$get, t, q, takeByName, _iterator3, _step3, attachment, isRuntimeMessage, stepInfo, _stepInfo$hookStep$uu, _stepInfo$hookStep, stepUuid, hookStep, isBeforeHook, targetStack, stepResult, fileName, _t;
418
- return _regenerator().w(function (_context) {
419
- while (1) switch (_context.n) {
648
+ var _onTestEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(test, result) {
649
+ var _this3 = this,
650
+ _this$attachmentTarge2;
651
+ var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, beforeHooksStack, afterHooksStack, targets, targetsByName, _iterator4, _step4, _targetsByName$get, t, q, takeByName, _iterator5, _step5, attachment, isRuntimeMessage, stepInfo, _stepInfo$hookStep$uu2, _stepInfo$hookStep2, message, targetStack, _targetStack, stepUuid, _targetStack2, stepResult, fileName, _t;
652
+ return _regenerator().w(function (_context2) {
653
+ while (1) switch (_context2.n) {
420
654
  case 0:
421
655
  testUuid = this.allureResultsUuids.get(test.id); // We need to check parallelIndex first because pw introduced this field only in v1.30.0
422
656
  threadId = result.parallelIndex !== undefined ? result.parallelIndex : result.workerIndex;
@@ -434,7 +668,7 @@ export var AllureReporter = /*#__PURE__*/function () {
434
668
  value: projectSuiteTitle
435
669
  });
436
670
  }
437
- if (_this2.options.suiteTitle && fileSuiteTitle && !hasLabel(testResult, LabelName.SUITE)) {
671
+ if (_this3.options.suiteTitle && fileSuiteTitle && !hasLabel(testResult, LabelName.SUITE)) {
438
672
  testResult.labels.push({
439
673
  name: LabelName.SUITE,
440
674
  value: fileSuiteTitle
@@ -472,21 +706,22 @@ export var AllureReporter = /*#__PURE__*/function () {
472
706
  contentType: ContentType.TEXT
473
707
  });
474
708
  }
475
- attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : []; // FIFO
476
- targets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
709
+
710
+ // FIFO
711
+ targets = (_this$attachmentTarge2 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge2 !== void 0 ? _this$attachmentTarge2 : [];
477
712
  targetsByName = new Map();
478
- _iterator2 = _createForOfIteratorHelper(targets);
713
+ _iterator4 = _createForOfIteratorHelper(targets);
479
714
  try {
480
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
481
- t = _step2.value;
715
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
716
+ t = _step4.value;
482
717
  q = (_targetsByName$get = targetsByName.get(t.name)) !== null && _targetsByName$get !== void 0 ? _targetsByName$get : [];
483
718
  q.push(t);
484
719
  targetsByName.set(t.name, q);
485
720
  }
486
721
  } catch (err) {
487
- _iterator2.e(err);
722
+ _iterator4.e(err);
488
723
  } finally {
489
- _iterator2.f();
724
+ _iterator4.f();
490
725
  }
491
726
  takeByName = function takeByName(name) {
492
727
  var target = targetsByName.get(name);
@@ -495,38 +730,59 @@ export var AllureReporter = /*#__PURE__*/function () {
495
730
  }
496
731
  return target.shift();
497
732
  };
498
- _iterator3 = _createForOfIteratorHelper(result.attachments);
499
- _context.p = 1;
500
- _iterator3.s();
733
+ _iterator5 = _createForOfIteratorHelper(result.attachments);
734
+ _context2.p = 1;
735
+ _iterator5.s();
501
736
  case 2:
502
- if ((_step3 = _iterator3.n()).done) {
503
- _context.n = 9;
737
+ if ((_step5 = _iterator5.n()).done) {
738
+ _context2.n = 11;
504
739
  break;
505
740
  }
506
- attachment = _step3.value;
741
+ attachment = _step5.value;
507
742
  isRuntimeMessage = attachment.contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
508
743
  stepInfo = takeByName(attachment.name);
509
- if (!isRuntimeMessage) {
510
- _context.n = 4;
744
+ if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.processedAtStepEnd)) {
745
+ _context2.n = 3;
511
746
  break;
512
747
  }
513
- stepUuid = (_stepInfo$hookStep$uu = stepInfo === null || stepInfo === void 0 || (_stepInfo$hookStep = stepInfo.hookStep) === null || _stepInfo$hookStep === void 0 ? void 0 : _stepInfo$hookStep.uuid) !== null && _stepInfo$hookStep$uu !== void 0 ? _stepInfo$hookStep$uu : stepInfo === null || stepInfo === void 0 ? void 0 : stepInfo.stepUuid;
514
- _context.n = 3;
515
- return this.processAttachment(testUuid, stepUuid, attachment);
748
+ return _context2.a(3, 10);
516
749
  case 3:
517
- return _context.a(3, 8);
750
+ if (!isRuntimeMessage) {
751
+ _context2.n = 6;
752
+ break;
753
+ }
754
+ message = attachment.body ? JSON.parse(attachment.body.toString()) : undefined;
755
+ if (stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep) {
756
+ targetStack = this.getHookStepsStack(test.id, stepInfo.hookStep);
757
+ this.removeStepFromHookStack(targetStack, stepInfo.hookStep.uuid);
758
+ }
759
+ if (!((message === null || message === void 0 ? void 0 : message.type) === "step_metadata" && stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
760
+ _context2.n = 4;
761
+ break;
762
+ }
763
+ if (stepInfo.hookStep) {
764
+ _targetStack = this.getHookStepsStack(test.id, stepInfo.hookStep);
765
+ this.processHookStepMetadataMessage(_targetStack, stepInfo.stepUuid, message);
766
+ } else {
767
+ this.processStepMetadataMessage(stepInfo.stepUuid, message);
768
+ }
769
+ return _context2.a(3, 10);
518
770
  case 4:
771
+ stepUuid = (_stepInfo$hookStep$uu2 = stepInfo === null || stepInfo === void 0 || (_stepInfo$hookStep2 = stepInfo.hookStep) === null || _stepInfo$hookStep2 === void 0 ? void 0 : _stepInfo$hookStep2.uuid) !== null && _stepInfo$hookStep$uu2 !== void 0 ? _stepInfo$hookStep$uu2 : stepInfo === null || stepInfo === void 0 ? void 0 : stepInfo.stepUuid;
772
+ _context2.n = 5;
773
+ return this.processAttachment(testUuid, stepUuid, attachment);
774
+ case 5:
775
+ return _context2.a(3, 10);
776
+ case 6:
519
777
  if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep)) {
520
- _context.n = 5;
778
+ _context2.n = 7;
521
779
  break;
522
780
  }
523
- hookStep = stepInfo.hookStep;
524
- isBeforeHook = attachmentsInBeforeHooks.includes(hookStep);
525
- targetStack = isBeforeHook ? beforeHooksStack : afterHooksStack;
526
- if (targetStack) {
527
- stepResult = targetStack.findStepByUuid(hookStep.uuid);
781
+ _targetStack2 = this.getHookStepsStack(test.id, stepInfo.hookStep);
782
+ if (_targetStack2) {
783
+ stepResult = _targetStack2.findStepByUuid(stepInfo.hookStep.uuid);
528
784
  if (stepResult) {
529
- fileName = targetStack.addAttachment(attachment, this.allureRuntime.writer);
785
+ fileName = _targetStack2.addAttachment(attachment, this.allureRuntime.writer);
530
786
  stepResult.attachments.push({
531
787
  name: attachment.name,
532
788
  type: attachment.contentType,
@@ -534,34 +790,37 @@ export var AllureReporter = /*#__PURE__*/function () {
534
790
  });
535
791
  }
536
792
  }
537
- return _context.a(3, 8);
538
- case 5:
793
+ return _context2.a(3, 10);
794
+ case 7:
539
795
  if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
540
- _context.n = 7;
796
+ _context2.n = 9;
541
797
  break;
542
798
  }
543
- _context.n = 6;
799
+ _context2.n = 8;
544
800
  return this.processAttachment(testUuid, stepInfo.stepUuid, attachment);
545
- case 6:
546
- return _context.a(3, 8);
547
- case 7:
548
- _context.n = 8;
549
- return this.processAttachment(testUuid, undefined, attachment);
550
801
  case 8:
551
- _context.n = 2;
552
- break;
802
+ return _context2.a(3, 10);
553
803
  case 9:
554
- _context.n = 11;
555
- break;
804
+ _context2.n = 10;
805
+ return this.processAttachment(testUuid, undefined, attachment);
556
806
  case 10:
557
- _context.p = 10;
558
- _t = _context.v;
559
- _iterator3.e(_t);
807
+ _context2.n = 2;
808
+ break;
560
809
  case 11:
561
- _context.p = 11;
562
- _iterator3.f();
563
- return _context.f(11);
810
+ _context2.n = 13;
811
+ break;
564
812
  case 12:
813
+ _context2.p = 12;
814
+ _t = _context2.v;
815
+ _iterator5.e(_t);
816
+ case 13:
817
+ _context2.p = 13;
818
+ _iterator5.f();
819
+ return _context2.f(13);
820
+ case 14:
821
+ _context2.n = 15;
822
+ return this.flushAttachmentTasks(test.id);
823
+ case 15:
565
824
  // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
566
825
  // in next iterations we need to implement the logic for every javascript integration
567
826
  this.allureRuntime.updateTest(testUuid, function (testResult) {
@@ -581,14 +840,14 @@ export var AllureReporter = /*#__PURE__*/function () {
581
840
  });
582
841
  if (beforeHooksStack) {
583
842
  var _testResult$steps;
584
- (_testResult$steps = testResult.steps).unshift.apply(_testResult$steps, _toConsumableArray(beforeHooksStack.steps));
585
- _this2.beforeHooksStepsStack["delete"](test.id);
843
+ (_testResult$steps = testResult.steps).unshift.apply(_testResult$steps, _toConsumableArray(_this3.pruneEmptyHookRoots(beforeHooksStack.steps)));
586
844
  }
845
+ _this3.beforeHooksStepsStack["delete"](test.id);
587
846
  if (afterHooksStack) {
588
847
  var _testResult$steps2;
589
- (_testResult$steps2 = testResult.steps).push.apply(_testResult$steps2, _toConsumableArray(afterHooksStack.steps));
590
- _this2.afterHooksStepsStack["delete"](test.id);
848
+ (_testResult$steps2 = testResult.steps).push.apply(_testResult$steps2, _toConsumableArray(_this3.pruneEmptyHookRoots(afterHooksStack.steps)));
591
849
  }
850
+ _this3.afterHooksStepsStack["delete"](test.id);
592
851
  testResult.labels = newLabels;
593
852
  });
594
853
  this.allureRuntime.stopTest(testUuid, {
@@ -596,12 +855,13 @@ export var AllureReporter = /*#__PURE__*/function () {
596
855
  });
597
856
  this.allureRuntime.writeTest(testUuid);
598
857
  this.attachmentTargets["delete"](test.id);
599
- case 13:
600
- return _context.a(2);
858
+ this.pendingAttachmentTasks["delete"](test.id);
859
+ case 16:
860
+ return _context2.a(2);
601
861
  }
602
- }, _callee, this, [[1, 10, 11, 12]]);
862
+ }, _callee2, this, [[1, 12, 13, 14]]);
603
863
  }));
604
- function onTestEnd(_x, _x2) {
864
+ function onTestEnd(_x2, _x3) {
605
865
  return _onTestEnd.apply(this, arguments);
606
866
  }
607
867
  return onTestEnd;
@@ -609,28 +869,28 @@ export var AllureReporter = /*#__PURE__*/function () {
609
869
  }, {
610
870
  key: "addSkippedResults",
611
871
  value: function () {
612
- var _addSkippedResults = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
613
- var _this3 = this;
614
- var unprocessedCases, _iterator4, _step4, testCase, _t2;
615
- return _regenerator().w(function (_context2) {
616
- while (1) switch (_context2.n) {
872
+ var _addSkippedResults = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
873
+ var _this4 = this;
874
+ var unprocessedCases, _iterator6, _step6, testCase, _t2;
875
+ return _regenerator().w(function (_context3) {
876
+ while (1) switch (_context3.n) {
617
877
  case 0:
618
878
  unprocessedCases = this.suite.allTests().filter(function (_ref2) {
619
879
  var title = _ref2.title;
620
880
  var titleMetadata = extractMetadataFromString(title);
621
- return !_this3.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
881
+ return !_this4.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
622
882
  });
623
- _iterator4 = _createForOfIteratorHelper(unprocessedCases);
624
- _context2.p = 1;
625
- _iterator4.s();
883
+ _iterator6 = _createForOfIteratorHelper(unprocessedCases);
884
+ _context3.p = 1;
885
+ _iterator6.s();
626
886
  case 2:
627
- if ((_step4 = _iterator4.n()).done) {
628
- _context2.n = 4;
887
+ if ((_step6 = _iterator6.n()).done) {
888
+ _context3.n = 4;
629
889
  break;
630
890
  }
631
- testCase = _step4.value;
891
+ testCase = _step6.value;
632
892
  this.onTestBegin(testCase);
633
- _context2.n = 3;
893
+ _context3.n = 3;
634
894
  return this.onTestEnd(testCase, {
635
895
  status: Status.SKIPPED,
636
896
  attachments: [],
@@ -646,23 +906,23 @@ export var AllureReporter = /*#__PURE__*/function () {
646
906
  annotations: []
647
907
  });
648
908
  case 3:
649
- _context2.n = 2;
909
+ _context3.n = 2;
650
910
  break;
651
911
  case 4:
652
- _context2.n = 6;
912
+ _context3.n = 6;
653
913
  break;
654
914
  case 5:
655
- _context2.p = 5;
656
- _t2 = _context2.v;
657
- _iterator4.e(_t2);
915
+ _context3.p = 5;
916
+ _t2 = _context3.v;
917
+ _iterator6.e(_t2);
658
918
  case 6:
659
- _context2.p = 6;
660
- _iterator4.f();
661
- return _context2.f(6);
919
+ _context3.p = 6;
920
+ _iterator6.f();
921
+ return _context3.f(6);
662
922
  case 7:
663
- return _context2.a(2);
923
+ return _context3.a(2);
664
924
  }
665
- }, _callee2, this, [[1, 5, 6, 7]]);
925
+ }, _callee3, this, [[1, 5, 6, 7]]);
666
926
  }));
667
927
  function addSkippedResults() {
668
928
  return _addSkippedResults.apply(this, arguments);
@@ -672,19 +932,19 @@ export var AllureReporter = /*#__PURE__*/function () {
672
932
  }, {
673
933
  key: "onEnd",
674
934
  value: function () {
675
- var _onEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
676
- return _regenerator().w(function (_context3) {
677
- while (1) switch (_context3.n) {
935
+ var _onEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
936
+ return _regenerator().w(function (_context4) {
937
+ while (1) switch (_context4.n) {
678
938
  case 0:
679
- _context3.n = 1;
939
+ _context4.n = 1;
680
940
  return this.addSkippedResults();
681
941
  case 1:
682
942
  this.allureRuntime.writeEnvironmentInfo();
683
943
  this.allureRuntime.writeCategoriesDefinitions();
684
944
  case 2:
685
- return _context3.a(2);
945
+ return _context4.a(2);
686
946
  }
687
- }, _callee3, this);
947
+ }, _callee4, this);
688
948
  }));
689
949
  function onEnd() {
690
950
  return _onEnd.apply(this, arguments);
@@ -696,6 +956,46 @@ export var AllureReporter = /*#__PURE__*/function () {
696
956
  value: function printsToStdio() {
697
957
  return false;
698
958
  }
959
+ }, {
960
+ key: "isEmptyPassedHookRoot",
961
+ value: function isEmptyPassedHookRoot(step) {
962
+ if (this.options.detail) {
963
+ return false;
964
+ }
965
+ return (step.name === BEFORE_HOOKS_ROOT_STEP_TITLE || step.name === AFTER_HOOKS_ROOT_STEP_TITLE) && step.steps.length === 0 && step.attachments.length === 0 && step.status === Status.PASSED;
966
+ }
967
+ }, {
968
+ key: "pruneEmptyHookRoots",
969
+ value: function pruneEmptyHookRoots(steps) {
970
+ var _this5 = this;
971
+ return steps.map(function (step) {
972
+ return _objectSpread(_objectSpread({}, step), {}, {
973
+ steps: _this5.pruneEmptyHookRoots(step.steps)
974
+ });
975
+ }).filter(function (step) {
976
+ return !_this5.isEmptyPassedHookRoot(step);
977
+ });
978
+ }
979
+ }, {
980
+ key: "removeStepFromHookStack",
981
+ value: function removeStepFromHookStack(stack, stepUuid) {
982
+ var _this6 = this;
983
+ if (!stack) {
984
+ return;
985
+ }
986
+ var _removeRecursively = function removeRecursively(steps) {
987
+ return steps.filter(function (step) {
988
+ return step.uuid !== stepUuid;
989
+ }).map(function (step) {
990
+ return _objectSpread(_objectSpread({}, step), {}, {
991
+ steps: _removeRecursively(step.steps)
992
+ });
993
+ }).filter(function (step) {
994
+ return !_this6.isEmptyPassedHookRoot(step);
995
+ });
996
+ };
997
+ stack.steps = _removeRecursively(stack.steps);
998
+ }
699
999
  }, {
700
1000
  key: "getStaticTestMetadata",
701
1001
  value: function getStaticTestMetadata(test) {
@@ -725,11 +1025,11 @@ export var AllureReporter = /*#__PURE__*/function () {
725
1025
 
726
1026
  // Test-plan matching happens during discovery, so runtime API labels are intentionally excluded here.
727
1027
  if (!staticAllureId && "annotations" in test) {
728
- var _iterator5 = _createForOfIteratorHelper(test.annotations),
729
- _step5;
1028
+ var _iterator7 = _createForOfIteratorHelper(test.annotations),
1029
+ _step7;
730
1030
  try {
731
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
732
- var annotation = _step5.value;
1031
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1032
+ var annotation = _step7.value;
733
1033
  var label = getMetadataLabel(annotation.type, annotation.description);
734
1034
  if ((label === null || label === void 0 ? void 0 : label.name) === LabelName.ALLURE_ID) {
735
1035
  staticAllureId = label.value;
@@ -737,9 +1037,9 @@ export var AllureReporter = /*#__PURE__*/function () {
737
1037
  }
738
1038
  }
739
1039
  } catch (err) {
740
- _iterator5.e(err);
1040
+ _iterator7.e(err);
741
1041
  } finally {
742
- _iterator5.f();
1042
+ _iterator7.f();
743
1043
  }
744
1044
  }
745
1045
  return {
@@ -777,8 +1077,8 @@ export var AllureReporter = /*#__PURE__*/function () {
777
1077
  value: function processStepMetadataMessage(attachmentStepUuid, message) {
778
1078
  var _message$data = message.data,
779
1079
  name = _message$data.name,
780
- _message$data$paramet = _message$data.parameters,
781
- parameters = _message$data$paramet === void 0 ? [] : _message$data$paramet;
1080
+ _message$data$paramet2 = _message$data.parameters,
1081
+ parameters = _message$data$paramet2 === void 0 ? [] : _message$data$paramet2;
782
1082
  this.allureRuntime.updateStep(attachmentStepUuid, function (step) {
783
1083
  var _step$parameters;
784
1084
  if (name) {
@@ -787,43 +1087,53 @@ export var AllureReporter = /*#__PURE__*/function () {
787
1087
  (_step$parameters = step.parameters).push.apply(_step$parameters, _toConsumableArray(parameters));
788
1088
  });
789
1089
  }
1090
+ }, {
1091
+ key: "processHookStepMetadataMessage",
1092
+ value: function processHookStepMetadataMessage(stack, attachmentStepUuid, message) {
1093
+ var _step$parameters2;
1094
+ var step = stack === null || stack === void 0 ? void 0 : stack.findStepByUuid(attachmentStepUuid);
1095
+ if (!step) {
1096
+ return;
1097
+ }
1098
+ var _message$data2 = message.data,
1099
+ name = _message$data2.name,
1100
+ _message$data2$parame = _message$data2.parameters,
1101
+ parameters = _message$data2$parame === void 0 ? [] : _message$data2$parame;
1102
+ if (name) {
1103
+ step.name = name;
1104
+ }
1105
+ (_step$parameters2 = step.parameters).push.apply(_step$parameters2, _toConsumableArray(parameters));
1106
+ }
790
1107
  }, {
791
1108
  key: "processAttachment",
792
1109
  value: function () {
793
- var _processAttachment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(testUuid, attachmentStepUuid, attachment) {
1110
+ var _processAttachment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(testUuid, attachmentStepUuid, attachment) {
794
1111
  var _replace;
795
1112
  var allureRuntimeMessage, message, parentUuid, contentType, pathWithoutEndFromSnapshotDir, pathWithoutEnd, fileExists, readImageFromDirs, actualBase64, expectedBase64, diffBase64, diffName;
796
- return _regenerator().w(function (_context6) {
797
- while (1) switch (_context6.n) {
1113
+ return _regenerator().w(function (_context7) {
1114
+ while (1) switch (_context7.n) {
798
1115
  case 0:
799
1116
  if (!(!attachment.body && !attachment.path)) {
800
- _context6.n = 1;
1117
+ _context7.n = 1;
801
1118
  break;
802
1119
  }
803
- return _context6.a(2);
1120
+ return _context7.a(2);
804
1121
  case 1:
805
1122
  allureRuntimeMessage = attachment.contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
806
1123
  if (!(allureRuntimeMessage && !attachment.body)) {
807
- _context6.n = 2;
1124
+ _context7.n = 2;
808
1125
  break;
809
1126
  }
810
- return _context6.a(2);
1127
+ return _context7.a(2);
811
1128
  case 2:
812
1129
  if (!allureRuntimeMessage) {
813
- _context6.n = 4;
1130
+ _context7.n = 3;
814
1131
  break;
815
1132
  }
816
1133
  message = JSON.parse(attachment.body.toString());
817
- if (!(message.type === "step_metadata")) {
818
- _context6.n = 3;
819
- break;
820
- }
821
- this.processStepMetadataMessage(attachmentStepUuid, message);
822
- return _context6.a(2);
823
- case 3:
824
1134
  this.allureRuntime.applyRuntimeMessages(testUuid, [message]);
825
- return _context6.a(2);
826
- case 4:
1135
+ return _context7.a(2);
1136
+ case 3:
827
1137
  parentUuid = this.allureRuntime.startStep(testUuid, attachmentStepUuid, {
828
1138
  name: attachment.name
829
1139
  }); // only stop if step is created. Step may not be created only if test with specified uuid doesn't exists.
@@ -833,112 +1143,112 @@ export var AllureReporter = /*#__PURE__*/function () {
833
1143
  this.allureRuntime.stopStep(parentUuid, undefined);
834
1144
  }
835
1145
  if (!attachment.body) {
836
- _context6.n = 5;
1146
+ _context7.n = 4;
837
1147
  break;
838
1148
  }
839
1149
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.body, {
840
1150
  contentType: attachment.contentType
841
1151
  });
842
- _context6.n = 7;
1152
+ _context7.n = 6;
843
1153
  break;
844
- case 5:
1154
+ case 4:
845
1155
  if (existsSync(attachment.path)) {
846
- _context6.n = 6;
1156
+ _context7.n = 5;
847
1157
  break;
848
1158
  }
849
- return _context6.a(2);
850
- case 6:
851
- contentType = attachment.name === "trace" && attachment.contentType === "application/zip" ? "application/vnd.allure.playwright-trace" : attachment.contentType;
1159
+ return _context7.a(2);
1160
+ case 5:
1161
+ contentType = attachment.name === "trace" && attachment.contentType === "application/zip" ? ContentType.PLAYWRIGHT_TRACE : attachment.contentType;
852
1162
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.path, {
853
1163
  contentType: contentType
854
1164
  });
855
- case 7:
1165
+ case 6:
856
1166
  if (attachment.name.match(diffEndRegexp)) {
857
- _context6.n = 8;
1167
+ _context7.n = 7;
858
1168
  break;
859
1169
  }
860
- return _context6.a(2);
861
- case 8:
1170
+ return _context7.a(2);
1171
+ case 7:
862
1172
  pathWithoutEndFromSnapshotDir = (_replace = attachment.path.replace(this.outputDir, this.snapshotDir)) === null || _replace === void 0 ? void 0 : _replace.replace(diffEndRegexp, "").replace(/\.png/, "");
863
1173
  pathWithoutEnd = attachment.path.replace(diffEndRegexp, "").replace(/\.png/, "");
864
1174
  if (!(this.processedDiffs.includes(pathWithoutEnd) || this.processedDiffs.includes(pathWithoutEndFromSnapshotDir))) {
865
- _context6.n = 9;
1175
+ _context7.n = 8;
866
1176
  break;
867
1177
  }
868
- return _context6.a(2);
869
- case 9:
1178
+ return _context7.a(2);
1179
+ case 8:
870
1180
  fileExists = /*#__PURE__*/function () {
871
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(filePath) {
872
- return _regenerator().w(function (_context4) {
873
- while (1) switch (_context4.n) {
1181
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(filePath) {
1182
+ return _regenerator().w(function (_context5) {
1183
+ while (1) switch (_context5.n) {
874
1184
  case 0:
875
- _context4.n = 1;
1185
+ _context5.n = 1;
876
1186
  return access(filePath).then(function () {
877
1187
  return true;
878
1188
  })["catch"](function () {
879
1189
  return false;
880
1190
  });
881
1191
  case 1:
882
- return _context4.a(2, _context4.v);
1192
+ return _context5.a(2, _context5.v);
883
1193
  }
884
- }, _callee4);
1194
+ }, _callee5);
885
1195
  }));
886
- return function fileExists(_x6) {
1196
+ return function fileExists(_x7) {
887
1197
  return _ref4.apply(this, arguments);
888
1198
  };
889
1199
  }();
890
1200
  readImageFromDirs = /*#__PURE__*/function () {
891
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(modifier) {
1201
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(modifier) {
892
1202
  var defaultPath, snapshotPath;
893
- return _regenerator().w(function (_context5) {
894
- while (1) switch (_context5.n) {
1203
+ return _regenerator().w(function (_context6) {
1204
+ while (1) switch (_context6.n) {
895
1205
  case 0:
896
1206
  defaultPath = "".concat(pathWithoutEnd, "-").concat(modifier, ".png");
897
1207
  snapshotPath = "".concat(pathWithoutEndFromSnapshotDir, "-").concat(modifier, ".png");
898
- _context5.n = 1;
1208
+ _context6.n = 1;
899
1209
  return fileExists(defaultPath);
900
1210
  case 1:
901
- if (!_context5.v) {
902
- _context5.n = 3;
1211
+ if (!_context6.v) {
1212
+ _context6.n = 3;
903
1213
  break;
904
1214
  }
905
- _context5.n = 2;
1215
+ _context6.n = 2;
906
1216
  return readImageAsBase64(defaultPath);
907
1217
  case 2:
908
- return _context5.a(2, _context5.v);
1218
+ return _context6.a(2, _context6.v);
909
1219
  case 3:
910
- _context5.n = 4;
1220
+ _context6.n = 4;
911
1221
  return fileExists(snapshotPath);
912
1222
  case 4:
913
- if (!_context5.v) {
914
- _context5.n = 6;
1223
+ if (!_context6.v) {
1224
+ _context6.n = 6;
915
1225
  break;
916
1226
  }
917
- _context5.n = 5;
1227
+ _context6.n = 5;
918
1228
  return readImageAsBase64(snapshotPath);
919
1229
  case 5:
920
- return _context5.a(2, _context5.v);
1230
+ return _context6.a(2, _context6.v);
921
1231
  case 6:
922
- return _context5.a(2, undefined);
1232
+ return _context6.a(2, undefined);
923
1233
  }
924
- }, _callee5);
1234
+ }, _callee6);
925
1235
  }));
926
- return function readImageFromDirs(_x7) {
1236
+ return function readImageFromDirs(_x8) {
927
1237
  return _ref5.apply(this, arguments);
928
1238
  };
929
1239
  }();
930
- _context6.n = 10;
1240
+ _context7.n = 9;
931
1241
  return readImageFromDirs("actual");
932
- case 10:
933
- actualBase64 = _context6.v;
934
- _context6.n = 11;
1242
+ case 9:
1243
+ actualBase64 = _context7.v;
1244
+ _context7.n = 10;
935
1245
  return readImageFromDirs("expected");
936
- case 11:
937
- expectedBase64 = _context6.v;
938
- _context6.n = 12;
1246
+ case 10:
1247
+ expectedBase64 = _context7.v;
1248
+ _context7.n = 11;
939
1249
  return readImageFromDirs("diff");
940
- case 12:
941
- diffBase64 = _context6.v;
1250
+ case 11:
1251
+ diffBase64 = _context7.v;
942
1252
  diffName = attachment.name.replace(diffEndRegexp, "");
943
1253
  this.allureRuntime.writeAttachment(testUuid, undefined, diffName, Buffer.from(JSON.stringify({
944
1254
  expected: expectedBase64,
@@ -950,12 +1260,12 @@ export var AllureReporter = /*#__PURE__*/function () {
950
1260
  fileExtension: ".imagediff"
951
1261
  });
952
1262
  this.processedDiffs.push(pathWithoutEnd);
953
- case 13:
954
- return _context6.a(2);
1263
+ case 12:
1264
+ return _context7.a(2);
955
1265
  }
956
- }, _callee6, this);
1266
+ }, _callee7, this);
957
1267
  }));
958
- function processAttachment(_x3, _x4, _x5) {
1268
+ function processAttachment(_x4, _x5, _x6) {
959
1269
  return _processAttachment.apply(this, arguments);
960
1270
  }
961
1271
  return processAttachment;
@@ -987,6 +1297,22 @@ function _shouldIgnoreStep(step) {
987
1297
  }
988
1298
  return false;
989
1299
  }
1300
+ function _getOrCreateHookStack(testId, isBeforeHook, startTime) {
1301
+ var map = isBeforeHook ? this.beforeHooksStepsStack : this.afterHooksStepsStack;
1302
+ var stack = map.get(testId);
1303
+ if (!stack) {
1304
+ stack = new ShallowStepsStack();
1305
+ var rootHookStep = _objectSpread(_objectSpread({}, createStepResult()), {}, {
1306
+ name: isBeforeHook ? BEFORE_HOOKS_ROOT_STEP_TITLE : AFTER_HOOKS_ROOT_STEP_TITLE,
1307
+ start: startTime.getTime(),
1308
+ stage: Stage.RUNNING,
1309
+ uuid: randomUuid()
1310
+ });
1311
+ stack.startStep(rootHookStep);
1312
+ map.set(testId, stack);
1313
+ }
1314
+ return stack;
1315
+ }
990
1316
  export var allure = allurePlaywrightLegacyApi;
991
1317
 
992
1318
  /**