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/esm/index.js CHANGED
@@ -34,7 +34,7 @@ import { ContentType, LabelName, LinkType, Stage, Status } from "allure-js-commo
34
34
  import { extractMetadataFromString, getMessageAndTraceFromError, getMetadataLabel, hasLabel, stripAnsi } from "allure-js-commons/sdk";
35
35
  import { ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE, ReporterRuntime, ShallowStepsStack, createDefaultWriter, createStepResult, escapeRegExp, formatLink, getEnvironmentLabels, getFrameworkLabel, getHostLabel, getLanguageLabel, getPackageLabel, getThreadLabel, getWorstTestStepResult, md5, parseTestPlan, randomUuid, readImageAsBase64 } from "allure-js-commons/sdk/reporter";
36
36
  import { allurePlaywrightLegacyApi } from "./legacy.js";
37
- import { AFTER_HOOKS_ROOT_STEP_TITLE, BEFORE_HOOKS_ROOT_STEP_TITLE, diffEndRegexp, isAfterHookStep, isBeforeHookStep, isDescendantOfStepWithTitle, normalizeHookTitle, statusToAllureStats } from "./utils.js";
37
+ import { AFTER_HOOKS_ROOT_STEP_TITLE, BEFORE_HOOKS_ROOT_STEP_TITLE, diffEndRegexp, isAfterHookStep, isBeforeHookStep, isDescendantOfStepWithTitle, normalizeAttachStepTitle, normalizeHookTitle, statusToAllureStats } from "./utils.js";
38
38
  var _AllureReporter_brand = /*#__PURE__*/new WeakSet();
39
39
  export var AllureReporter = /*#__PURE__*/function () {
40
40
  function AllureReporter(config) {
@@ -276,13 +276,30 @@ export var AllureReporter = /*#__PURE__*/function () {
276
276
  var parent = step.parent ? (_this$pwStepUuid$get = this.pwStepUuid.get(step.parent)) !== null && _this$pwStepUuid$get !== void 0 ? _this$pwStepUuid$get : null : null;
277
277
  var targets = (_this$attachmentTarge = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge !== void 0 ? _this$attachmentTarge : [];
278
278
  targets.push({
279
+ name: normalizeAttachStepTitle(step.title),
279
280
  stepUuid: parent !== null && parent !== void 0 ? parent : undefined
280
281
  });
281
282
  this.attachmentTargets.set(test.id, targets);
282
283
  return;
283
284
  }
284
285
  if (isHookStep) {
286
+ // Lazily initialize the hook stack if it doesn't exist (e.g., when detail: false and root hook was ignored)
285
287
  var stack = isBeforeHookDescendant ? this.beforeHooksStepsStack.get(test.id) : this.afterHooksStepsStack.get(test.id);
288
+ if (!stack) {
289
+ stack = new ShallowStepsStack();
290
+ var rootHookStep = _objectSpread(_objectSpread({}, createStepResult()), {}, {
291
+ name: isBeforeHookDescendant ? BEFORE_HOOKS_ROOT_STEP_TITLE : AFTER_HOOKS_ROOT_STEP_TITLE,
292
+ start: step.startTime.getTime(),
293
+ stage: Stage.RUNNING,
294
+ uuid: randomUuid()
295
+ });
296
+ stack.startStep(rootHookStep);
297
+ if (isBeforeHookDescendant) {
298
+ this.beforeHooksStepsStack.set(test.id, stack);
299
+ } else {
300
+ this.afterHooksStepsStack.set(test.id, stack);
301
+ }
302
+ }
286
303
  if (["test.attach", "attach"].includes(step.category)) {
287
304
  var _this$attachmentTarge2;
288
305
  var hookStepWithUuid;
@@ -300,6 +317,7 @@ export var AllureReporter = /*#__PURE__*/function () {
300
317
  stack.stopStep();
301
318
  var _targets = (_this$attachmentTarge2 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge2 !== void 0 ? _this$attachmentTarge2 : [];
302
319
  _targets.push({
320
+ name: normalizeAttachStepTitle(step.title),
303
321
  hookStep: hookStepWithUuid
304
322
  });
305
323
  this.attachmentTargets.set(test.id, _targets);
@@ -327,6 +345,33 @@ export var AllureReporter = /*#__PURE__*/function () {
327
345
  }, {
328
346
  key: "onStepEnd",
329
347
  value: function onStepEnd(test, _result, step) {
348
+ var isRootBeforeHook = step.title === BEFORE_HOOKS_ROOT_STEP_TITLE;
349
+ var isRootAfterHook = step.title === AFTER_HOOKS_ROOT_STEP_TITLE;
350
+ var isRootHook = isRootBeforeHook || isRootAfterHook;
351
+
352
+ // For root hooks, check if we have a lazily created stack that needs to be finalized
353
+ if (isRootHook) {
354
+ var stack = isRootAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
355
+
356
+ // If stack exists (was lazily created), finalize the root hook step
357
+ if (stack) {
358
+ stack.updateStep(function (stepResult) {
359
+ var _getWorstTestStepResu;
360
+ var _ref2 = (_getWorstTestStepResu = getWorstTestStepResult(stepResult.steps)) !== null && _getWorstTestStepResu !== void 0 ? _getWorstTestStepResu : {},
361
+ _ref2$status = _ref2.status,
362
+ status = _ref2$status === void 0 ? Status.PASSED : _ref2$status;
363
+ stepResult.status = step.error ? Status.FAILED : status;
364
+ stepResult.stage = Stage.FINISHED;
365
+ if (step.error) {
366
+ stepResult.statusDetails = _objectSpread({}, getMessageAndTraceFromError(step.error));
367
+ }
368
+ });
369
+ stack.stopStep({
370
+ duration: step.duration
371
+ });
372
+ }
373
+ return;
374
+ }
330
375
  if (_assertClassBrand(_AllureReporter_brand, this, _shouldIgnoreStep).call(this, step)) {
331
376
  return;
332
377
  }
@@ -335,26 +380,29 @@ export var AllureReporter = /*#__PURE__*/function () {
335
380
  return;
336
381
  }
337
382
  var testUuid = this.allureResultsUuids.get(test.id);
338
- var isRootBeforeHook = step.title === BEFORE_HOOKS_ROOT_STEP_TITLE;
339
- var isRootAfterHook = step.title === AFTER_HOOKS_ROOT_STEP_TITLE;
340
383
  var isBeforeHookDescendant = isBeforeHookStep(step);
341
384
  var isAfterHookDescendant = isAfterHookStep(step);
342
- var isAfterHook = isRootAfterHook || isAfterHookDescendant;
343
- var isHook = isRootBeforeHook || isRootAfterHook || isBeforeHookDescendant || isAfterHookDescendant;
385
+ var isAfterHook = isAfterHookDescendant;
386
+ var isHook = isBeforeHookDescendant || isAfterHookDescendant;
344
387
  if (isHook) {
345
- var stack = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
346
- stack.updateStep(function (stepResult) {
347
- var _getWorstTestStepResu;
348
- var _ref2 = (_getWorstTestStepResu = getWorstTestStepResult(stepResult.steps)) !== null && _getWorstTestStepResu !== void 0 ? _getWorstTestStepResu : {},
349
- _ref2$status = _ref2.status,
350
- status = _ref2$status === void 0 ? Status.PASSED : _ref2$status;
388
+ var _stack2 = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
389
+
390
+ // Stack might not exist if root hook was ignored (e.g., detail: false) and no test.step was called inside it
391
+ if (!_stack2) {
392
+ return;
393
+ }
394
+ _stack2.updateStep(function (stepResult) {
395
+ var _getWorstTestStepResu2;
396
+ var _ref3 = (_getWorstTestStepResu2 = getWorstTestStepResult(stepResult.steps)) !== null && _getWorstTestStepResu2 !== void 0 ? _getWorstTestStepResu2 : {},
397
+ _ref3$status = _ref3.status,
398
+ status = _ref3$status === void 0 ? Status.PASSED : _ref3$status;
351
399
  stepResult.status = step.error ? Status.FAILED : status;
352
400
  stepResult.stage = Stage.FINISHED;
353
401
  if (step.error) {
354
402
  stepResult.statusDetails = _objectSpread({}, getMessageAndTraceFromError(step.error));
355
403
  }
356
404
  });
357
- stack.stopStep({
405
+ _stack2.stopStep({
358
406
  duration: step.duration
359
407
  });
360
408
  return;
@@ -368,10 +416,10 @@ export var AllureReporter = /*#__PURE__*/function () {
368
416
  return;
369
417
  }
370
418
  this.allureRuntime.updateStep(stepUuid, function (stepResult) {
371
- var _getWorstTestStepResu2;
372
- var _ref3 = (_getWorstTestStepResu2 = getWorstTestStepResult(stepResult.steps)) !== null && _getWorstTestStepResu2 !== void 0 ? _getWorstTestStepResu2 : {},
373
- _ref3$status = _ref3.status,
374
- status = _ref3$status === void 0 ? Status.PASSED : _ref3$status;
419
+ var _getWorstTestStepResu3;
420
+ var _ref4 = (_getWorstTestStepResu3 = getWorstTestStepResult(stepResult.steps)) !== null && _getWorstTestStepResu3 !== void 0 ? _getWorstTestStepResu3 : {},
421
+ _ref4$status = _ref4.status,
422
+ status = _ref4$status === void 0 ? Status.PASSED : _ref4$status;
375
423
  stepResult.status = step.error ? Status.FAILED : status;
376
424
  stepResult.stage = Stage.FINISHED;
377
425
  if (step.error) {
@@ -389,7 +437,7 @@ export var AllureReporter = /*#__PURE__*/function () {
389
437
  var _this = this,
390
438
  _this$beforeHooksAtta,
391
439
  _this$attachmentTarge3;
392
- 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;
440
+ 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;
393
441
  return _regenerator().w(function (_context) {
394
442
  while (1) switch (_context.n) {
395
443
  case 0:
@@ -447,20 +495,40 @@ export var AllureReporter = /*#__PURE__*/function () {
447
495
  contentType: ContentType.TEXT
448
496
  });
449
497
  }
450
- attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : [];
451
- attachmentTargets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
452
- targetIndex = 0;
453
- _iterator2 = _createForOfIteratorHelper(result.attachments);
498
+ attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : []; // FIFO
499
+ targets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
500
+ targetsByName = new Map();
501
+ _iterator2 = _createForOfIteratorHelper(targets);
502
+ try {
503
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
504
+ t = _step2.value;
505
+ q = (_targetsByName$get = targetsByName.get(t.name)) !== null && _targetsByName$get !== void 0 ? _targetsByName$get : [];
506
+ q.push(t);
507
+ targetsByName.set(t.name, q);
508
+ }
509
+ } catch (err) {
510
+ _iterator2.e(err);
511
+ } finally {
512
+ _iterator2.f();
513
+ }
514
+ takeByName = function takeByName(name) {
515
+ var target = targetsByName.get(name);
516
+ if (!target || target.length === 0) {
517
+ return undefined;
518
+ }
519
+ return target.shift();
520
+ };
521
+ _iterator3 = _createForOfIteratorHelper(result.attachments);
454
522
  _context.p = 1;
455
- _iterator2.s();
523
+ _iterator3.s();
456
524
  case 2:
457
- if ((_step2 = _iterator2.n()).done) {
525
+ if ((_step3 = _iterator3.n()).done) {
458
526
  _context.n = 9;
459
527
  break;
460
528
  }
461
- attachment = _step2.value;
529
+ attachment = _step3.value;
462
530
  isRuntimeMessage = attachment.contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
463
- stepInfo = targetIndex < attachmentTargets.length ? attachmentTargets[targetIndex++] : undefined;
531
+ stepInfo = takeByName(attachment.name);
464
532
  if (!isRuntimeMessage) {
465
533
  _context.n = 4;
466
534
  break;
@@ -511,10 +579,10 @@ export var AllureReporter = /*#__PURE__*/function () {
511
579
  case 10:
512
580
  _context.p = 10;
513
581
  _t = _context.v;
514
- _iterator2.e(_t);
582
+ _iterator3.e(_t);
515
583
  case 11:
516
584
  _context.p = 11;
517
- _iterator2.f();
585
+ _iterator3.f();
518
586
  return _context.f(11);
519
587
  case 12:
520
588
  // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
@@ -550,6 +618,7 @@ export var AllureReporter = /*#__PURE__*/function () {
550
618
  duration: result.duration
551
619
  });
552
620
  this.allureRuntime.writeTest(testUuid);
621
+ this.attachmentTargets["delete"](test.id);
553
622
  case 13:
554
623
  return _context.a(2);
555
624
  }
@@ -565,24 +634,24 @@ export var AllureReporter = /*#__PURE__*/function () {
565
634
  value: function () {
566
635
  var _addSkippedResults = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
567
636
  var _this2 = this;
568
- var unprocessedCases, _iterator3, _step3, testCase, _t2;
637
+ var unprocessedCases, _iterator4, _step4, testCase, _t2;
569
638
  return _regenerator().w(function (_context2) {
570
639
  while (1) switch (_context2.n) {
571
640
  case 0:
572
- unprocessedCases = this.suite.allTests().filter(function (_ref4) {
573
- var title = _ref4.title;
641
+ unprocessedCases = this.suite.allTests().filter(function (_ref5) {
642
+ var title = _ref5.title;
574
643
  var titleMetadata = extractMetadataFromString(title);
575
644
  return !_this2.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
576
645
  });
577
- _iterator3 = _createForOfIteratorHelper(unprocessedCases);
646
+ _iterator4 = _createForOfIteratorHelper(unprocessedCases);
578
647
  _context2.p = 1;
579
- _iterator3.s();
648
+ _iterator4.s();
580
649
  case 2:
581
- if ((_step3 = _iterator3.n()).done) {
650
+ if ((_step4 = _iterator4.n()).done) {
582
651
  _context2.n = 4;
583
652
  break;
584
653
  }
585
- testCase = _step3.value;
654
+ testCase = _step4.value;
586
655
  this.onTestBegin(testCase);
587
656
  _context2.n = 3;
588
657
  return this.onTestEnd(testCase, {
@@ -608,10 +677,10 @@ export var AllureReporter = /*#__PURE__*/function () {
608
677
  case 5:
609
678
  _context2.p = 5;
610
679
  _t2 = _context2.v;
611
- _iterator3.e(_t2);
680
+ _iterator4.e(_t2);
612
681
  case 6:
613
682
  _context2.p = 6;
614
- _iterator3.f();
683
+ _iterator4.f();
615
684
  return _context2.f(6);
616
685
  case 7:
617
686
  return _context2.a(2);
@@ -746,7 +815,7 @@ export var AllureReporter = /*#__PURE__*/function () {
746
815
  return _context6.a(2);
747
816
  case 9:
748
817
  fileExists = /*#__PURE__*/function () {
749
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(filePath) {
818
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(filePath) {
750
819
  return _regenerator().w(function (_context4) {
751
820
  while (1) switch (_context4.n) {
752
821
  case 0:
@@ -762,11 +831,11 @@ export var AllureReporter = /*#__PURE__*/function () {
762
831
  }, _callee4);
763
832
  }));
764
833
  return function fileExists(_x6) {
765
- return _ref5.apply(this, arguments);
834
+ return _ref6.apply(this, arguments);
766
835
  };
767
836
  }();
768
837
  readImageFromDirs = /*#__PURE__*/function () {
769
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(modifier) {
838
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(modifier) {
770
839
  var defaultPath, snapshotPath;
771
840
  return _regenerator().w(function (_context5) {
772
841
  while (1) switch (_context5.n) {
@@ -802,7 +871,7 @@ export var AllureReporter = /*#__PURE__*/function () {
802
871
  }, _callee5);
803
872
  }));
804
873
  return function readImageFromDirs(_x7) {
805
- return _ref6.apply(this, arguments);
874
+ return _ref7.apply(this, arguments);
806
875
  };
807
876
  }();
808
877
  _context6.n = 10;