allure-playwright 3.2.1 → 3.2.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
@@ -51,8 +51,6 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
51
51
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
52
52
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
53
53
  function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
54
- // TODO: move to utils.ts
55
- var diffEndRegexp = /-((expected)|(diff)|(actual))\.png$/;
56
54
  var _AllureReporter_brand = /*#__PURE__*/new WeakSet();
57
55
  var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
58
56
  function AllureReporter(config) {
@@ -69,6 +67,8 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
69
67
  _defineProperty(this, "attachmentSteps", new Map());
70
68
  _defineProperty(this, "beforeHooksStepsStack", new Map());
71
69
  _defineProperty(this, "afterHooksStepsStack", new Map());
70
+ _defineProperty(this, "beforeHooksAttachmentsStack", new Map());
71
+ _defineProperty(this, "afterHooksAttachmentsStack", new Map());
72
72
  this.options = _objectSpread({
73
73
  suiteTitle: true,
74
74
  detail: true
@@ -263,8 +263,14 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
263
263
  }, {
264
264
  key: "onStepBegin",
265
265
  value: function onStepBegin(test, _result, step) {
266
+ var isRootBeforeHook = step.title === _utils.BEFORE_HOOKS_ROOT_STEP_TITLE;
267
+ var isRootAfterHook = step.title === _utils.AFTER_HOOKS_ROOT_STEP_TITLE;
268
+ var isRootHook = isRootBeforeHook || isRootAfterHook;
269
+ var isBeforeHookDescendant = (0, _utils.isBeforeHookStep)(step);
270
+ var isAfterHookDescendant = (0, _utils.isAfterHookStep)(step);
271
+ var isHookStep = isBeforeHookDescendant || isAfterHookDescendant;
266
272
  var testUuid = this.allureResultsUuids.get(test.id);
267
- if (step.category === "attach") {
273
+ if (step.category === "attach" && !isHookStep) {
268
274
  var _this$allureRuntime, _this$attachmentSteps;
269
275
  var currentStep = (_this$allureRuntime = this.allureRuntime) === null || _this$allureRuntime === void 0 ? void 0 : _this$allureRuntime.currentStep(testUuid);
270
276
  this.attachmentSteps.set(testUuid, [].concat(_toConsumableArray((_this$attachmentSteps = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps !== void 0 ? _this$attachmentSteps : []), [currentStep]));
@@ -276,15 +282,25 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
276
282
  var baseStep = _objectSpread(_objectSpread({}, (0, _reporter.createStepResult)()), {}, {
277
283
  name: step.title,
278
284
  start: step.startTime.getTime(),
279
- stage: _allureJsCommons.Stage.RUNNING
285
+ stage: _allureJsCommons.Stage.RUNNING,
286
+ uuid: (0, _reporter.randomUuid)()
280
287
  });
281
- var isRootBeforeHook = step.title === _utils.BEFORE_HOOKS_ROOT_STEP_TITLE;
282
- var isRootAfterHook = step.title === _utils.AFTER_HOOKS_ROOT_STEP_TITLE;
283
- var isRootHook = isRootBeforeHook || isRootAfterHook;
284
- var isBeforeHookDescendant = (0, _utils.isBeforeHookStep)(step);
285
- var isAfterHookDescendant = (0, _utils.isAfterHookStep)(step);
286
- if (isBeforeHookDescendant || isAfterHookDescendant) {
288
+ if (isHookStep) {
287
289
  var stack = isBeforeHookDescendant ? this.beforeHooksStepsStack.get(test.id) : this.afterHooksStepsStack.get(test.id);
290
+ if (step.category === "attach") {
291
+ stack.startStep(baseStep);
292
+ var attachStack = isBeforeHookDescendant ? this.beforeHooksAttachmentsStack : this.afterHooksAttachmentsStack;
293
+ stack.updateStep(function (stepResult) {
294
+ var _attachStack$get;
295
+ stepResult.name = (0, _utils.normalizeHookTitle)(stepResult.name);
296
+ stepResult.stage = _allureJsCommons.Stage.FINISHED;
297
+ attachStack.set(test.id, [].concat(_toConsumableArray((_attachStack$get = attachStack.get(test.id)) !== null && _attachStack$get !== void 0 ? _attachStack$get : []), [_objectSpread(_objectSpread({}, step), {}, {
298
+ uuid: stepResult.uuid
299
+ })]));
300
+ });
301
+ stack.stopStep();
302
+ return;
303
+ }
288
304
  stack.startStep(baseStep);
289
305
  return;
290
306
  }
@@ -306,7 +322,6 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
306
322
  if (_assertClassBrand(_AllureReporter_brand, this, _shouldIgnoreStep).call(this, step)) {
307
323
  return;
308
324
  }
309
-
310
325
  // ignore attach steps since attachments are already in the report
311
326
  if (step.category === "attach") {
312
327
  return;
@@ -360,10 +375,12 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
360
375
  value: function () {
361
376
  var _onTestEnd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(test, result) {
362
377
  var _this = this,
378
+ _this$beforeHooksAtta,
379
+ _this$afterHooksAttac,
363
380
  _this$attachmentSteps2;
364
- var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, beforeHooksStack, afterHooksStack, attachmentSteps, i, attachment, attachmentStep;
365
- return _regeneratorRuntime().wrap(function _callee$(_context) {
366
- while (1) switch (_context.prev = _context.next) {
381
+ var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, beforeHooksStack, afterHooksStack, attachmentsInBeforeHooks, attachmentsInAfterHooks, hookAttachmentUuids, attachmentSteps, attachmentsInSteps, i, attachment, attachmentStep, hookAttachmentNames, onlyHooksAttachments, _iterator2, _step2, _loop;
382
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
383
+ while (1) switch (_context2.prev = _context2.next) {
367
384
  case 0:
368
385
  testUuid = this.allureResultsUuids.get(test.id); // We need to check parallelIndex first because pw introduced this field only in v1.30.0
369
386
  threadId = result.parallelIndex !== undefined ? result.parallelIndex : result.workerIndex;
@@ -409,22 +426,30 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
409
426
  testResult.status = (0, _utils.statusToAllureStats)(result.status, test.expectedStatus);
410
427
  testResult.stage = _allureJsCommons.Stage.FINISHED;
411
428
  });
429
+ attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : [];
430
+ attachmentsInAfterHooks = (_this$afterHooksAttac = this.afterHooksAttachmentsStack.get(test.id)) !== null && _this$afterHooksAttac !== void 0 ? _this$afterHooksAttac : [];
431
+ hookAttachmentUuids = new Set([].concat(_toConsumableArray(attachmentsInBeforeHooks), _toConsumableArray(attachmentsInAfterHooks)).map(function (hookStep) {
432
+ return (0, _utils.normalizeHookTitle)(hookStep.title);
433
+ }).filter(Boolean));
412
434
  attachmentSteps = (_this$attachmentSteps2 = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps2 !== void 0 ? _this$attachmentSteps2 : [];
435
+ attachmentsInSteps = result.attachments.filter(function (attachment) {
436
+ return !hookAttachmentUuids.has(attachment.name);
437
+ });
413
438
  i = 0;
414
- case 10:
415
- if (!(i < result.attachments.length)) {
416
- _context.next = 18;
439
+ case 14:
440
+ if (!(i < attachmentsInSteps.length)) {
441
+ _context2.next = 22;
417
442
  break;
418
443
  }
419
- attachment = result.attachments[i];
444
+ attachment = attachmentsInSteps[i];
420
445
  attachmentStep = attachmentSteps.length > i ? attachmentSteps[i] : undefined;
421
- _context.next = 15;
446
+ _context2.next = 19;
422
447
  return this.processAttachment(testUuid, attachmentStep, attachment);
423
- case 15:
448
+ case 19:
424
449
  i++;
425
- _context.next = 10;
450
+ _context2.next = 14;
426
451
  break;
427
- case 18:
452
+ case 22:
428
453
  if (result.stdout.length > 0) {
429
454
  this.allureRuntime.writeAttachment(testUuid, undefined, "stdout", Buffer.from((0, _sdk.stripAnsi)(result.stdout.join("")), "utf-8"), {
430
455
  contentType: _allureJsCommons.ContentType.TEXT
@@ -438,6 +463,67 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
438
463
 
439
464
  // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
440
465
  // in next iterations we need to implement the logic for every javascript integration
466
+ hookAttachmentNames = new Set([].concat(_toConsumableArray(attachmentsInBeforeHooks), _toConsumableArray(attachmentsInAfterHooks)).map(function (hookStep) {
467
+ return (0, _utils.normalizeHookTitle)(hookStep.title);
468
+ }).filter(Boolean));
469
+ onlyHooksAttachments = result.attachments.filter(function (att) {
470
+ return hookAttachmentNames.has(att.name);
471
+ });
472
+ _iterator2 = _createForOfIteratorHelper(onlyHooksAttachments);
473
+ _context2.prev = 27;
474
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
475
+ var attachment, matchingBeforeHookStep, matchingAfterHookStep, targetStack, hookStep, stepResult, fileName;
476
+ return _regeneratorRuntime().wrap(function _loop$(_context) {
477
+ while (1) switch (_context.prev = _context.next) {
478
+ case 0:
479
+ attachment = _step2.value;
480
+ matchingBeforeHookStep = attachmentsInBeforeHooks.find(function (step) {
481
+ return (0, _utils.normalizeHookTitle)(step.title) === attachment.name;
482
+ });
483
+ matchingAfterHookStep = attachmentsInAfterHooks.find(function (step) {
484
+ return (0, _utils.normalizeHookTitle)(step.title) === attachment.name;
485
+ });
486
+ targetStack = matchingBeforeHookStep ? beforeHooksStack : afterHooksStack;
487
+ hookStep = matchingBeforeHookStep || matchingAfterHookStep;
488
+ if (targetStack && hookStep) {
489
+ stepResult = targetStack === null || targetStack === void 0 ? void 0 : targetStack.findStepByUuid(hookStep === null || hookStep === void 0 ? void 0 : hookStep.uuid);
490
+ if (stepResult) {
491
+ fileName = targetStack.addAttachment(attachment, _this.allureRuntime.writer);
492
+ stepResult.attachments.push({
493
+ name: attachment.name,
494
+ type: attachment.contentType,
495
+ source: fileName
496
+ });
497
+ }
498
+ }
499
+ case 6:
500
+ case "end":
501
+ return _context.stop();
502
+ }
503
+ }, _loop);
504
+ });
505
+ _iterator2.s();
506
+ case 30:
507
+ if ((_step2 = _iterator2.n()).done) {
508
+ _context2.next = 34;
509
+ break;
510
+ }
511
+ return _context2.delegateYield(_loop(), "t0", 32);
512
+ case 32:
513
+ _context2.next = 30;
514
+ break;
515
+ case 34:
516
+ _context2.next = 39;
517
+ break;
518
+ case 36:
519
+ _context2.prev = 36;
520
+ _context2.t1 = _context2["catch"](27);
521
+ _iterator2.e(_context2.t1);
522
+ case 39:
523
+ _context2.prev = 39;
524
+ _iterator2.f();
525
+ return _context2.finish(39);
526
+ case 42:
441
527
  this.allureRuntime.updateTest(testUuid, function (testResult) {
442
528
  var mappedLabels = testResult.labels.reduce(function (acc, label) {
443
529
  if (!acc[label.name]) {
@@ -469,11 +555,11 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
469
555
  duration: result.duration
470
556
  });
471
557
  this.allureRuntime.writeTest(testUuid);
472
- case 23:
558
+ case 45:
473
559
  case "end":
474
- return _context.stop();
560
+ return _context2.stop();
475
561
  }
476
- }, _callee, this);
562
+ }, _callee, this, [[27, 36, 39, 42]]);
477
563
  }));
478
564
  function onTestEnd(_x, _x2) {
479
565
  return _onTestEnd.apply(this, arguments);
@@ -485,26 +571,26 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
485
571
  value: function () {
486
572
  var _addSkippedResults = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
487
573
  var _this2 = this;
488
- var unprocessedCases, _iterator2, _step2, testCase;
489
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
490
- while (1) switch (_context2.prev = _context2.next) {
574
+ var unprocessedCases, _iterator3, _step3, testCase;
575
+ return _regeneratorRuntime().wrap(function _callee2$(_context3) {
576
+ while (1) switch (_context3.prev = _context3.next) {
491
577
  case 0:
492
578
  unprocessedCases = this.suite.allTests().filter(function (_ref4) {
493
579
  var title = _ref4.title;
494
580
  var titleMetadata = (0, _sdk.extractMetadataFromString)(title);
495
581
  return !_this2.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
496
582
  });
497
- _iterator2 = _createForOfIteratorHelper(unprocessedCases);
498
- _context2.prev = 2;
499
- _iterator2.s();
583
+ _iterator3 = _createForOfIteratorHelper(unprocessedCases);
584
+ _context3.prev = 2;
585
+ _iterator3.s();
500
586
  case 4:
501
- if ((_step2 = _iterator2.n()).done) {
502
- _context2.next = 11;
587
+ if ((_step3 = _iterator3.n()).done) {
588
+ _context3.next = 11;
503
589
  break;
504
590
  }
505
- testCase = _step2.value;
591
+ testCase = _step3.value;
506
592
  this.onTestBegin(testCase);
507
- _context2.next = 9;
593
+ _context3.next = 9;
508
594
  return this.onTestEnd(testCase, {
509
595
  status: _allureJsCommons.Status.SKIPPED,
510
596
  attachments: [],
@@ -519,22 +605,22 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
519
605
  startTime: this.globalStartTime
520
606
  });
521
607
  case 9:
522
- _context2.next = 4;
608
+ _context3.next = 4;
523
609
  break;
524
610
  case 11:
525
- _context2.next = 16;
611
+ _context3.next = 16;
526
612
  break;
527
613
  case 13:
528
- _context2.prev = 13;
529
- _context2.t0 = _context2["catch"](2);
530
- _iterator2.e(_context2.t0);
614
+ _context3.prev = 13;
615
+ _context3.t0 = _context3["catch"](2);
616
+ _iterator3.e(_context3.t0);
531
617
  case 16:
532
- _context2.prev = 16;
533
- _iterator2.f();
534
- return _context2.finish(16);
618
+ _context3.prev = 16;
619
+ _iterator3.f();
620
+ return _context3.finish(16);
535
621
  case 19:
536
622
  case "end":
537
- return _context2.stop();
623
+ return _context3.stop();
538
624
  }
539
625
  }, _callee2, this, [[2, 13, 16, 19]]);
540
626
  }));
@@ -547,17 +633,17 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
547
633
  key: "onEnd",
548
634
  value: function () {
549
635
  var _onEnd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
550
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
551
- while (1) switch (_context3.prev = _context3.next) {
636
+ return _regeneratorRuntime().wrap(function _callee3$(_context4) {
637
+ while (1) switch (_context4.prev = _context4.next) {
552
638
  case 0:
553
- _context3.next = 2;
639
+ _context4.next = 2;
554
640
  return this.addSkippedResults();
555
641
  case 2:
556
642
  this.allureRuntime.writeEnvironmentInfo();
557
643
  this.allureRuntime.writeCategoriesDefinitions();
558
644
  case 4:
559
645
  case "end":
560
- return _context3.stop();
646
+ return _context4.stop();
561
647
  }
562
648
  }, _callee3, this);
563
649
  }));
@@ -591,36 +677,36 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
591
677
  value: function () {
592
678
  var _processAttachment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(testUuid, attachmentStepUuid, attachment) {
593
679
  var allureRuntimeMessage, message, parentUuid, contentType, pathWithoutEnd, actualBase64, expectedBase64, diffBase64, diffName;
594
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
595
- while (1) switch (_context4.prev = _context4.next) {
680
+ return _regeneratorRuntime().wrap(function _callee4$(_context5) {
681
+ while (1) switch (_context5.prev = _context5.next) {
596
682
  case 0:
597
683
  if (!(!attachment.body && !attachment.path)) {
598
- _context4.next = 2;
684
+ _context5.next = 2;
599
685
  break;
600
686
  }
601
- return _context4.abrupt("return");
687
+ return _context5.abrupt("return");
602
688
  case 2:
603
689
  allureRuntimeMessage = attachment.contentType === _reporter.ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
604
690
  if (!(allureRuntimeMessage && !attachment.body)) {
605
- _context4.next = 5;
691
+ _context5.next = 5;
606
692
  break;
607
693
  }
608
- return _context4.abrupt("return");
694
+ return _context5.abrupt("return");
609
695
  case 5:
610
696
  if (!allureRuntimeMessage) {
611
- _context4.next = 12;
697
+ _context5.next = 12;
612
698
  break;
613
699
  }
614
700
  message = JSON.parse(attachment.body.toString());
615
701
  if (!(message.type === "step_metadata")) {
616
- _context4.next = 10;
702
+ _context5.next = 10;
617
703
  break;
618
704
  }
619
705
  this.processStepMetadataMessage(attachmentStepUuid, message);
620
- return _context4.abrupt("return");
706
+ return _context5.abrupt("return");
621
707
  case 10:
622
708
  this.allureRuntime.applyRuntimeMessages(testUuid, [message]);
623
- return _context4.abrupt("return");
709
+ return _context5.abrupt("return");
624
710
  case 12:
625
711
  parentUuid = this.allureRuntime.startStep(testUuid, attachmentStepUuid, {
626
712
  name: attachment.name
@@ -631,52 +717,52 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
631
717
  this.allureRuntime.stopStep(parentUuid, undefined);
632
718
  }
633
719
  if (!attachment.body) {
634
- _context4.next = 18;
720
+ _context5.next = 18;
635
721
  break;
636
722
  }
637
723
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.body, {
638
724
  contentType: attachment.contentType
639
725
  });
640
- _context4.next = 24;
726
+ _context5.next = 24;
641
727
  break;
642
728
  case 18:
643
729
  if ((0, _nodeFs.existsSync)(attachment.path)) {
644
- _context4.next = 22;
730
+ _context5.next = 22;
645
731
  break;
646
732
  }
647
- return _context4.abrupt("return");
733
+ return _context5.abrupt("return");
648
734
  case 22:
649
735
  contentType = attachment.name === "trace" && attachment.contentType === "application/zip" ? "application/vnd.allure.playwright-trace" : attachment.contentType;
650
736
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.path, {
651
737
  contentType: contentType
652
738
  });
653
739
  case 24:
654
- if (attachment.name.match(diffEndRegexp)) {
655
- _context4.next = 26;
740
+ if (attachment.name.match(_utils.diffEndRegexp)) {
741
+ _context5.next = 26;
656
742
  break;
657
743
  }
658
- return _context4.abrupt("return");
744
+ return _context5.abrupt("return");
659
745
  case 26:
660
- pathWithoutEnd = attachment.path.replace(diffEndRegexp, "");
746
+ pathWithoutEnd = attachment.path.replace(_utils.diffEndRegexp, "");
661
747
  if (!this.processedDiffs.includes(pathWithoutEnd)) {
662
- _context4.next = 29;
748
+ _context5.next = 29;
663
749
  break;
664
750
  }
665
- return _context4.abrupt("return");
751
+ return _context5.abrupt("return");
666
752
  case 29:
667
- _context4.next = 31;
753
+ _context5.next = 31;
668
754
  return (0, _reporter.readImageAsBase64)("".concat(pathWithoutEnd, "-actual.png"));
669
755
  case 31:
670
- actualBase64 = _context4.sent;
671
- _context4.next = 34;
756
+ actualBase64 = _context5.sent;
757
+ _context5.next = 34;
672
758
  return (0, _reporter.readImageAsBase64)("".concat(pathWithoutEnd, "-expected.png"));
673
759
  case 34:
674
- expectedBase64 = _context4.sent;
675
- _context4.next = 37;
760
+ expectedBase64 = _context5.sent;
761
+ _context5.next = 37;
676
762
  return (0, _reporter.readImageAsBase64)("".concat(pathWithoutEnd, "-diff.png"));
677
763
  case 37:
678
- diffBase64 = _context4.sent;
679
- diffName = attachment.name.replace(diffEndRegexp, "");
764
+ diffBase64 = _context5.sent;
765
+ diffName = attachment.name.replace(_utils.diffEndRegexp, "");
680
766
  this.allureRuntime.writeAttachment(testUuid, undefined, diffName, Buffer.from(JSON.stringify({
681
767
  expected: expectedBase64,
682
768
  actual: actualBase64,
@@ -689,7 +775,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
689
775
  this.processedDiffs.push(pathWithoutEnd);
690
776
  case 41:
691
777
  case "end":
692
- return _context4.stop();
778
+ return _context5.stop();
693
779
  }
694
780
  }, _callee4, this);
695
781
  }));