allure-playwright 3.4.2 → 3.4.4

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
@@ -68,7 +68,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
68
68
  _defineProperty(this, "processedDiffs", []);
69
69
  _defineProperty(this, "startedTestCasesTitlesCache", []);
70
70
  _defineProperty(this, "allureResultsUuids", new Map());
71
- _defineProperty(this, "attachmentSteps", new Map());
71
+ _defineProperty(this, "attachmentTargets", new Map());
72
72
  _defineProperty(this, "beforeHooksStepsStack", new Map());
73
73
  _defineProperty(this, "afterHooksStepsStack", new Map());
74
74
  _defineProperty(this, "beforeHooksAttachmentsStack", new Map());
@@ -272,7 +272,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
272
272
  }, {
273
273
  key: "onStepBegin",
274
274
  value: function onStepBegin(test, _result, step) {
275
- var _this$pwStepUuid$get;
275
+ var _this$pwStepUuid$get2;
276
276
  var isRootBeforeHook = step.title === _utils.BEFORE_HOOKS_ROOT_STEP_TITLE;
277
277
  var isRootAfterHook = step.title === _utils.AFTER_HOOKS_ROOT_STEP_TITLE;
278
278
  var isRootHook = isRootBeforeHook || isRootAfterHook;
@@ -280,12 +280,6 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
280
280
  var isAfterHookDescendant = (0, _utils.isAfterHookStep)(step);
281
281
  var isHookStep = isBeforeHookDescendant || isAfterHookDescendant;
282
282
  var testUuid = this.allureResultsUuids.get(test.id);
283
- if (["test.attach", "attach"].includes(step.category) && !isHookStep) {
284
- var _this$allureRuntime, _this$attachmentSteps;
285
- var currentStep = (_this$allureRuntime = this.allureRuntime) === null || _this$allureRuntime === void 0 ? void 0 : _this$allureRuntime.currentStep(testUuid);
286
- this.attachmentSteps.set(testUuid, [].concat(_toConsumableArray((_this$attachmentSteps = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps !== void 0 ? _this$attachmentSteps : []), [currentStep]));
287
- return;
288
- }
289
283
  if (_assertClassBrand(_AllureReporter_brand, this, _shouldIgnoreStep).call(this, step)) {
290
284
  return;
291
285
  }
@@ -295,20 +289,40 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
295
289
  stage: _allureJsCommons.Stage.RUNNING,
296
290
  uuid: (0, _reporter.randomUuid)()
297
291
  });
292
+ if (["test.attach", "attach"].includes(step.category) && !isHookStep) {
293
+ var _this$pwStepUuid$get, _this$attachmentTarge;
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
+ var targets = (_this$attachmentTarge = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge !== void 0 ? _this$attachmentTarge : [];
296
+ targets.push({
297
+ name: (0, _utils.normalizeAttachStepTitle)(step.title),
298
+ stepUuid: parent !== null && parent !== void 0 ? parent : undefined
299
+ });
300
+ this.attachmentTargets.set(test.id, targets);
301
+ return;
302
+ }
298
303
  if (isHookStep) {
299
304
  var stack = isBeforeHookDescendant ? this.beforeHooksStepsStack.get(test.id) : this.afterHooksStepsStack.get(test.id);
300
305
  if (["test.attach", "attach"].includes(step.category)) {
306
+ var _this$attachmentTarge2;
307
+ var hookStepWithUuid;
301
308
  stack.startStep(baseStep);
302
309
  var attachStack = isBeforeHookDescendant ? this.beforeHooksAttachmentsStack : this.afterHooksAttachmentsStack;
303
310
  stack.updateStep(function (stepResult) {
304
311
  var _attachStack$get;
312
+ hookStepWithUuid = _objectSpread(_objectSpread({}, step), {}, {
313
+ uuid: stepResult.uuid
314
+ });
305
315
  stepResult.name = (0, _utils.normalizeHookTitle)(stepResult.name);
306
316
  stepResult.stage = _allureJsCommons.Stage.FINISHED;
307
- attachStack.set(test.id, [].concat(_toConsumableArray((_attachStack$get = attachStack.get(test.id)) !== null && _attachStack$get !== void 0 ? _attachStack$get : []), [_objectSpread(_objectSpread({}, step), {}, {
308
- uuid: stepResult.uuid
309
- })]));
317
+ attachStack.set(test.id, [].concat(_toConsumableArray((_attachStack$get = attachStack.get(test.id)) !== null && _attachStack$get !== void 0 ? _attachStack$get : []), [hookStepWithUuid]));
310
318
  });
311
319
  stack.stopStep();
320
+ var _targets = (_this$attachmentTarge2 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge2 !== void 0 ? _this$attachmentTarge2 : [];
321
+ _targets.push({
322
+ name: (0, _utils.normalizeAttachStepTitle)(step.title),
323
+ hookStep: hookStepWithUuid
324
+ });
325
+ this.attachmentTargets.set(test.id, _targets);
312
326
  return;
313
327
  }
314
328
  stack.startStep(baseStep);
@@ -324,7 +338,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
324
338
  }
325
339
  return;
326
340
  }
327
- var parentUuid = step.parent ? (_this$pwStepUuid$get = this.pwStepUuid.get(step.parent)) !== null && _this$pwStepUuid$get !== void 0 ? _this$pwStepUuid$get : null : null;
341
+ var parentUuid = step.parent ? (_this$pwStepUuid$get2 = this.pwStepUuid.get(step.parent)) !== null && _this$pwStepUuid$get2 !== void 0 ? _this$pwStepUuid$get2 : null : null;
328
342
  var createdUuid = this.allureRuntime.startStep(testUuid, parentUuid, baseStep);
329
343
  if (createdUuid) {
330
344
  this.pwStepUuid.set(step, createdUuid);
@@ -394,9 +408,8 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
394
408
  var _onTestEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(test, result) {
395
409
  var _this = this,
396
410
  _this$beforeHooksAtta,
397
- _this$afterHooksAttac,
398
- _this$attachmentSteps2;
399
- var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, beforeHooksStack, afterHooksStack, attachmentsInBeforeHooks, attachmentsInAfterHooks, attachmentSteps, attachmentToStepMap, attachmentIndex, _iterator2, _step2, _hookStep, _iterator3, _step3, stepUuid, _iterator4, _step4, _hookStep2, i, attachment, stepInfo, _i, _attachment, _stepInfo, hookStep, isBeforeHook, targetStack, stepResult, fileName;
411
+ _this$attachmentTarge3;
412
+ 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;
400
413
  return _regenerator().w(function (_context) {
401
414
  while (1) switch (_context.n) {
402
415
  case 0:
@@ -444,142 +457,108 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
444
457
  testResult.status = (0, _utils.statusToAllureStats)(result.status, test.expectedStatus);
445
458
  testResult.stage = _allureJsCommons.Stage.FINISHED;
446
459
  });
447
- attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : [];
448
- attachmentsInAfterHooks = (_this$afterHooksAttac = this.afterHooksAttachmentsStack.get(test.id)) !== null && _this$afterHooksAttac !== void 0 ? _this$afterHooksAttac : [];
449
- attachmentSteps = (_this$attachmentSteps2 = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps2 !== void 0 ? _this$attachmentSteps2 : [];
450
- attachmentToStepMap = new Map();
451
- attachmentIndex = 0;
452
- _iterator2 = _createForOfIteratorHelper(attachmentsInBeforeHooks);
460
+ if (result.stdout.length > 0) {
461
+ this.allureRuntime.writeAttachment(testUuid, undefined, "stdout", Buffer.from((0, _sdk.stripAnsi)(result.stdout.join("")), "utf-8"), {
462
+ contentType: _allureJsCommons.ContentType.TEXT
463
+ });
464
+ }
465
+ if (result.stderr.length > 0) {
466
+ this.allureRuntime.writeAttachment(testUuid, undefined, "stderr", Buffer.from((0, _sdk.stripAnsi)(result.stderr.join("")), "utf-8"), {
467
+ contentType: _allureJsCommons.ContentType.TEXT
468
+ });
469
+ }
470
+ attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : []; // FIFO
471
+ targets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
472
+ targetsByName = new Map();
473
+ _iterator2 = _createForOfIteratorHelper(targets);
453
474
  try {
454
475
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
455
- _hookStep = _step2.value;
456
- attachmentToStepMap.set(attachmentIndex, {
457
- stepUuid: _hookStep.uuid,
458
- isHook: true,
459
- hookStep: _hookStep
460
- });
461
- attachmentIndex++;
476
+ t = _step2.value;
477
+ q = (_targetsByName$get = targetsByName.get(t.name)) !== null && _targetsByName$get !== void 0 ? _targetsByName$get : [];
478
+ q.push(t);
479
+ targetsByName.set(t.name, q);
462
480
  }
463
481
  } catch (err) {
464
482
  _iterator2.e(err);
465
483
  } finally {
466
484
  _iterator2.f();
467
485
  }
468
- _iterator3 = _createForOfIteratorHelper(attachmentSteps);
469
- try {
470
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
471
- stepUuid = _step3.value;
472
- attachmentToStepMap.set(attachmentIndex, {
473
- stepUuid: stepUuid,
474
- isHook: false
475
- });
476
- attachmentIndex++;
486
+ takeByName = function takeByName(name) {
487
+ var target = targetsByName.get(name);
488
+ if (!target || target.length === 0) {
489
+ return undefined;
477
490
  }
478
- } catch (err) {
479
- _iterator3.e(err);
480
- } finally {
481
- _iterator3.f();
482
- }
483
- _iterator4 = _createForOfIteratorHelper(attachmentsInAfterHooks);
484
- try {
485
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
486
- _hookStep2 = _step4.value;
487
- attachmentToStepMap.set(attachmentIndex, {
488
- stepUuid: _hookStep2.uuid,
489
- isHook: true,
490
- hookStep: _hookStep2
491
- });
492
- attachmentIndex++;
493
- }
494
- } catch (err) {
495
- _iterator4.e(err);
496
- } finally {
497
- _iterator4.f();
498
- }
499
- i = 0;
500
- case 1:
501
- if (!(i < result.attachments.length)) {
502
- _context.n = 6;
503
- break;
504
- }
505
- attachment = result.attachments[i];
506
- stepInfo = attachmentToStepMap.get(i);
507
- if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.isHook)) {
508
- _context.n = 2;
491
+ return target.shift();
492
+ };
493
+ _iterator3 = _createForOfIteratorHelper(result.attachments);
494
+ _context.p = 1;
495
+ _iterator3.s();
496
+ case 2:
497
+ if ((_step3 = _iterator3.n()).done) {
498
+ _context.n = 9;
509
499
  break;
510
500
  }
511
- return _context.a(3, 5);
512
- case 2:
513
- if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
501
+ attachment = _step3.value;
502
+ isRuntimeMessage = attachment.contentType === _reporter.ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
503
+ stepInfo = takeByName(attachment.name);
504
+ if (!isRuntimeMessage) {
514
505
  _context.n = 4;
515
506
  break;
516
507
  }
508
+ 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;
517
509
  _context.n = 3;
518
- return this.processAttachment(testUuid, stepInfo.stepUuid, attachment);
510
+ return this.processAttachment(testUuid, stepUuid, attachment);
519
511
  case 3:
520
- _context.n = 5;
521
- break;
512
+ return _context.a(3, 8);
522
513
  case 4:
523
- _context.n = 5;
524
- return this.processAttachment(testUuid, undefined, attachment);
525
- case 5:
526
- i++;
527
- _context.n = 1;
528
- break;
529
- case 6:
530
- if (result.stdout.length > 0) {
531
- this.allureRuntime.writeAttachment(testUuid, undefined, "stdout", Buffer.from((0, _sdk.stripAnsi)(result.stdout.join("")), "utf-8"), {
532
- contentType: _allureJsCommons.ContentType.TEXT
533
- });
534
- }
535
- if (result.stderr.length > 0) {
536
- this.allureRuntime.writeAttachment(testUuid, undefined, "stderr", Buffer.from((0, _sdk.stripAnsi)(result.stderr.join("")), "utf-8"), {
537
- contentType: _allureJsCommons.ContentType.TEXT
538
- });
539
- }
540
-
541
- // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
542
- // in next iterations we need to implement the logic for every javascript integration
543
- _i = 0;
544
- case 7:
545
- if (!(_i < result.attachments.length)) {
546
- _context.n = 11;
514
+ if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep)) {
515
+ _context.n = 5;
547
516
  break;
548
517
  }
549
- _attachment = result.attachments[_i];
550
- _stepInfo = attachmentToStepMap.get(_i);
551
- if (!(_stepInfo !== null && _stepInfo !== void 0 && _stepInfo.isHook && _stepInfo.hookStep)) {
552
- _context.n = 10;
553
- break;
554
- }
555
- hookStep = _stepInfo.hookStep;
518
+ hookStep = stepInfo.hookStep;
556
519
  isBeforeHook = attachmentsInBeforeHooks.includes(hookStep);
557
520
  targetStack = isBeforeHook ? beforeHooksStack : afterHooksStack;
558
- if (!(_attachment.contentType === _reporter.ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE)) {
559
- _context.n = 9;
560
- break;
561
- }
562
- _context.n = 8;
563
- return this.processAttachment(testUuid, hookStep.uuid, _attachment);
564
- case 8:
565
- return _context.a(3, 10);
566
- case 9:
567
521
  if (targetStack) {
568
522
  stepResult = targetStack.findStepByUuid(hookStep.uuid);
569
523
  if (stepResult) {
570
- fileName = targetStack.addAttachment(_attachment, this.allureRuntime.writer);
524
+ fileName = targetStack.addAttachment(attachment, this.allureRuntime.writer);
571
525
  stepResult.attachments.push({
572
- name: _attachment.name,
573
- type: _attachment.contentType,
526
+ name: attachment.name,
527
+ type: attachment.contentType,
574
528
  source: fileName
575
529
  });
576
530
  }
577
531
  }
578
- case 10:
579
- _i++;
580
- _context.n = 7;
532
+ return _context.a(3, 8);
533
+ case 5:
534
+ if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
535
+ _context.n = 7;
536
+ break;
537
+ }
538
+ _context.n = 6;
539
+ return this.processAttachment(testUuid, stepInfo.stepUuid, attachment);
540
+ case 6:
541
+ return _context.a(3, 8);
542
+ case 7:
543
+ _context.n = 8;
544
+ return this.processAttachment(testUuid, undefined, attachment);
545
+ case 8:
546
+ _context.n = 2;
581
547
  break;
548
+ case 9:
549
+ _context.n = 11;
550
+ break;
551
+ case 10:
552
+ _context.p = 10;
553
+ _t = _context.v;
554
+ _iterator3.e(_t);
582
555
  case 11:
556
+ _context.p = 11;
557
+ _iterator3.f();
558
+ return _context.f(11);
559
+ case 12:
560
+ // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
561
+ // in next iterations we need to implement the logic for every javascript integration
583
562
  this.allureRuntime.updateTest(testUuid, function (testResult) {
584
563
  var mappedLabels = testResult.labels.reduce(function (acc, label) {
585
564
  if (!acc[label.name]) {
@@ -611,10 +590,11 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
611
590
  duration: result.duration
612
591
  });
613
592
  this.allureRuntime.writeTest(testUuid);
614
- case 12:
593
+ this.attachmentTargets["delete"](test.id);
594
+ case 13:
615
595
  return _context.a(2);
616
596
  }
617
- }, _callee, this);
597
+ }, _callee, this, [[1, 10, 11, 12]]);
618
598
  }));
619
599
  function onTestEnd(_x, _x2) {
620
600
  return _onTestEnd.apply(this, arguments);
@@ -626,7 +606,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
626
606
  value: function () {
627
607
  var _addSkippedResults = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
628
608
  var _this2 = this;
629
- var unprocessedCases, _iterator5, _step5, testCase, _t;
609
+ var unprocessedCases, _iterator4, _step4, testCase, _t2;
630
610
  return _regenerator().w(function (_context2) {
631
611
  while (1) switch (_context2.n) {
632
612
  case 0:
@@ -635,15 +615,15 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
635
615
  var titleMetadata = (0, _sdk.extractMetadataFromString)(title);
636
616
  return !_this2.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
637
617
  });
638
- _iterator5 = _createForOfIteratorHelper(unprocessedCases);
618
+ _iterator4 = _createForOfIteratorHelper(unprocessedCases);
639
619
  _context2.p = 1;
640
- _iterator5.s();
620
+ _iterator4.s();
641
621
  case 2:
642
- if ((_step5 = _iterator5.n()).done) {
622
+ if ((_step4 = _iterator4.n()).done) {
643
623
  _context2.n = 4;
644
624
  break;
645
625
  }
646
- testCase = _step5.value;
626
+ testCase = _step4.value;
647
627
  this.onTestBegin(testCase);
648
628
  _context2.n = 3;
649
629
  return this.onTestEnd(testCase, {
@@ -668,11 +648,11 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
668
648
  break;
669
649
  case 5:
670
650
  _context2.p = 5;
671
- _t = _context2.v;
672
- _iterator5.e(_t);
651
+ _t2 = _context2.v;
652
+ _iterator4.e(_t2);
673
653
  case 6:
674
654
  _context2.p = 6;
675
- _iterator5.f();
655
+ _iterator4.f();
676
656
  return _context2.f(6);
677
657
  case 7:
678
658
  return _context2.a(2);
@@ -910,7 +890,7 @@ var AllureReporter = exports.AllureReporter = /*#__PURE__*/function () {
910
890
  * @deprecated for removal, import functions directly from "allure-js-commons".
911
891
  */
912
892
  function _shouldIgnoreStep(step) {
913
- if (!this.options.detail && step.category !== "test.step") {
893
+ if (!this.options.detail && !["test.step", "attach", "test.attach"].includes(step.category)) {
914
894
  return true;
915
895
  }
916
896