allure-playwright 3.7.1 → 3.7.2

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
@@ -54,8 +54,6 @@ 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());
59
57
  _defineProperty(this, "pwStepUuid", new WeakMap());
60
58
  _defineProperty(this, "testPlan", parseTestPlan());
61
59
  this.options = _objectSpread({
@@ -284,56 +282,41 @@ export var AllureReporter = /*#__PURE__*/function () {
284
282
  return;
285
283
  }
286
284
  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
285
  if (["test.attach", "attach"].includes(step.category)) {
305
- var _this$attachmentTarge2;
286
+ var _stack$currentStep, _this$attachmentTarge2;
287
+ var attachmentName = normalizeAttachStepTitle(step.title);
288
+ var _stack = _assertClassBrand(_AllureReporter_brand, this, _getOrCreateHookStack).call(this, test.id, isBeforeHookDescendant, step.startTime);
306
289
  var hookStepWithUuid;
307
- stack.startStep(baseStep);
308
- var attachStack = isBeforeHookDescendant ? this.beforeHooksAttachmentsStack : this.afterHooksAttachmentsStack;
309
- stack.updateStep(function (stepResult) {
310
- var _attachStack$get;
290
+ var parentHookStepUuid = (_stack$currentStep = _stack.currentStep()) === null || _stack$currentStep === void 0 ? void 0 : _stack$currentStep.uuid;
291
+ _stack.startStep(baseStep);
292
+ _stack.updateStep(function (stepResult) {
311
293
  hookStepWithUuid = _objectSpread(_objectSpread({}, step), {}, {
312
294
  uuid: stepResult.uuid
313
295
  });
314
296
  stepResult.name = normalizeHookTitle(stepResult.name);
315
297
  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
298
  });
318
- stack.stopStep();
299
+ _stack.stopStep();
319
300
  var _targets = (_this$attachmentTarge2 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge2 !== void 0 ? _this$attachmentTarge2 : [];
320
301
  _targets.push({
321
- name: normalizeAttachStepTitle(step.title),
322
- hookStep: hookStepWithUuid
302
+ name: attachmentName,
303
+ hookStep: hookStepWithUuid,
304
+ stepUuid: attachmentName === "Allure Step Metadata" ? parentHookStepUuid : undefined
323
305
  });
324
306
  this.attachmentTargets.set(test.id, _targets);
325
307
  return;
326
308
  }
309
+ var stack = _assertClassBrand(_AllureReporter_brand, this, _getOrCreateHookStack).call(this, test.id, isBeforeHookDescendant, step.startTime);
327
310
  stack.startStep(baseStep);
328
311
  return;
329
312
  }
330
313
  if (isRootHook) {
331
- var _stack = new ShallowStepsStack();
332
- _stack.startStep(baseStep);
314
+ var _stack2 = new ShallowStepsStack();
315
+ _stack2.startStep(baseStep);
333
316
  if (isRootBeforeHook) {
334
- this.beforeHooksStepsStack.set(test.id, _stack);
317
+ this.beforeHooksStepsStack.set(test.id, _stack2);
335
318
  } else {
336
- this.afterHooksStepsStack.set(test.id, _stack);
319
+ this.afterHooksStepsStack.set(test.id, _stack2);
337
320
  }
338
321
  return;
339
322
  }
@@ -378,16 +361,16 @@ export var AllureReporter = /*#__PURE__*/function () {
378
361
  var isAfterHook = isAfterHookDescendant;
379
362
  var isHook = isBeforeHookDescendant || isAfterHookDescendant;
380
363
  if (isHook) {
381
- var _stack2 = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
364
+ var _stack3 = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
382
365
 
383
366
  // Stack might not exist if root hook was ignored (e.g., detail: false) and no test.step was called inside it
384
- if (!_stack2) {
367
+ if (!_stack3) {
385
368
  return;
386
369
  }
387
- _stack2.updateStep(function (stepResult) {
370
+ _stack3.updateStep(function (stepResult) {
388
371
  return finalizeStepResult(stepResult, step);
389
372
  });
390
- _stack2.stopStep({
373
+ _stack3.stopStep({
391
374
  duration: step.duration
392
375
  });
393
376
  return;
@@ -412,9 +395,8 @@ export var AllureReporter = /*#__PURE__*/function () {
412
395
  value: function () {
413
396
  var _onTestEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(test, result) {
414
397
  var _this2 = this,
415
- _this$beforeHooksAtta,
416
398
  _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;
399
+ var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, beforeHooksStack, afterHooksStack, targets, targetsByName, _iterator2, _step2, _targetsByName$get, t, q, takeByName, _iterator3, _step3, attachment, isRuntimeMessage, stepInfo, _stepInfo$hookStep$uu, _stepInfo$hookStep, message, targetStack, _targetStack, stepUuid, hookStep, _targetStack2, stepResult, fileName, _t;
418
400
  return _regenerator().w(function (_context) {
419
401
  while (1) switch (_context.n) {
420
402
  case 0:
@@ -472,7 +454,8 @@ export var AllureReporter = /*#__PURE__*/function () {
472
454
  contentType: ContentType.TEXT
473
455
  });
474
456
  }
475
- attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : []; // FIFO
457
+
458
+ // FIFO
476
459
  targets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
477
460
  targetsByName = new Map();
478
461
  _iterator2 = _createForOfIteratorHelper(targets);
@@ -500,33 +483,49 @@ export var AllureReporter = /*#__PURE__*/function () {
500
483
  _iterator3.s();
501
484
  case 2:
502
485
  if ((_step3 = _iterator3.n()).done) {
503
- _context.n = 9;
486
+ _context.n = 10;
504
487
  break;
505
488
  }
506
489
  attachment = _step3.value;
507
490
  isRuntimeMessage = attachment.contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
508
491
  stepInfo = takeByName(attachment.name);
509
492
  if (!isRuntimeMessage) {
510
- _context.n = 4;
493
+ _context.n = 5;
511
494
  break;
512
495
  }
496
+ message = attachment.body ? JSON.parse(attachment.body.toString()) : undefined;
497
+ if (stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep) {
498
+ targetStack = isBeforeHookStep(stepInfo.hookStep) ? beforeHooksStack : afterHooksStack;
499
+ this.removeStepFromHookStack(targetStack, stepInfo.hookStep.uuid);
500
+ }
501
+ if (!((message === null || message === void 0 ? void 0 : message.type) === "step_metadata" && stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
502
+ _context.n = 3;
503
+ break;
504
+ }
505
+ if (stepInfo.hookStep) {
506
+ _targetStack = isBeforeHookStep(stepInfo.hookStep) ? beforeHooksStack : afterHooksStack;
507
+ this.processHookStepMetadataMessage(_targetStack, stepInfo.stepUuid, message);
508
+ } else {
509
+ this.processStepMetadataMessage(stepInfo.stepUuid, message);
510
+ }
511
+ return _context.a(3, 9);
512
+ case 3:
513
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;
514
+ _context.n = 4;
515
515
  return this.processAttachment(testUuid, stepUuid, attachment);
516
- case 3:
517
- return _context.a(3, 8);
518
516
  case 4:
517
+ return _context.a(3, 9);
518
+ case 5:
519
519
  if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep)) {
520
- _context.n = 5;
520
+ _context.n = 6;
521
521
  break;
522
522
  }
523
523
  hookStep = stepInfo.hookStep;
524
- isBeforeHook = attachmentsInBeforeHooks.includes(hookStep);
525
- targetStack = isBeforeHook ? beforeHooksStack : afterHooksStack;
526
- if (targetStack) {
527
- stepResult = targetStack.findStepByUuid(hookStep.uuid);
524
+ _targetStack2 = isBeforeHookStep(hookStep) ? beforeHooksStack : afterHooksStack;
525
+ if (_targetStack2) {
526
+ stepResult = _targetStack2.findStepByUuid(hookStep.uuid);
528
527
  if (stepResult) {
529
- fileName = targetStack.addAttachment(attachment, this.allureRuntime.writer);
528
+ fileName = _targetStack2.addAttachment(attachment, this.allureRuntime.writer);
530
529
  stepResult.attachments.push({
531
530
  name: attachment.name,
532
531
  type: attachment.contentType,
@@ -534,34 +533,34 @@ export var AllureReporter = /*#__PURE__*/function () {
534
533
  });
535
534
  }
536
535
  }
537
- return _context.a(3, 8);
538
- case 5:
536
+ return _context.a(3, 9);
537
+ case 6:
539
538
  if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
540
- _context.n = 7;
539
+ _context.n = 8;
541
540
  break;
542
541
  }
543
- _context.n = 6;
542
+ _context.n = 7;
544
543
  return this.processAttachment(testUuid, stepInfo.stepUuid, attachment);
545
- case 6:
546
- return _context.a(3, 8);
547
544
  case 7:
548
- _context.n = 8;
549
- return this.processAttachment(testUuid, undefined, attachment);
545
+ return _context.a(3, 9);
550
546
  case 8:
551
- _context.n = 2;
552
- break;
547
+ _context.n = 9;
548
+ return this.processAttachment(testUuid, undefined, attachment);
553
549
  case 9:
554
- _context.n = 11;
550
+ _context.n = 2;
555
551
  break;
556
552
  case 10:
557
- _context.p = 10;
558
- _t = _context.v;
559
- _iterator3.e(_t);
553
+ _context.n = 12;
554
+ break;
560
555
  case 11:
561
556
  _context.p = 11;
562
- _iterator3.f();
563
- return _context.f(11);
557
+ _t = _context.v;
558
+ _iterator3.e(_t);
564
559
  case 12:
560
+ _context.p = 12;
561
+ _iterator3.f();
562
+ return _context.f(12);
563
+ case 13:
565
564
  // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
566
565
  // in next iterations we need to implement the logic for every javascript integration
567
566
  this.allureRuntime.updateTest(testUuid, function (testResult) {
@@ -582,13 +581,13 @@ export var AllureReporter = /*#__PURE__*/function () {
582
581
  if (beforeHooksStack) {
583
582
  var _testResult$steps;
584
583
  (_testResult$steps = testResult.steps).unshift.apply(_testResult$steps, _toConsumableArray(beforeHooksStack.steps));
585
- _this2.beforeHooksStepsStack["delete"](test.id);
586
584
  }
585
+ _this2.beforeHooksStepsStack["delete"](test.id);
587
586
  if (afterHooksStack) {
588
587
  var _testResult$steps2;
589
588
  (_testResult$steps2 = testResult.steps).push.apply(_testResult$steps2, _toConsumableArray(afterHooksStack.steps));
590
- _this2.afterHooksStepsStack["delete"](test.id);
591
589
  }
590
+ _this2.afterHooksStepsStack["delete"](test.id);
592
591
  testResult.labels = newLabels;
593
592
  });
594
593
  this.allureRuntime.stopTest(testUuid, {
@@ -596,10 +595,10 @@ export var AllureReporter = /*#__PURE__*/function () {
596
595
  });
597
596
  this.allureRuntime.writeTest(testUuid);
598
597
  this.attachmentTargets["delete"](test.id);
599
- case 13:
598
+ case 14:
600
599
  return _context.a(2);
601
600
  }
602
- }, _callee, this, [[1, 10, 11, 12]]);
601
+ }, _callee, this, [[1, 11, 12, 13]]);
603
602
  }));
604
603
  function onTestEnd(_x, _x2) {
605
604
  return _onTestEnd.apply(this, arguments);
@@ -696,6 +695,25 @@ export var AllureReporter = /*#__PURE__*/function () {
696
695
  value: function printsToStdio() {
697
696
  return false;
698
697
  }
698
+ }, {
699
+ key: "removeStepFromHookStack",
700
+ value: function removeStepFromHookStack(stack, stepUuid) {
701
+ if (!stack) {
702
+ return;
703
+ }
704
+ var _removeRecursively = function removeRecursively(steps) {
705
+ return steps.filter(function (step) {
706
+ return step.uuid !== stepUuid;
707
+ }).map(function (step) {
708
+ return _objectSpread(_objectSpread({}, step), {}, {
709
+ steps: _removeRecursively(step.steps)
710
+ });
711
+ }).filter(function (step) {
712
+ 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;
713
+ });
714
+ };
715
+ stack.steps = _removeRecursively(stack.steps);
716
+ }
699
717
  }, {
700
718
  key: "getStaticTestMetadata",
701
719
  value: function getStaticTestMetadata(test) {
@@ -787,6 +805,23 @@ export var AllureReporter = /*#__PURE__*/function () {
787
805
  (_step$parameters = step.parameters).push.apply(_step$parameters, _toConsumableArray(parameters));
788
806
  });
789
807
  }
808
+ }, {
809
+ key: "processHookStepMetadataMessage",
810
+ value: function processHookStepMetadataMessage(stack, attachmentStepUuid, message) {
811
+ var _step$parameters2;
812
+ var step = stack === null || stack === void 0 ? void 0 : stack.findStepByUuid(attachmentStepUuid);
813
+ if (!step) {
814
+ return;
815
+ }
816
+ var _message$data2 = message.data,
817
+ name = _message$data2.name,
818
+ _message$data2$parame = _message$data2.parameters,
819
+ parameters = _message$data2$parame === void 0 ? [] : _message$data2$parame;
820
+ if (name) {
821
+ step.name = name;
822
+ }
823
+ (_step$parameters2 = step.parameters).push.apply(_step$parameters2, _toConsumableArray(parameters));
824
+ }
790
825
  }, {
791
826
  key: "processAttachment",
792
827
  value: function () {
@@ -810,20 +845,13 @@ export var AllureReporter = /*#__PURE__*/function () {
810
845
  return _context6.a(2);
811
846
  case 2:
812
847
  if (!allureRuntimeMessage) {
813
- _context6.n = 4;
814
- break;
815
- }
816
- message = JSON.parse(attachment.body.toString());
817
- if (!(message.type === "step_metadata")) {
818
848
  _context6.n = 3;
819
849
  break;
820
850
  }
821
- this.processStepMetadataMessage(attachmentStepUuid, message);
822
- return _context6.a(2);
823
- case 3:
851
+ message = JSON.parse(attachment.body.toString());
824
852
  this.allureRuntime.applyRuntimeMessages(testUuid, [message]);
825
853
  return _context6.a(2);
826
- case 4:
854
+ case 3:
827
855
  parentUuid = this.allureRuntime.startStep(testUuid, attachmentStepUuid, {
828
856
  name: attachment.name
829
857
  }); // only stop if step is created. Step may not be created only if test with specified uuid doesn't exists.
@@ -833,40 +861,40 @@ export var AllureReporter = /*#__PURE__*/function () {
833
861
  this.allureRuntime.stopStep(parentUuid, undefined);
834
862
  }
835
863
  if (!attachment.body) {
836
- _context6.n = 5;
864
+ _context6.n = 4;
837
865
  break;
838
866
  }
839
867
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.body, {
840
868
  contentType: attachment.contentType
841
869
  });
842
- _context6.n = 7;
870
+ _context6.n = 6;
843
871
  break;
844
- case 5:
872
+ case 4:
845
873
  if (existsSync(attachment.path)) {
846
- _context6.n = 6;
874
+ _context6.n = 5;
847
875
  break;
848
876
  }
849
877
  return _context6.a(2);
850
- case 6:
851
- contentType = attachment.name === "trace" && attachment.contentType === "application/zip" ? "application/vnd.allure.playwright-trace" : attachment.contentType;
878
+ case 5:
879
+ contentType = attachment.name === "trace" && attachment.contentType === "application/zip" ? ContentType.PLAYWRIGHT_TRACE : attachment.contentType;
852
880
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.path, {
853
881
  contentType: contentType
854
882
  });
855
- case 7:
883
+ case 6:
856
884
  if (attachment.name.match(diffEndRegexp)) {
857
- _context6.n = 8;
885
+ _context6.n = 7;
858
886
  break;
859
887
  }
860
888
  return _context6.a(2);
861
- case 8:
889
+ case 7:
862
890
  pathWithoutEndFromSnapshotDir = (_replace = attachment.path.replace(this.outputDir, this.snapshotDir)) === null || _replace === void 0 ? void 0 : _replace.replace(diffEndRegexp, "").replace(/\.png/, "");
863
891
  pathWithoutEnd = attachment.path.replace(diffEndRegexp, "").replace(/\.png/, "");
864
892
  if (!(this.processedDiffs.includes(pathWithoutEnd) || this.processedDiffs.includes(pathWithoutEndFromSnapshotDir))) {
865
- _context6.n = 9;
893
+ _context6.n = 8;
866
894
  break;
867
895
  }
868
896
  return _context6.a(2);
869
- case 9:
897
+ case 8:
870
898
  fileExists = /*#__PURE__*/function () {
871
899
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(filePath) {
872
900
  return _regenerator().w(function (_context4) {
@@ -927,17 +955,17 @@ export var AllureReporter = /*#__PURE__*/function () {
927
955
  return _ref5.apply(this, arguments);
928
956
  };
929
957
  }();
930
- _context6.n = 10;
958
+ _context6.n = 9;
931
959
  return readImageFromDirs("actual");
932
- case 10:
960
+ case 9:
933
961
  actualBase64 = _context6.v;
934
- _context6.n = 11;
962
+ _context6.n = 10;
935
963
  return readImageFromDirs("expected");
936
- case 11:
964
+ case 10:
937
965
  expectedBase64 = _context6.v;
938
- _context6.n = 12;
966
+ _context6.n = 11;
939
967
  return readImageFromDirs("diff");
940
- case 12:
968
+ case 11:
941
969
  diffBase64 = _context6.v;
942
970
  diffName = attachment.name.replace(diffEndRegexp, "");
943
971
  this.allureRuntime.writeAttachment(testUuid, undefined, diffName, Buffer.from(JSON.stringify({
@@ -950,7 +978,7 @@ export var AllureReporter = /*#__PURE__*/function () {
950
978
  fileExtension: ".imagediff"
951
979
  });
952
980
  this.processedDiffs.push(pathWithoutEnd);
953
- case 13:
981
+ case 12:
954
982
  return _context6.a(2);
955
983
  }
956
984
  }, _callee6, this);
@@ -987,6 +1015,22 @@ function _shouldIgnoreStep(step) {
987
1015
  }
988
1016
  return false;
989
1017
  }
1018
+ function _getOrCreateHookStack(testId, isBeforeHook, startTime) {
1019
+ var map = isBeforeHook ? this.beforeHooksStepsStack : this.afterHooksStepsStack;
1020
+ var stack = map.get(testId);
1021
+ if (!stack) {
1022
+ stack = new ShallowStepsStack();
1023
+ var rootHookStep = _objectSpread(_objectSpread({}, createStepResult()), {}, {
1024
+ name: isBeforeHook ? BEFORE_HOOKS_ROOT_STEP_TITLE : AFTER_HOOKS_ROOT_STEP_TITLE,
1025
+ start: startTime.getTime(),
1026
+ stage: Stage.RUNNING,
1027
+ uuid: randomUuid()
1028
+ });
1029
+ stack.startStep(rootHookStep);
1030
+ map.set(testId, stack);
1031
+ }
1032
+ return stack;
1033
+ }
990
1034
  export var allure = allurePlaywrightLegacyApi;
991
1035
 
992
1036
  /**