allure-playwright 3.1.0 → 3.2.1

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
@@ -28,9 +28,9 @@ import path from "node:path";
28
28
  import process from "node:process";
29
29
  import { ContentType, LabelName, LinkType, Stage, Status } from "allure-js-commons";
30
30
  import { extractMetadataFromString, getMessageAndTraceFromError, getMetadataLabel, hasLabel, stripAnsi } from "allure-js-commons/sdk";
31
- import { ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE, ReporterRuntime, createDefaultWriter, escapeRegExp, formatLink, getEnvironmentLabels, getFrameworkLabel, getHostLabel, getLanguageLabel, getPackageLabel, getThreadLabel, md5, parseTestPlan, readImageAsBase64 } from "allure-js-commons/sdk/reporter";
31
+ import { ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE, ReporterRuntime, ShallowStepsStack, createDefaultWriter, createStepResult, escapeRegExp, formatLink, getEnvironmentLabels, getFrameworkLabel, getHostLabel, getLanguageLabel, getPackageLabel, getThreadLabel, getWorstTestStepResult, md5, parseTestPlan, readImageAsBase64 } from "allure-js-commons/sdk/reporter";
32
32
  import { allurePlaywrightLegacyApi } from "./legacy.js";
33
- import { statusToAllureStats } from "./utils.js";
33
+ import { AFTER_HOOKS_ROOT_STEP_TITLE, BEFORE_HOOKS_ROOT_STEP_TITLE, isAfterHookStep, isBeforeHookStep, isDescendantOfStepWithTitle, statusToAllureStats } from "./utils.js";
34
34
 
35
35
  // TODO: move to utils.ts
36
36
  var diffEndRegexp = /-((expected)|(diff)|(actual))\.png$/;
@@ -48,6 +48,8 @@ export var AllureReporter = /*#__PURE__*/function () {
48
48
  _defineProperty(this, "startedTestCasesTitlesCache", []);
49
49
  _defineProperty(this, "allureResultsUuids", new Map());
50
50
  _defineProperty(this, "attachmentSteps", new Map());
51
+ _defineProperty(this, "beforeHooksStepsStack", new Map());
52
+ _defineProperty(this, "afterHooksStepsStack", new Map());
51
53
  this.options = _objectSpread({
52
54
  suiteTitle: true,
53
55
  detail: true
@@ -252,10 +254,32 @@ export var AllureReporter = /*#__PURE__*/function () {
252
254
  if (_assertClassBrand(_AllureReporter_brand, this, _shouldIgnoreStep).call(this, step)) {
253
255
  return;
254
256
  }
255
- this.allureRuntime.startStep(testUuid, undefined, {
257
+ var baseStep = _objectSpread(_objectSpread({}, createStepResult()), {}, {
256
258
  name: step.title,
257
- start: step.startTime.getTime()
259
+ start: step.startTime.getTime(),
260
+ stage: Stage.RUNNING
258
261
  });
262
+ var isRootBeforeHook = step.title === BEFORE_HOOKS_ROOT_STEP_TITLE;
263
+ var isRootAfterHook = step.title === AFTER_HOOKS_ROOT_STEP_TITLE;
264
+ var isRootHook = isRootBeforeHook || isRootAfterHook;
265
+ var isBeforeHookDescendant = isBeforeHookStep(step);
266
+ var isAfterHookDescendant = isAfterHookStep(step);
267
+ if (isBeforeHookDescendant || isAfterHookDescendant) {
268
+ var stack = isBeforeHookDescendant ? this.beforeHooksStepsStack.get(test.id) : this.afterHooksStepsStack.get(test.id);
269
+ stack.startStep(baseStep);
270
+ return;
271
+ }
272
+ if (isRootHook) {
273
+ var _stack = new ShallowStepsStack();
274
+ _stack.startStep(baseStep);
275
+ if (isRootBeforeHook) {
276
+ this.beforeHooksStepsStack.set(test.id, _stack);
277
+ } else {
278
+ this.afterHooksStepsStack.set(test.id, _stack);
279
+ }
280
+ return;
281
+ }
282
+ this.allureRuntime.startStep(testUuid, undefined, baseStep);
259
283
  }
260
284
  }, {
261
285
  key: "onStepEnd",
@@ -269,12 +293,40 @@ export var AllureReporter = /*#__PURE__*/function () {
269
293
  return;
270
294
  }
271
295
  var testUuid = this.allureResultsUuids.get(test.id);
296
+ var isRootBeforeHook = step.title === BEFORE_HOOKS_ROOT_STEP_TITLE;
297
+ var isRootAfterHook = step.title === AFTER_HOOKS_ROOT_STEP_TITLE;
298
+ var isBeforeHookDescendant = isBeforeHookStep(step);
299
+ var isAfterHookDescendant = isAfterHookStep(step);
300
+ var isAfterHook = isRootAfterHook || isAfterHookDescendant;
301
+ var isHook = isRootBeforeHook || isRootAfterHook || isBeforeHookDescendant || isAfterHookDescendant;
302
+ if (isHook) {
303
+ var stack = isAfterHook ? this.afterHooksStepsStack.get(test.id) : this.beforeHooksStepsStack.get(test.id);
304
+ stack.updateStep(function (stepResult) {
305
+ var _getWorstTestStepResu;
306
+ var _ref2 = (_getWorstTestStepResu = getWorstTestStepResult(stepResult.steps)) !== null && _getWorstTestStepResu !== void 0 ? _getWorstTestStepResu : {},
307
+ _ref2$status = _ref2.status,
308
+ status = _ref2$status === void 0 ? Status.PASSED : _ref2$status;
309
+ stepResult.status = step.error ? Status.FAILED : status;
310
+ stepResult.stage = Stage.FINISHED;
311
+ if (step.error) {
312
+ stepResult.statusDetails = _objectSpread({}, getMessageAndTraceFromError(step.error));
313
+ }
314
+ });
315
+ stack.stopStep({
316
+ duration: step.duration
317
+ });
318
+ return;
319
+ }
272
320
  var currentStep = this.allureRuntime.currentStep(testUuid);
273
321
  if (!currentStep) {
274
322
  return;
275
323
  }
276
324
  this.allureRuntime.updateStep(currentStep, function (stepResult) {
277
- stepResult.status = step.error ? Status.FAILED : Status.PASSED;
325
+ var _getWorstTestStepResu2;
326
+ var _ref3 = (_getWorstTestStepResu2 = getWorstTestStepResult(stepResult.steps)) !== null && _getWorstTestStepResu2 !== void 0 ? _getWorstTestStepResu2 : {},
327
+ _ref3$status = _ref3.status,
328
+ status = _ref3$status === void 0 ? Status.PASSED : _ref3$status;
329
+ stepResult.status = step.error ? Status.FAILED : status;
278
330
  stepResult.stage = Stage.FINISHED;
279
331
  if (step.error) {
280
332
  stepResult.statusDetails = _objectSpread({}, getMessageAndTraceFromError(step.error));
@@ -290,7 +342,7 @@ export var AllureReporter = /*#__PURE__*/function () {
290
342
  var _onTestEnd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(test, result) {
291
343
  var _this = this,
292
344
  _this$attachmentSteps2;
293
- var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, attachmentSteps, i, attachment, attachmentStep;
345
+ var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, beforeHooksStack, afterHooksStack, attachmentSteps, i, attachment, attachmentStep;
294
346
  return _regeneratorRuntime().wrap(function _callee$(_context) {
295
347
  while (1) switch (_context.prev = _context.next) {
296
348
  case 0:
@@ -299,6 +351,8 @@ export var AllureReporter = /*#__PURE__*/function () {
299
351
  thread = "pid-".concat(process.pid, "-worker-").concat(threadId);
300
352
  error = result.error; // only apply default suites if not set by user
301
353
  _test$parent$titlePat = test.parent.titlePath(), _test$parent$titlePat2 = _toArray(_test$parent$titlePat), projectSuiteTitle = _test$parent$titlePat2[1], fileSuiteTitle = _test$parent$titlePat2[2], suiteTitles = _test$parent$titlePat2.slice(3);
354
+ beforeHooksStack = this.beforeHooksStepsStack.get(test.id);
355
+ afterHooksStack = this.afterHooksStepsStack.get(test.id);
302
356
  this.allureRuntime.updateTest(testUuid, function (testResult) {
303
357
  testResult.labels.push(getHostLabel());
304
358
  testResult.labels.push(getThreadLabel(thread));
@@ -338,20 +392,20 @@ export var AllureReporter = /*#__PURE__*/function () {
338
392
  });
339
393
  attachmentSteps = (_this$attachmentSteps2 = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps2 !== void 0 ? _this$attachmentSteps2 : [];
340
394
  i = 0;
341
- case 8:
395
+ case 10:
342
396
  if (!(i < result.attachments.length)) {
343
- _context.next = 16;
397
+ _context.next = 18;
344
398
  break;
345
399
  }
346
400
  attachment = result.attachments[i];
347
401
  attachmentStep = attachmentSteps.length > i ? attachmentSteps[i] : undefined;
348
- _context.next = 13;
402
+ _context.next = 15;
349
403
  return this.processAttachment(testUuid, attachmentStep, attachment);
350
- case 13:
404
+ case 15:
351
405
  i++;
352
- _context.next = 8;
406
+ _context.next = 10;
353
407
  break;
354
- case 16:
408
+ case 18:
355
409
  if (result.stdout.length > 0) {
356
410
  this.allureRuntime.writeAttachment(testUuid, undefined, "stdout", Buffer.from(stripAnsi(result.stdout.join("")), "utf-8"), {
357
411
  contentType: ContentType.TEXT
@@ -380,13 +434,23 @@ export var AllureReporter = /*#__PURE__*/function () {
380
434
  }
381
435
  return labelsGroup;
382
436
  });
437
+ if (beforeHooksStack) {
438
+ var _testResult$steps;
439
+ (_testResult$steps = testResult.steps).unshift.apply(_testResult$steps, _toConsumableArray(beforeHooksStack.steps));
440
+ _this.beforeHooksStepsStack["delete"](test.id);
441
+ }
442
+ if (afterHooksStack) {
443
+ var _testResult$steps2;
444
+ (_testResult$steps2 = testResult.steps).push.apply(_testResult$steps2, _toConsumableArray(afterHooksStack.steps));
445
+ _this.afterHooksStepsStack["delete"](test.id);
446
+ }
383
447
  testResult.labels = newLabels;
384
448
  });
385
449
  this.allureRuntime.stopTest(testUuid, {
386
450
  duration: result.duration
387
451
  });
388
452
  this.allureRuntime.writeTest(testUuid);
389
- case 21:
453
+ case 23:
390
454
  case "end":
391
455
  return _context.stop();
392
456
  }
@@ -406,8 +470,8 @@ export var AllureReporter = /*#__PURE__*/function () {
406
470
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
407
471
  while (1) switch (_context2.prev = _context2.next) {
408
472
  case 0:
409
- unprocessedCases = this.suite.allTests().filter(function (_ref2) {
410
- var title = _ref2.title;
473
+ unprocessedCases = this.suite.allTests().filter(function (_ref4) {
474
+ var title = _ref4.title;
411
475
  var titleMetadata = extractMetadataFromString(title);
412
476
  return !_this2.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
413
477
  });
@@ -488,11 +552,26 @@ export var AllureReporter = /*#__PURE__*/function () {
488
552
  value: function printsToStdio() {
489
553
  return false;
490
554
  }
555
+ }, {
556
+ key: "processStepMetadataMessage",
557
+ value: function processStepMetadataMessage(attachmentStepUuid, message) {
558
+ var _message$data = message.data,
559
+ name = _message$data.name,
560
+ _message$data$paramet = _message$data.parameters,
561
+ parameters = _message$data$paramet === void 0 ? [] : _message$data$paramet;
562
+ this.allureRuntime.updateStep(attachmentStepUuid, function (step) {
563
+ var _step$parameters;
564
+ if (name) {
565
+ step.name = name;
566
+ }
567
+ (_step$parameters = step.parameters).push.apply(_step$parameters, _toConsumableArray(parameters));
568
+ });
569
+ }
491
570
  }, {
492
571
  key: "processAttachment",
493
572
  value: function () {
494
573
  var _processAttachment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(testUuid, attachmentStepUuid, attachment) {
495
- var allureRuntimeMessage, message, parentUuid, pathWithoutEnd, actualBase64, expectedBase64, diffBase64, diffName;
574
+ var allureRuntimeMessage, message, parentUuid, contentType, pathWithoutEnd, actualBase64, expectedBase64, diffBase64, diffName;
496
575
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
497
576
  while (1) switch (_context4.prev = _context4.next) {
498
577
  case 0:
@@ -510,13 +589,20 @@ export var AllureReporter = /*#__PURE__*/function () {
510
589
  return _context4.abrupt("return");
511
590
  case 5:
512
591
  if (!allureRuntimeMessage) {
513
- _context4.next = 9;
592
+ _context4.next = 12;
593
+ break;
594
+ }
595
+ message = JSON.parse(attachment.body.toString());
596
+ if (!(message.type === "step_metadata")) {
597
+ _context4.next = 10;
514
598
  break;
515
599
  }
516
- message = JSON.parse(attachment.body.toString()); // TODO fix step metadata messages
600
+ this.processStepMetadataMessage(attachmentStepUuid, message);
601
+ return _context4.abrupt("return");
602
+ case 10:
517
603
  this.allureRuntime.applyRuntimeMessages(testUuid, [message]);
518
604
  return _context4.abrupt("return");
519
- case 9:
605
+ case 12:
520
606
  parentUuid = this.allureRuntime.startStep(testUuid, attachmentStepUuid, {
521
607
  name: attachment.name
522
608
  }); // only stop if step is created. Step may not be created only if test with specified uuid doesn't exists.
@@ -526,50 +612,50 @@ export var AllureReporter = /*#__PURE__*/function () {
526
612
  this.allureRuntime.stopStep(parentUuid, undefined);
527
613
  }
528
614
  if (!attachment.body) {
529
- _context4.next = 15;
615
+ _context4.next = 18;
530
616
  break;
531
617
  }
532
618
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.body, {
533
619
  contentType: attachment.contentType
534
620
  });
535
- _context4.next = 20;
621
+ _context4.next = 24;
536
622
  break;
537
- case 15:
623
+ case 18:
538
624
  if (existsSync(attachment.path)) {
539
- _context4.next = 19;
625
+ _context4.next = 22;
540
626
  break;
541
627
  }
542
628
  return _context4.abrupt("return");
543
- case 19:
544
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
629
+ case 22:
630
+ contentType = attachment.name === "trace" && attachment.contentType === "application/zip" ? "application/vnd.allure.playwright-trace" : attachment.contentType;
545
631
  this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.path, {
546
- contentType: attachment.contentType
632
+ contentType: contentType
547
633
  });
548
- case 20:
634
+ case 24:
549
635
  if (attachment.name.match(diffEndRegexp)) {
550
- _context4.next = 22;
636
+ _context4.next = 26;
551
637
  break;
552
638
  }
553
639
  return _context4.abrupt("return");
554
- case 22:
640
+ case 26:
555
641
  pathWithoutEnd = attachment.path.replace(diffEndRegexp, "");
556
642
  if (!this.processedDiffs.includes(pathWithoutEnd)) {
557
- _context4.next = 25;
643
+ _context4.next = 29;
558
644
  break;
559
645
  }
560
646
  return _context4.abrupt("return");
561
- case 25:
562
- _context4.next = 27;
647
+ case 29:
648
+ _context4.next = 31;
563
649
  return readImageAsBase64("".concat(pathWithoutEnd, "-actual.png"));
564
- case 27:
650
+ case 31:
565
651
  actualBase64 = _context4.sent;
566
- _context4.next = 30;
652
+ _context4.next = 34;
567
653
  return readImageAsBase64("".concat(pathWithoutEnd, "-expected.png"));
568
- case 30:
654
+ case 34:
569
655
  expectedBase64 = _context4.sent;
570
- _context4.next = 33;
656
+ _context4.next = 37;
571
657
  return readImageAsBase64("".concat(pathWithoutEnd, "-diff.png"));
572
- case 33:
658
+ case 37:
573
659
  diffBase64 = _context4.sent;
574
660
  diffName = attachment.name.replace(diffEndRegexp, "");
575
661
  this.allureRuntime.writeAttachment(testUuid, undefined, diffName, Buffer.from(JSON.stringify({
@@ -582,7 +668,7 @@ export var AllureReporter = /*#__PURE__*/function () {
582
668
  fileExtension: ".imagediff"
583
669
  });
584
670
  this.processedDiffs.push(pathWithoutEnd);
585
- case 37:
671
+ case 41:
586
672
  case "end":
587
673
  return _context4.stop();
588
674
  }
@@ -613,6 +699,11 @@ function _shouldIgnoreStep(step) {
613
699
  if (step.category === "pw:api" && step.title === "route.continue()") {
614
700
  return true;
615
701
  }
702
+
703
+ // playwright doesn't report this step
704
+ if (step.title === "Worker Cleanup" || isDescendantOfStepWithTitle(step, "Worker Cleanup")) {
705
+ return true;
706
+ }
616
707
  return false;
617
708
  }
618
709
  export var allure = allurePlaywrightLegacyApi;