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/cjs/index.js CHANGED
@@ -71,8 +71,6 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
71
71
  _defineProperty(this, "attachmentTargets", new Map());
72
72
  _defineProperty(this, "beforeHooksStepsStack", new Map());
73
73
  _defineProperty(this, "afterHooksStepsStack", new Map());
74
- _defineProperty(this, "beforeHooksAttachmentsStack", new Map());
75
- _defineProperty(this, "afterHooksAttachmentsStack", new Map());
76
74
  _defineProperty(this, "pwStepUuid", new WeakMap());
77
75
  _defineProperty(this, "testPlan", (0, _reporter.parseTestPlan)());
78
76
  this.options = _objectSpread({
@@ -301,56 +299,41 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
301
299
  return;
302
300
  }
303
301
  if (isHookStep) {
304
- // Lazily initialize the hook stack if it doesn't exist (e.g., when detail: false and root hook was ignored)
305
- var stack = isBeforeHookDescendant ? this.beforeHooksStepsStack.get(test.id) : this.afterHooksStepsStack.get(test.id);
306
- if (!stack) {
307
- stack = new _reporter.ShallowStepsStack();
308
- var rootHookStep = _objectSpread(_objectSpread({}, (0, _reporter.createStepResult)()), {}, {
309
- name: isBeforeHookDescendant ? _utils.BEFORE_HOOKS_ROOT_STEP_TITLE : _utils.AFTER_HOOKS_ROOT_STEP_TITLE,
310
- start: step.startTime.getTime(),
311
- stage: _allureJsCommons.Stage.RUNNING,
312
- uuid: (0, _reporter.randomUuid)()
313
- });
314
- stack.startStep(rootHookStep);
315
- if (isBeforeHookDescendant) {
316
- this.beforeHooksStepsStack.set(test.id, stack);
317
- } else {
318
- this.afterHooksStepsStack.set(test.id, stack);
319
- }
320
- }
321
302
  if (["test.attach", "attach"].includes(step.category)) {
322
- var _this$attachmentTarge2;
303
+ var _stack$currentStep, _this$attachmentTarge2;
304
+ var attachmentName = (0, _utils.normalizeAttachStepTitle)(step.title);
305
+ var _stack = _assertClassBrand(_AllureReporter_brand, this, _getOrCreateHookStack).call(this, test.id, isBeforeHookDescendant, step.startTime);
323
306
  var hookStepWithUuid;
324
- stack.startStep(baseStep);
325
- var attachStack = isBeforeHookDescendant ? this.beforeHooksAttachmentsStack : this.afterHooksAttachmentsStack;
326
- stack.updateStep(function (stepResult) {
327
- var _attachStack$get;
307
+ var parentHookStepUuid = (_stack$currentStep = _stack.currentStep()) === null || _stack$currentStep === void 0 ? void 0 : _stack$currentStep.uuid;
308
+ _stack.startStep(baseStep);
309
+ _stack.updateStep(function (stepResult) {
328
310
  hookStepWithUuid = _objectSpread(_objectSpread({}, step), {}, {
329
311
  uuid: stepResult.uuid
330
312
  });
331
313
  stepResult.name = (0, _utils.normalizeHookTitle)(stepResult.name);
332
314
  stepResult.stage = _allureJsCommons.Stage.FINISHED;
333
- attachStack.set(test.id, [].concat(_toConsumableArray((_attachStack$get = attachStack.get(test.id)) !== null && _attachStack$get !== void 0 ? _attachStack$get : []), [hookStepWithUuid]));
334
315
  });
335
- stack.stopStep();
316
+ _stack.stopStep();
336
317
  var _targets = (_this$attachmentTarge2 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge2 !== void 0 ? _this$attachmentTarge2 : [];
337
318
  _targets.push({
338
- name: (0, _utils.normalizeAttachStepTitle)(step.title),
339
- hookStep: hookStepWithUuid
319
+ name: attachmentName,
320
+ hookStep: hookStepWithUuid,
321
+ stepUuid: attachmentName === "Allure Step Metadata" ? parentHookStepUuid : undefined
340
322
  });
341
323
  this.attachmentTargets.set(test.id, _targets);
342
324
  return;
343
325
  }
326
+ var stack = _assertClassBrand(_AllureReporter_brand, this, _getOrCreateHookStack).call(this, test.id, isBeforeHookDescendant, step.startTime);
344
327
  stack.startStep(baseStep);
345
328
  return;
346
329
  }
347
330
  if (isRootHook) {
348
- var _stack = new _reporter.ShallowStepsStack();
349
- _stack.startStep(baseStep);
331
+ var _stack2 = new _reporter.ShallowStepsStack();
332
+ _stack2.startStep(baseStep);
350
333
  if (isRootBeforeHook) {
351
- this.beforeHooksStepsStack.set(test.id, _stack);
334
+ this.beforeHooksStepsStack.set(test.id, _stack2);
352
335
  } else {
353
- this.afterHooksStepsStack.set(test.id, _stack);
336
+ this.afterHooksStepsStack.set(test.id, _stack2);
354
337
  }
355
338
  return;
356
339
  }
@@ -395,16 +378,16 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
395
378
  var isAfterHook = isAfterHookDescendant;
396
379
  var isHook = isBeforeHookDescendant || isAfterHookDescendant;
397
380
  if (isHook) {
398
- var _stack2 = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
381
+ var _stack3 = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
399
382
 
400
383
  // Stack might not exist if root hook was ignored (e.g., detail: false) and no test.step was called inside it
401
- if (!_stack2) {
384
+ if (!_stack3) {
402
385
  return;
403
386
  }
404
- _stack2.updateStep(function (stepResult) {
387
+ _stack3.updateStep(function (stepResult) {
405
388
  return (0, _utils.finalizeStepResult)(stepResult, step);
406
389
  });
407
- _stack2.stopStep({
390
+ _stack3.stopStep({
408
391
  duration: step.duration
409
392
  });
410
393
  return;
@@ -429,9 +412,8 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
429
412
  value: function () {
430
413
  var _onTestEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(test, result) {
431
414
  var _this2 = this,
432
- _this$beforeHooksAtta,
433
415
  _this$attachmentTarge3;
434
- 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;
416
+ 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;
435
417
  return _regenerator().w(function (_context) {
436
418
  while (1) switch (_context.n) {
437
419
  case 0:
@@ -489,7 +471,8 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
489
471
  contentType: _allureJsCommons.ContentType.TEXT
490
472
  });
491
473
  }
492
- attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : []; // FIFO
474
+
475
+ // FIFO
493
476
  targets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
494
477
  targetsByName = new Map();
495
478
  _iterator2 = _createForOfIteratorHelper(targets);
@@ -517,33 +500,49 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
517
500
  _iterator3.s();
518
501
  case 2:
519
502
  if ((_step3 = _iterator3.n()).done) {
520
- _context.n = 9;
503
+ _context.n = 10;
521
504
  break;
522
505
  }
523
506
  attachment = _step3.value;
524
507
  isRuntimeMessage = attachment.contentType === _reporter.ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
525
508
  stepInfo = takeByName(attachment.name);
526
509
  if (!isRuntimeMessage) {
527
- _context.n = 4;
510
+ _context.n = 5;
528
511
  break;
529
512
  }
513
+ message = attachment.body ? JSON.parse(attachment.body.toString()) : undefined;
514
+ if (stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep) {
515
+ targetStack = (0, _utils.isBeforeHookStep)(stepInfo.hookStep) ? beforeHooksStack : afterHooksStack;
516
+ this.removeStepFromHookStack(targetStack, stepInfo.hookStep.uuid);
517
+ }
518
+ if (!((message === null || message === void 0 ? void 0 : message.type) === "step_metadata" && stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
519
+ _context.n = 3;
520
+ break;
521
+ }
522
+ if (stepInfo.hookStep) {
523
+ _targetStack = (0, _utils.isBeforeHookStep)(stepInfo.hookStep) ? beforeHooksStack : afterHooksStack;
524
+ this.processHookStepMetadataMessage(_targetStack, stepInfo.stepUuid, message);
525
+ } else {
526
+ this.processStepMetadataMessage(stepInfo.stepUuid, message);
527
+ }
528
+ return _context.a(3, 9);
529
+ case 3:
530
530
  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;
531
- _context.n = 3;
531
+ _context.n = 4;
532
532
  return this.processAttachment(testUuid, stepUuid, attachment);
533
- case 3:
534
- return _context.a(3, 8);
535
533
  case 4:
534
+ return _context.a(3, 9);
535
+ case 5:
536
536
  if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep)) {
537
- _context.n = 5;
537
+ _context.n = 6;
538
538
  break;
539
539
  }
540
540
  hookStep = stepInfo.hookStep;
541
- isBeforeHook = attachmentsInBeforeHooks.includes(hookStep);
542
- targetStack = isBeforeHook ? beforeHooksStack : afterHooksStack;
543
- if (targetStack) {
544
- stepResult = targetStack.findStepByUuid(hookStep.uuid);
541
+ _targetStack2 = (0, _utils.isBeforeHookStep)(hookStep) ? beforeHooksStack : afterHooksStack;
542
+ if (_targetStack2) {
543
+ stepResult = _targetStack2.findStepByUuid(hookStep.uuid);
545
544
  if (stepResult) {
546
- fileName = targetStack.addAttachment(attachment, this.allureRuntime.writer);
545
+ fileName = _targetStack2.addAttachment(attachment, this.allureRuntime.writer);
547
546
  stepResult.attachments.push({
548
547
  name: attachment.name,
549
548
  type: attachment.contentType,
@@ -551,34 +550,34 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
551
550
  });
552
551
  }
553
552
  }
554
- return _context.a(3, 8);
555
- case 5:
553
+ return _context.a(3, 9);
554
+ case 6:
556
555
  if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
557
- _context.n = 7;
556
+ _context.n = 8;
558
557
  break;
559
558
  }
560
- _context.n = 6;
559
+ _context.n = 7;
561
560
  return this.processAttachment(testUuid, stepInfo.stepUuid, attachment);
562
- case 6:
563
- return _context.a(3, 8);
564
561
  case 7:
565
- _context.n = 8;
566
- return this.processAttachment(testUuid, undefined, attachment);
562
+ return _context.a(3, 9);
567
563
  case 8:
568
- _context.n = 2;
569
- break;
564
+ _context.n = 9;
565
+ return this.processAttachment(testUuid, undefined, attachment);
570
566
  case 9:
571
- _context.n = 11;
567
+ _context.n = 2;
572
568
  break;
573
569
  case 10:
574
- _context.p = 10;
575
- _t = _context.v;
576
- _iterator3.e(_t);
570
+ _context.n = 12;
571
+ break;
577
572
  case 11:
578
573
  _context.p = 11;
579
- _iterator3.f();
580
- return _context.f(11);
574
+ _t = _context.v;
575
+ _iterator3.e(_t);
581
576
  case 12:
577
+ _context.p = 12;
578
+ _iterator3.f();
579
+ return _context.f(12);
580
+ case 13:
582
581
  // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
583
582
  // in next iterations we need to implement the logic for every javascript integration
584
583
  this.allureRuntime.updateTest(testUuid, function (testResult) {
@@ -599,13 +598,13 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
599
598
  if (beforeHooksStack) {
600
599
  var _testResult$steps;
601
600
  (_testResult$steps = testResult.steps).unshift.apply(_testResult$steps, _toConsumableArray(beforeHooksStack.steps));
602
- _this2.beforeHooksStepsStack["delete"](test.id);
603
601
  }
602
+ _this2.beforeHooksStepsStack["delete"](test.id);
604
603
  if (afterHooksStack) {
605
604
  var _testResult$steps2;
606
605
  (_testResult$steps2 = testResult.steps).push.apply(_testResult$steps2, _toConsumableArray(afterHooksStack.steps));
607
- _this2.afterHooksStepsStack["delete"](test.id);
608
606
  }
607
+ _this2.afterHooksStepsStack["delete"](test.id);
609
608
  testResult.labels = newLabels;
610
609
  });
611
610
  this.allureRuntime.stopTest(testUuid, {
@@ -613,10 +612,10 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
613
612
  });
614
613
  this.allureRuntime.writeTest(testUuid);
615
614
  this.attachmentTargets["delete"](test.id);
616
- case 13:
615
+ case 14:
617
616
  return _context.a(2);
618
617
  }
619
- }, _callee, this, [[1, 10, 11, 12]]);
618
+ }, _callee, this, [[1, 11, 12, 13]]);
620
619
  }));
621
620
  function onTestEnd(_x, _x2) {
622
621
  return _onTestEnd.apply(this, arguments);
@@ -713,6 +712,25 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
713
712
  value: function printsToStdio() {
714
713
  return false;
715
714
  }
715
+ }, {
716
+ key: "removeStepFromHookStack",
717
+ value: function removeStepFromHookStack(stack, stepUuid) {
718
+ if (!stack) {
719
+ return;
720
+ }
721
+ var _removeRecursively = function removeRecursively(steps) {
722
+ return steps.filter(function (step) {
723
+ return step.uuid !== stepUuid;
724
+ }).map(function (step) {
725
+ return _objectSpread(_objectSpread({}, step), {}, {
726
+ steps: _removeRecursively(step.steps)
727
+ });
728
+ }).filter(function (step) {
729
+ return step.name !== _utils.BEFORE_HOOKS_ROOT_STEP_TITLE && step.name !== _utils.AFTER_HOOKS_ROOT_STEP_TITLE || step.steps.length > 0 || step.attachments.length > 0 || step.status !== _allureJsCommons.Status.PASSED;
730
+ });
731
+ };
732
+ stack.steps = _removeRecursively(stack.steps);
733
+ }
716
734
  }, {
717
735
  key: "getStaticTestMetadata",
718
736
  value: function getStaticTestMetadata(test) {
@@ -804,6 +822,23 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
804
822
  (_step$parameters = step.parameters).push.apply(_step$parameters, _toConsumableArray(parameters));
805
823
  });
806
824
  }
825
+ }, {
826
+ key: "processHookStepMetadataMessage",
827
+ value: function processHookStepMetadataMessage(stack, attachmentStepUuid, message) {
828
+ var _step$parameters2;
829
+ var step = stack === null || stack === void 0 ? void 0 : stack.findStepByUuid(attachmentStepUuid);
830
+ if (!step) {
831
+ return;
832
+ }
833
+ var _message$data2 = message.data,
834
+ name = _message$data2.name,
835
+ _message$data2$parame = _message$data2.parameters,
836
+ parameters = _message$data2$parame === void 0 ? [] : _message$data2$parame;
837
+ if (name) {
838
+ step.name = name;
839
+ }
840
+ (_step$parameters2 = step.parameters).push.apply(_step$parameters2, _toConsumableArray(parameters));
841
+ }
807
842
  }, {
808
843
  key: "processAttachment",
809
844
  value: function () {
@@ -827,20 +862,13 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
827
862
  return _context6.a(2);
828
863
  case 2:
829
864
  if (!allureRuntimeMessage) {
830
- _context6.n = 4;
831
- break;
832
- }
833
- message = JSON.parse(attachment.body.toString());
834
- if (!(message.type === "step_metadata")) {
835
865
  _context6.n = 3;
836
866
  break;
837
867
  }
838
- this.processStepMetadataMessage(attachmentStepUuid, message);
839
- return _context6.a(2);
840
- case 3:
868
+ message = JSON.parse(attachment.body.toString());
841
869
  this.allureRuntime.applyRuntimeMessages(testUuid, [message]);
842
870
  return _context6.a(2);
843
- case 4:
871
+ case 3:
844
872
  parentUuid = this.allureRuntime.startStep(testUuid, attachmentStepUuid, {
845
873
  name: attachment.name
846
874
  }); // only stop if step is created. Step may not be created only if test with specified uuid doesn't exists.
@@ -850,40 +878,40 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
850
878
  this.allureRuntime.stopStep(parentUuid, undefined);
851
879
  }
852
880
  if (!attachment.body) {
853
- _context6.n = 5;
881
+ _context6.n = 4;
854
882
  break;
855
883
  }
856
884
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.body, {
857
885
  contentType: attachment.contentType
858
886
  });
859
- _context6.n = 7;
887
+ _context6.n = 6;
860
888
  break;
861
- case 5:
889
+ case 4:
862
890
  if ((0, _nodeFs.existsSync)(attachment.path)) {
863
- _context6.n = 6;
891
+ _context6.n = 5;
864
892
  break;
865
893
  }
866
894
  return _context6.a(2);
867
- case 6:
868
- contentType = attachment.name === "trace" && attachment.contentType === "application/zip" ? "application/vnd.allure.playwright-trace" : attachment.contentType;
895
+ case 5:
896
+ contentType = attachment.name === "trace" && attachment.contentType === "application/zip" ? _allureJsCommons.ContentType.PLAYWRIGHT_TRACE : attachment.contentType;
869
897
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.path, {
870
898
  contentType: contentType
871
899
  });
872
- case 7:
900
+ case 6:
873
901
  if (attachment.name.match(_utils.diffEndRegexp)) {
874
- _context6.n = 8;
902
+ _context6.n = 7;
875
903
  break;
876
904
  }
877
905
  return _context6.a(2);
878
- case 8:
906
+ case 7:
879
907
  pathWithoutEndFromSnapshotDir = (_replace = attachment.path.replace(this.outputDir, this.snapshotDir)) === null || _replace === void 0 ? void 0 : _replace.replace(_utils.diffEndRegexp, "").replace(/\.png/, "");
880
908
  pathWithoutEnd = attachment.path.replace(_utils.diffEndRegexp, "").replace(/\.png/, "");
881
909
  if (!(this.processedDiffs.includes(pathWithoutEnd) || this.processedDiffs.includes(pathWithoutEndFromSnapshotDir))) {
882
- _context6.n = 9;
910
+ _context6.n = 8;
883
911
  break;
884
912
  }
885
913
  return _context6.a(2);
886
- case 9:
914
+ case 8:
887
915
  fileExists = /*#__PURE__*/function () {
888
916
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(filePath) {
889
917
  return _regenerator().w(function (_context4) {
@@ -944,17 +972,17 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
944
972
  return _ref5.apply(this, arguments);
945
973
  };
946
974
  }();
947
- _context6.n = 10;
975
+ _context6.n = 9;
948
976
  return readImageFromDirs("actual");
949
- case 10:
977
+ case 9:
950
978
  actualBase64 = _context6.v;
951
- _context6.n = 11;
979
+ _context6.n = 10;
952
980
  return readImageFromDirs("expected");
953
- case 11:
981
+ case 10:
954
982
  expectedBase64 = _context6.v;
955
- _context6.n = 12;
983
+ _context6.n = 11;
956
984
  return readImageFromDirs("diff");
957
- case 12:
985
+ case 11:
958
986
  diffBase64 = _context6.v;
959
987
  diffName = attachment.name.replace(_utils.diffEndRegexp, "");
960
988
  this.allureRuntime.writeAttachment(testUuid, undefined, diffName, Buffer.from(JSON.stringify({
@@ -967,7 +995,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
967
995
  fileExtension: ".imagediff"
968
996
  });
969
997
  this.processedDiffs.push(pathWithoutEnd);
970
- case 13:
998
+ case 12:
971
999
  return _context6.a(2);
972
1000
  }
973
1001
  }, _callee6, this);
@@ -1003,6 +1031,22 @@ function _shouldIgnoreStep(step) {
1003
1031
  }
1004
1032
  return false;
1005
1033
  }
1034
+ function _getOrCreateHookStack(testId, isBeforeHook, startTime) {
1035
+ var map = isBeforeHook ? this.beforeHooksStepsStack : this.afterHooksStepsStack;
1036
+ var stack = map.get(testId);
1037
+ if (!stack) {
1038
+ stack = new _reporter.ShallowStepsStack();
1039
+ var rootHookStep = _objectSpread(_objectSpread({}, (0, _reporter.createStepResult)()), {}, {
1040
+ name: isBeforeHook ? _utils.BEFORE_HOOKS_ROOT_STEP_TITLE : _utils.AFTER_HOOKS_ROOT_STEP_TITLE,
1041
+ start: startTime.getTime(),
1042
+ stage: _allureJsCommons.Stage.RUNNING,
1043
+ uuid: (0, _reporter.randomUuid)()
1044
+ });
1045
+ stack.startStep(rootHookStep);
1046
+ map.set(testId, stack);
1047
+ }
1048
+ return stack;
1049
+ }
1006
1050
  var allure = exports.allure = _legacy.allurePlaywrightLegacyApi;
1007
1051
 
1008
1052
  /**