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/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) {
@@ -50,7 +50,7 @@ export var AllureReporter = /*#__PURE__*/function () {
50
50
  _defineProperty(this, "processedDiffs", []);
51
51
  _defineProperty(this, "startedTestCasesTitlesCache", []);
52
52
  _defineProperty(this, "allureResultsUuids", new Map());
53
- _defineProperty(this, "attachmentSteps", new Map());
53
+ _defineProperty(this, "attachmentTargets", new Map());
54
54
  _defineProperty(this, "beforeHooksStepsStack", new Map());
55
55
  _defineProperty(this, "afterHooksStepsStack", new Map());
56
56
  _defineProperty(this, "beforeHooksAttachmentsStack", new Map());
@@ -254,7 +254,7 @@ export var AllureReporter = /*#__PURE__*/function () {
254
254
  }, {
255
255
  key: "onStepBegin",
256
256
  value: function onStepBegin(test, _result, step) {
257
- var _this$pwStepUuid$get;
257
+ var _this$pwStepUuid$get2;
258
258
  var isRootBeforeHook = step.title === BEFORE_HOOKS_ROOT_STEP_TITLE;
259
259
  var isRootAfterHook = step.title === AFTER_HOOKS_ROOT_STEP_TITLE;
260
260
  var isRootHook = isRootBeforeHook || isRootAfterHook;
@@ -262,12 +262,6 @@ export var AllureReporter = /*#__PURE__*/function () {
262
262
  var isAfterHookDescendant = isAfterHookStep(step);
263
263
  var isHookStep = isBeforeHookDescendant || isAfterHookDescendant;
264
264
  var testUuid = this.allureResultsUuids.get(test.id);
265
- if (["test.attach", "attach"].includes(step.category) && !isHookStep) {
266
- var _this$allureRuntime, _this$attachmentSteps;
267
- var currentStep = (_this$allureRuntime = this.allureRuntime) === null || _this$allureRuntime === void 0 ? void 0 : _this$allureRuntime.currentStep(testUuid);
268
- this.attachmentSteps.set(testUuid, [].concat(_toConsumableArray((_this$attachmentSteps = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps !== void 0 ? _this$attachmentSteps : []), [currentStep]));
269
- return;
270
- }
271
265
  if (_assertClassBrand(_AllureReporter_brand, this, _shouldIgnoreStep).call(this, step)) {
272
266
  return;
273
267
  }
@@ -277,20 +271,40 @@ export var AllureReporter = /*#__PURE__*/function () {
277
271
  stage: Stage.RUNNING,
278
272
  uuid: randomUuid()
279
273
  });
274
+ if (["test.attach", "attach"].includes(step.category) && !isHookStep) {
275
+ var _this$pwStepUuid$get, _this$attachmentTarge;
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
+ var targets = (_this$attachmentTarge = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge !== void 0 ? _this$attachmentTarge : [];
278
+ targets.push({
279
+ name: normalizeAttachStepTitle(step.title),
280
+ stepUuid: parent !== null && parent !== void 0 ? parent : undefined
281
+ });
282
+ this.attachmentTargets.set(test.id, targets);
283
+ return;
284
+ }
280
285
  if (isHookStep) {
281
286
  var stack = isBeforeHookDescendant ? this.beforeHooksStepsStack.get(test.id) : this.afterHooksStepsStack.get(test.id);
282
287
  if (["test.attach", "attach"].includes(step.category)) {
288
+ var _this$attachmentTarge2;
289
+ var hookStepWithUuid;
283
290
  stack.startStep(baseStep);
284
291
  var attachStack = isBeforeHookDescendant ? this.beforeHooksAttachmentsStack : this.afterHooksAttachmentsStack;
285
292
  stack.updateStep(function (stepResult) {
286
293
  var _attachStack$get;
294
+ hookStepWithUuid = _objectSpread(_objectSpread({}, step), {}, {
295
+ uuid: stepResult.uuid
296
+ });
287
297
  stepResult.name = normalizeHookTitle(stepResult.name);
288
298
  stepResult.stage = Stage.FINISHED;
289
- attachStack.set(test.id, [].concat(_toConsumableArray((_attachStack$get = attachStack.get(test.id)) !== null && _attachStack$get !== void 0 ? _attachStack$get : []), [_objectSpread(_objectSpread({}, step), {}, {
290
- uuid: stepResult.uuid
291
- })]));
299
+ attachStack.set(test.id, [].concat(_toConsumableArray((_attachStack$get = attachStack.get(test.id)) !== null && _attachStack$get !== void 0 ? _attachStack$get : []), [hookStepWithUuid]));
292
300
  });
293
301
  stack.stopStep();
302
+ var _targets = (_this$attachmentTarge2 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge2 !== void 0 ? _this$attachmentTarge2 : [];
303
+ _targets.push({
304
+ name: normalizeAttachStepTitle(step.title),
305
+ hookStep: hookStepWithUuid
306
+ });
307
+ this.attachmentTargets.set(test.id, _targets);
294
308
  return;
295
309
  }
296
310
  stack.startStep(baseStep);
@@ -306,7 +320,7 @@ export var AllureReporter = /*#__PURE__*/function () {
306
320
  }
307
321
  return;
308
322
  }
309
- var parentUuid = step.parent ? (_this$pwStepUuid$get = this.pwStepUuid.get(step.parent)) !== null && _this$pwStepUuid$get !== void 0 ? _this$pwStepUuid$get : null : null;
323
+ var parentUuid = step.parent ? (_this$pwStepUuid$get2 = this.pwStepUuid.get(step.parent)) !== null && _this$pwStepUuid$get2 !== void 0 ? _this$pwStepUuid$get2 : null : null;
310
324
  var createdUuid = this.allureRuntime.startStep(testUuid, parentUuid, baseStep);
311
325
  if (createdUuid) {
312
326
  this.pwStepUuid.set(step, createdUuid);
@@ -376,9 +390,8 @@ export var AllureReporter = /*#__PURE__*/function () {
376
390
  var _onTestEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(test, result) {
377
391
  var _this = this,
378
392
  _this$beforeHooksAtta,
379
- _this$afterHooksAttac,
380
- _this$attachmentSteps2;
381
- 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;
393
+ _this$attachmentTarge3;
394
+ 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;
382
395
  return _regenerator().w(function (_context) {
383
396
  while (1) switch (_context.n) {
384
397
  case 0:
@@ -426,142 +439,108 @@ export var AllureReporter = /*#__PURE__*/function () {
426
439
  testResult.status = statusToAllureStats(result.status, test.expectedStatus);
427
440
  testResult.stage = Stage.FINISHED;
428
441
  });
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
- attachmentSteps = (_this$attachmentSteps2 = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps2 !== void 0 ? _this$attachmentSteps2 : [];
432
- attachmentToStepMap = new Map();
433
- attachmentIndex = 0;
434
- _iterator2 = _createForOfIteratorHelper(attachmentsInBeforeHooks);
442
+ if (result.stdout.length > 0) {
443
+ this.allureRuntime.writeAttachment(testUuid, undefined, "stdout", Buffer.from(stripAnsi(result.stdout.join("")), "utf-8"), {
444
+ contentType: ContentType.TEXT
445
+ });
446
+ }
447
+ if (result.stderr.length > 0) {
448
+ this.allureRuntime.writeAttachment(testUuid, undefined, "stderr", Buffer.from(stripAnsi(result.stderr.join("")), "utf-8"), {
449
+ contentType: ContentType.TEXT
450
+ });
451
+ }
452
+ attachmentsInBeforeHooks = (_this$beforeHooksAtta = this.beforeHooksAttachmentsStack.get(test.id)) !== null && _this$beforeHooksAtta !== void 0 ? _this$beforeHooksAtta : []; // FIFO
453
+ targets = (_this$attachmentTarge3 = this.attachmentTargets.get(test.id)) !== null && _this$attachmentTarge3 !== void 0 ? _this$attachmentTarge3 : [];
454
+ targetsByName = new Map();
455
+ _iterator2 = _createForOfIteratorHelper(targets);
435
456
  try {
436
457
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
437
- _hookStep = _step2.value;
438
- attachmentToStepMap.set(attachmentIndex, {
439
- stepUuid: _hookStep.uuid,
440
- isHook: true,
441
- hookStep: _hookStep
442
- });
443
- attachmentIndex++;
458
+ t = _step2.value;
459
+ q = (_targetsByName$get = targetsByName.get(t.name)) !== null && _targetsByName$get !== void 0 ? _targetsByName$get : [];
460
+ q.push(t);
461
+ targetsByName.set(t.name, q);
444
462
  }
445
463
  } catch (err) {
446
464
  _iterator2.e(err);
447
465
  } finally {
448
466
  _iterator2.f();
449
467
  }
450
- _iterator3 = _createForOfIteratorHelper(attachmentSteps);
451
- try {
452
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
453
- stepUuid = _step3.value;
454
- attachmentToStepMap.set(attachmentIndex, {
455
- stepUuid: stepUuid,
456
- isHook: false
457
- });
458
- attachmentIndex++;
468
+ takeByName = function takeByName(name) {
469
+ var target = targetsByName.get(name);
470
+ if (!target || target.length === 0) {
471
+ return undefined;
459
472
  }
460
- } catch (err) {
461
- _iterator3.e(err);
462
- } finally {
463
- _iterator3.f();
464
- }
465
- _iterator4 = _createForOfIteratorHelper(attachmentsInAfterHooks);
466
- try {
467
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
468
- _hookStep2 = _step4.value;
469
- attachmentToStepMap.set(attachmentIndex, {
470
- stepUuid: _hookStep2.uuid,
471
- isHook: true,
472
- hookStep: _hookStep2
473
- });
474
- attachmentIndex++;
475
- }
476
- } catch (err) {
477
- _iterator4.e(err);
478
- } finally {
479
- _iterator4.f();
480
- }
481
- i = 0;
482
- case 1:
483
- if (!(i < result.attachments.length)) {
484
- _context.n = 6;
485
- break;
486
- }
487
- attachment = result.attachments[i];
488
- stepInfo = attachmentToStepMap.get(i);
489
- if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.isHook)) {
490
- _context.n = 2;
473
+ return target.shift();
474
+ };
475
+ _iterator3 = _createForOfIteratorHelper(result.attachments);
476
+ _context.p = 1;
477
+ _iterator3.s();
478
+ case 2:
479
+ if ((_step3 = _iterator3.n()).done) {
480
+ _context.n = 9;
491
481
  break;
492
482
  }
493
- return _context.a(3, 5);
494
- case 2:
495
- if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
483
+ attachment = _step3.value;
484
+ isRuntimeMessage = attachment.contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
485
+ stepInfo = takeByName(attachment.name);
486
+ if (!isRuntimeMessage) {
496
487
  _context.n = 4;
497
488
  break;
498
489
  }
490
+ 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;
499
491
  _context.n = 3;
500
- return this.processAttachment(testUuid, stepInfo.stepUuid, attachment);
492
+ return this.processAttachment(testUuid, stepUuid, attachment);
501
493
  case 3:
502
- _context.n = 5;
503
- break;
494
+ return _context.a(3, 8);
504
495
  case 4:
505
- _context.n = 5;
506
- return this.processAttachment(testUuid, undefined, attachment);
507
- case 5:
508
- i++;
509
- _context.n = 1;
510
- break;
511
- case 6:
512
- if (result.stdout.length > 0) {
513
- this.allureRuntime.writeAttachment(testUuid, undefined, "stdout", Buffer.from(stripAnsi(result.stdout.join("")), "utf-8"), {
514
- contentType: ContentType.TEXT
515
- });
516
- }
517
- if (result.stderr.length > 0) {
518
- this.allureRuntime.writeAttachment(testUuid, undefined, "stderr", Buffer.from(stripAnsi(result.stderr.join("")), "utf-8"), {
519
- contentType: ContentType.TEXT
520
- });
521
- }
522
-
523
- // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
524
- // in next iterations we need to implement the logic for every javascript integration
525
- _i = 0;
526
- case 7:
527
- if (!(_i < result.attachments.length)) {
528
- _context.n = 11;
496
+ if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.hookStep)) {
497
+ _context.n = 5;
529
498
  break;
530
499
  }
531
- _attachment = result.attachments[_i];
532
- _stepInfo = attachmentToStepMap.get(_i);
533
- if (!(_stepInfo !== null && _stepInfo !== void 0 && _stepInfo.isHook && _stepInfo.hookStep)) {
534
- _context.n = 10;
535
- break;
536
- }
537
- hookStep = _stepInfo.hookStep;
500
+ hookStep = stepInfo.hookStep;
538
501
  isBeforeHook = attachmentsInBeforeHooks.includes(hookStep);
539
502
  targetStack = isBeforeHook ? beforeHooksStack : afterHooksStack;
540
- if (!(_attachment.contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE)) {
541
- _context.n = 9;
542
- break;
543
- }
544
- _context.n = 8;
545
- return this.processAttachment(testUuid, hookStep.uuid, _attachment);
546
- case 8:
547
- return _context.a(3, 10);
548
- case 9:
549
503
  if (targetStack) {
550
504
  stepResult = targetStack.findStepByUuid(hookStep.uuid);
551
505
  if (stepResult) {
552
- fileName = targetStack.addAttachment(_attachment, this.allureRuntime.writer);
506
+ fileName = targetStack.addAttachment(attachment, this.allureRuntime.writer);
553
507
  stepResult.attachments.push({
554
- name: _attachment.name,
555
- type: _attachment.contentType,
508
+ name: attachment.name,
509
+ type: attachment.contentType,
556
510
  source: fileName
557
511
  });
558
512
  }
559
513
  }
560
- case 10:
561
- _i++;
562
- _context.n = 7;
514
+ return _context.a(3, 8);
515
+ case 5:
516
+ if (!(stepInfo !== null && stepInfo !== void 0 && stepInfo.stepUuid)) {
517
+ _context.n = 7;
518
+ break;
519
+ }
520
+ _context.n = 6;
521
+ return this.processAttachment(testUuid, stepInfo.stepUuid, attachment);
522
+ case 6:
523
+ return _context.a(3, 8);
524
+ case 7:
525
+ _context.n = 8;
526
+ return this.processAttachment(testUuid, undefined, attachment);
527
+ case 8:
528
+ _context.n = 2;
563
529
  break;
530
+ case 9:
531
+ _context.n = 11;
532
+ break;
533
+ case 10:
534
+ _context.p = 10;
535
+ _t = _context.v;
536
+ _iterator3.e(_t);
564
537
  case 11:
538
+ _context.p = 11;
539
+ _iterator3.f();
540
+ return _context.f(11);
541
+ case 12:
542
+ // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
543
+ // in next iterations we need to implement the logic for every javascript integration
565
544
  this.allureRuntime.updateTest(testUuid, function (testResult) {
566
545
  var mappedLabels = testResult.labels.reduce(function (acc, label) {
567
546
  if (!acc[label.name]) {
@@ -593,10 +572,11 @@ export var AllureReporter = /*#__PURE__*/function () {
593
572
  duration: result.duration
594
573
  });
595
574
  this.allureRuntime.writeTest(testUuid);
596
- case 12:
575
+ this.attachmentTargets["delete"](test.id);
576
+ case 13:
597
577
  return _context.a(2);
598
578
  }
599
- }, _callee, this);
579
+ }, _callee, this, [[1, 10, 11, 12]]);
600
580
  }));
601
581
  function onTestEnd(_x, _x2) {
602
582
  return _onTestEnd.apply(this, arguments);
@@ -608,7 +588,7 @@ export var AllureReporter = /*#__PURE__*/function () {
608
588
  value: function () {
609
589
  var _addSkippedResults = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
610
590
  var _this2 = this;
611
- var unprocessedCases, _iterator5, _step5, testCase, _t;
591
+ var unprocessedCases, _iterator4, _step4, testCase, _t2;
612
592
  return _regenerator().w(function (_context2) {
613
593
  while (1) switch (_context2.n) {
614
594
  case 0:
@@ -617,15 +597,15 @@ export var AllureReporter = /*#__PURE__*/function () {
617
597
  var titleMetadata = extractMetadataFromString(title);
618
598
  return !_this2.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
619
599
  });
620
- _iterator5 = _createForOfIteratorHelper(unprocessedCases);
600
+ _iterator4 = _createForOfIteratorHelper(unprocessedCases);
621
601
  _context2.p = 1;
622
- _iterator5.s();
602
+ _iterator4.s();
623
603
  case 2:
624
- if ((_step5 = _iterator5.n()).done) {
604
+ if ((_step4 = _iterator4.n()).done) {
625
605
  _context2.n = 4;
626
606
  break;
627
607
  }
628
- testCase = _step5.value;
608
+ testCase = _step4.value;
629
609
  this.onTestBegin(testCase);
630
610
  _context2.n = 3;
631
611
  return this.onTestEnd(testCase, {
@@ -650,11 +630,11 @@ export var AllureReporter = /*#__PURE__*/function () {
650
630
  break;
651
631
  case 5:
652
632
  _context2.p = 5;
653
- _t = _context2.v;
654
- _iterator5.e(_t);
633
+ _t2 = _context2.v;
634
+ _iterator4.e(_t2);
655
635
  case 6:
656
636
  _context2.p = 6;
657
- _iterator5.f();
637
+ _iterator4.f();
658
638
  return _context2.f(6);
659
639
  case 7:
660
640
  return _context2.a(2);
@@ -893,7 +873,7 @@ export var AllureReporter = /*#__PURE__*/function () {
893
873
  * @deprecated for removal, import functions directly from "allure-js-commons".
894
874
  */
895
875
  function _shouldIgnoreStep(step) {
896
- if (!this.options.detail && step.category !== "test.step") {
876
+ if (!this.options.detail && !["test.step", "attach", "test.attach"].includes(step.category)) {
897
877
  return true;
898
878
  }
899
879