allure-playwright 3.4.3 → 3.4.5

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
@@ -294,13 +294,30 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
294
294
  var parent = step.parent ? (_this$pwStepUuid$get = this.pwStepUuid.get(step.parent)) !== null && _this$pwStepUuid$get !== void 0 ? _this$pwStepUuid$get : null : null;
295
295
  var targets = (_this$attachmentTarge = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge !== void 0 ? _this$attachmentTarge : [];
296
296
  targets.push({
297
+ name: (0, _utils.normalizeAttachStepTitle)(step.title),
297
298
  stepUuid: parent !== null && parent !== void 0 ? parent : undefined
298
299
  });
299
300
  this.attachmentTargets.set(test.id, targets);
300
301
  return;
301
302
  }
302
303
  if (isHookStep) {
304
+ // Lazily initialize the hook stack if it doesn't exist (e.g., when detail: false and root hook was ignored)
303
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
+ }
304
321
  if (["test.attach", "attach"].includes(step.category)) {
305
322
  var _this$attachmentTarge2;
306
323
  var hookStepWithUuid;
@@ -318,6 +335,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
318
335
  stack.stopStep();
319
336
  var _targets = (_this$attachmentTarge2 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge2 !== void 0 ? _this$attachmentTarge2 : [];
320
337
  _targets.push({
338
+ name: (0, _utils.normalizeAttachStepTitle)(step.title),
321
339
  hookStep: hookStepWithUuid
322
340
  });
323
341
  this.attachmentTargets.set(test.id, _targets);
@@ -345,6 +363,33 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
345
363
  }, {
346
364
  key: "onStepEnd",
347
365
  value: function onStepEnd(test, _result, step) {
366
+ var isRootBeforeHook = step.title === _utils.BEFORE_HOOKS_ROOT_STEP_TITLE;
367
+ var isRootAfterHook = step.title === _utils.AFTER_HOOKS_ROOT_STEP_TITLE;
368
+ var isRootHook = isRootBeforeHook || isRootAfterHook;
369
+
370
+ // For root hooks, check if we have a lazily created stack that needs to be finalized
371
+ if (isRootHook) {
372
+ var stack = isRootAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
373
+
374
+ // If stack exists (was lazily created), finalize the root hook step
375
+ if (stack) {
376
+ stack.updateStep(function (stepResult) {
377
+ var _getWorstTestStepResu;
378
+ var _ref2 = (_getWorstTestStepResu = (0, _reporter.getWorstTestStepResult)(stepResult.steps)) !== null && _getWorstTestStepResu !== void 0 ? _getWorstTestStepResu : {},
379
+ _ref2$status = _ref2.status,
380
+ status = _ref2$status === void 0 ? _allureJsCommons.Status.PASSED : _ref2$status;
381
+ stepResult.status = step.error ? _allureJsCommons.Status.FAILED : status;
382
+ stepResult.stage = _allureJsCommons.Stage.FINISHED;
383
+ if (step.error) {
384
+ stepResult.statusDetails = _objectSpread({}, (0, _sdk.getMessageAndTraceFromError)(step.error));
385
+ }
386
+ });
387
+ stack.stopStep({
388
+ duration: step.duration
389
+ });
390
+ }
391
+ return;
392
+ }
348
393
  if (_assertClassBrand(_AllureReporter_brand, this, _shouldIgnoreStep).call(this, step)) {
349
394
  return;
350
395
  }
@@ -353,26 +398,29 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
353
398
  return;
354
399
  }
355
400
  var testUuid = this.allureResultsUuids.get(test.id);
356
- var isRootBeforeHook = step.title === _utils.BEFORE_HOOKS_ROOT_STEP_TITLE;
357
- var isRootAfterHook = step.title === _utils.AFTER_HOOKS_ROOT_STEP_TITLE;
358
401
  var isBeforeHookDescendant = (0, _utils.isBeforeHookStep)(step);
359
402
  var isAfterHookDescendant = (0, _utils.isAfterHookStep)(step);
360
- var isAfterHook = isRootAfterHook || isAfterHookDescendant;
361
- var isHook = isRootBeforeHook || isRootAfterHook || isBeforeHookDescendant || isAfterHookDescendant;
403
+ var isAfterHook = isAfterHookDescendant;
404
+ var isHook = isBeforeHookDescendant || isAfterHookDescendant;
362
405
  if (isHook) {
363
- var stack = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
364
- stack.updateStep(function (stepResult) {
365
- var _getWorstTestStepResu;
366
- var _ref2 = (_getWorstTestStepResu = (0, _reporter.getWorstTestStepResult)(stepResult.steps)) !== null && _getWorstTestStepResu !== void 0 ? _getWorstTestStepResu : {},
367
- _ref2$status = _ref2.status,
368
- status = _ref2$status === void 0 ? _allureJsCommons.Status.PASSED : _ref2$status;
406
+ var _stack2 = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
407
+
408
+ // Stack might not exist if root hook was ignored (e.g., detail: false) and no test.step was called inside it
409
+ if (!_stack2) {
410
+ return;
411
+ }
412
+ _stack2.updateStep(function (stepResult) {
413
+ var _getWorstTestStepResu2;
414
+ var _ref3 = (_getWorstTestStepResu2 = (0, _reporter.getWorstTestStepResult)(stepResult.steps)) !== null && _getWorstTestStepResu2 !== void 0 ? _getWorstTestStepResu2 : {},
415
+ _ref3$status = _ref3.status,
416
+ status = _ref3$status === void 0 ? _allureJsCommons.Status.PASSED : _ref3$status;
369
417
  stepResult.status = step.error ? _allureJsCommons.Status.FAILED : status;
370
418
  stepResult.stage = _allureJsCommons.Stage.FINISHED;
371
419
  if (step.error) {
372
420
  stepResult.statusDetails = _objectSpread({}, (0, _sdk.getMessageAndTraceFromError)(step.error));
373
421
  }
374
422
  });
375
- stack.stopStep({
423
+ _stack2.stopStep({
376
424
  duration: step.duration
377
425
  });
378
426
  return;
@@ -386,10 +434,10 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
386
434
  return;
387
435
  }
388
436
  this.allureRuntime.updateStep(stepUuid, function (stepResult) {
389
- var _getWorstTestStepResu2;
390
- var _ref3 = (_getWorstTestStepResu2 = (0, _reporter.getWorstTestStepResult)(stepResult.steps)) !== null && _getWorstTestStepResu2 !== void 0 ? _getWorstTestStepResu2 : {},
391
- _ref3$status = _ref3.status,
392
- status = _ref3$status === void 0 ? _allureJsCommons.Status.PASSED : _ref3$status;
437
+ var _getWorstTestStepResu3;
438
+ var _ref4 = (_getWorstTestStepResu3 = (0, _reporter.getWorstTestStepResult)(stepResult.steps)) !== null && _getWorstTestStepResu3 !== void 0 ? _getWorstTestStepResu3 : {},
439
+ _ref4$status = _ref4.status,
440
+ status = _ref4$status === void 0 ? _allureJsCommons.Status.PASSED : _ref4$status;
393
441
  stepResult.status = step.error ? _allureJsCommons.Status.FAILED : status;
394
442
  stepResult.stage = _allureJsCommons.Stage.FINISHED;
395
443
  if (step.error) {
@@ -407,7 +455,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
407
455
  var _this = this,
408
456
  _this$beforeHooksAtta,
409
457
  _this$attachmentTarge3;
410
- var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, beforeHooksStack, afterHooksStack, attachmentsInBeforeHooks, attachmentTargets, targetIndex, _iterator2, _step2, attachment, isRuntimeMessage, stepInfo, _stepInfo$hookStep$uu, _stepInfo$hookStep, stepUuid, hookStep, isBeforeHook, targetStack, stepResult, fileName, _t;
458
+ 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;
411
459
  return _regenerator().w(function (_context) {
412
460
  while (1) switch (_context.n) {
413
461
  case 0:
@@ -465,20 +513,40 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
465
513
  contentType: _allureJsCommons.ContentType.TEXT
466
514
  });
467
515
  }
468
- attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : [];
469
- attachmentTargets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
470
- targetIndex = 0;
471
- _iterator2 = _createForOfIteratorHelper(result.attachments);
516
+ attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : []; // FIFO
517
+ targets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
518
+ targetsByName = new Map();
519
+ _iterator2 = _createForOfIteratorHelper(targets);
520
+ try {
521
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
522
+ t = _step2.value;
523
+ q = (_targetsByName$get = targetsByName.get(t.name)) !== null && _targetsByName$get !== void 0 ? _targetsByName$get : [];
524
+ q.push(t);
525
+ targetsByName.set(t.name, q);
526
+ }
527
+ } catch (err) {
528
+ _iterator2.e(err);
529
+ } finally {
530
+ _iterator2.f();
531
+ }
532
+ takeByName = function takeByName(name) {
533
+ var target = targetsByName.get(name);
534
+ if (!target || target.length === 0) {
535
+ return undefined;
536
+ }
537
+ return target.shift();
538
+ };
539
+ _iterator3 = _createForOfIteratorHelper(result.attachments);
472
540
  _context.p = 1;
473
- _iterator2.s();
541
+ _iterator3.s();
474
542
  case 2:
475
- if ((_step2 = _iterator2.n()).done) {
543
+ if ((_step3 = _iterator3.n()).done) {
476
544
  _context.n = 9;
477
545
  break;
478
546
  }
479
- attachment = _step2.value;
547
+ attachment = _step3.value;
480
548
  isRuntimeMessage = attachment.contentType === _reporter.ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
481
- stepInfo = targetIndex < attachmentTargets.length ? attachmentTargets[targetIndex++] : undefined;
549
+ stepInfo = takeByName(attachment.name);
482
550
  if (!isRuntimeMessage) {
483
551
  _context.n = 4;
484
552
  break;
@@ -529,10 +597,10 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
529
597
  case 10:
530
598
  _context.p = 10;
531
599
  _t = _context.v;
532
- _iterator2.e(_t);
600
+ _iterator3.e(_t);
533
601
  case 11:
534
602
  _context.p = 11;
535
- _iterator2.f();
603
+ _iterator3.f();
536
604
  return _context.f(11);
537
605
  case 12:
538
606
  // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
@@ -568,6 +636,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
568
636
  duration: result.duration
569
637
  });
570
638
  this.allureRuntime.writeTest(testUuid);
639
+ this.attachmentTargets["delete"](test.id);
571
640
  case 13:
572
641
  return _context.a(2);
573
642
  }
@@ -583,24 +652,24 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
583
652
  value: function () {
584
653
  var _addSkippedResults = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
585
654
  var _this2 = this;
586
- var unprocessedCases, _iterator3, _step3, testCase, _t2;
655
+ var unprocessedCases, _iterator4, _step4, testCase, _t2;
587
656
  return _regenerator().w(function (_context2) {
588
657
  while (1) switch (_context2.n) {
589
658
  case 0:
590
- unprocessedCases = this.suite.allTests().filter(function (_ref4) {
591
- var title = _ref4.title;
659
+ unprocessedCases = this.suite.allTests().filter(function (_ref5) {
660
+ var title = _ref5.title;
592
661
  var titleMetadata = (0, _sdk.extractMetadataFromString)(title);
593
662
  return !_this2.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
594
663
  });
595
- _iterator3 = _createForOfIteratorHelper(unprocessedCases);
664
+ _iterator4 = _createForOfIteratorHelper(unprocessedCases);
596
665
  _context2.p = 1;
597
- _iterator3.s();
666
+ _iterator4.s();
598
667
  case 2:
599
- if ((_step3 = _iterator3.n()).done) {
668
+ if ((_step4 = _iterator4.n()).done) {
600
669
  _context2.n = 4;
601
670
  break;
602
671
  }
603
- testCase = _step3.value;
672
+ testCase = _step4.value;
604
673
  this.onTestBegin(testCase);
605
674
  _context2.n = 3;
606
675
  return this.onTestEnd(testCase, {
@@ -626,10 +695,10 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
626
695
  case 5:
627
696
  _context2.p = 5;
628
697
  _t2 = _context2.v;
629
- _iterator3.e(_t2);
698
+ _iterator4.e(_t2);
630
699
  case 6:
631
700
  _context2.p = 6;
632
- _iterator3.f();
701
+ _iterator4.f();
633
702
  return _context2.f(6);
634
703
  case 7:
635
704
  return _context2.a(2);
@@ -764,7 +833,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
764
833
  return _context6.a(2);
765
834
  case 9:
766
835
  fileExists = /*#__PURE__*/function () {
767
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(filePath) {
836
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(filePath) {
768
837
  return _regenerator().w(function (_context4) {
769
838
  while (1) switch (_context4.n) {
770
839
  case 0:
@@ -780,11 +849,11 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
780
849
  }, _callee4);
781
850
  }));
782
851
  return function fileExists(_x6) {
783
- return _ref5.apply(this, arguments);
852
+ return _ref6.apply(this, arguments);
784
853
  };
785
854
  }();
786
855
  readImageFromDirs = /*#__PURE__*/function () {
787
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(modifier) {
856
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(modifier) {
788
857
  var defaultPath, snapshotPath;
789
858
  return _regenerator().w(function (_context5) {
790
859
  while (1) switch (_context5.n) {
@@ -820,7 +889,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
820
889
  }, _callee5);
821
890
  }));
822
891
  return function readImageFromDirs(_x7) {
823
- return _ref6.apply(this, arguments);
892
+ return _ref7.apply(this, arguments);
824
893
  };
825
894
  }();
826
895
  _context6.n = 10;