allure-playwright 2.15.1 → 3.0.0-beta.10

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.
Files changed (47) hide show
  1. package/README.md +64 -303
  2. package/dist/cjs/autoconfig.js +6 -0
  3. package/dist/cjs/autoconfig.js.map +1 -0
  4. package/dist/cjs/index.js +595 -0
  5. package/dist/cjs/index.js.map +1 -0
  6. package/dist/cjs/legacy.js +178 -0
  7. package/dist/cjs/legacy.js.map +1 -0
  8. package/dist/cjs/model.js +2 -0
  9. package/dist/cjs/model.js.map +1 -0
  10. package/dist/cjs/package.json +3 -0
  11. package/dist/cjs/runtime.js +127 -0
  12. package/dist/cjs/runtime.js.map +1 -0
  13. package/dist/cjs/testplan.js +20 -0
  14. package/dist/cjs/testplan.js.map +1 -0
  15. package/dist/cjs/utils.js +20 -0
  16. package/dist/cjs/utils.js.map +1 -0
  17. package/dist/esm/autoconfig.js +4 -0
  18. package/dist/esm/autoconfig.js.map +1 -0
  19. package/dist/esm/index.js +578 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/legacy.js +170 -0
  22. package/dist/esm/legacy.js.map +1 -0
  23. package/dist/esm/model.js +2 -0
  24. package/dist/esm/model.js.map +1 -0
  25. package/dist/esm/package.json +3 -0
  26. package/dist/esm/runtime.js +121 -0
  27. package/dist/esm/runtime.js.map +1 -0
  28. package/dist/esm/testplan.js +14 -0
  29. package/dist/esm/testplan.js.map +1 -0
  30. package/dist/esm/utils.js +14 -0
  31. package/dist/esm/utils.js.map +1 -0
  32. package/dist/types/autoconfig.d.ts +1 -0
  33. package/dist/types/index.d.ts +58 -0
  34. package/dist/types/legacy.d.ts +40 -0
  35. package/dist/types/model.d.ts +5 -0
  36. package/dist/types/runtime.d.ts +11 -0
  37. package/dist/types/utils.d.ts +3 -0
  38. package/package.json +57 -21
  39. package/dist/helpers.d.ts +0 -30
  40. package/dist/helpers.js +0 -112
  41. package/dist/helpers.js.map +0 -1
  42. package/dist/index.d.ts +0 -41
  43. package/dist/index.js +0 -316
  44. package/dist/index.js.map +0 -1
  45. package/dist/testplan.js +0 -16
  46. package/dist/testplan.js.map +0 -1
  47. /package/dist/{testplan.d.ts → types/testplan.d.ts} +0 -0
@@ -0,0 +1,578 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
3
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
4
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
5
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
6
+ function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
9
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
10
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
13
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
18
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
19
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
20
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
22
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ import { existsSync } from "node:fs";
24
+ import os from "node:os";
25
+ import path from "node:path";
26
+ import process from "node:process";
27
+ import { ContentType, LabelName, Stage, Status } from "allure-js-commons";
28
+ import { extractMetadataFromString, getMessageAndTraceFromError, hasLabel, stripAnsi } from "allure-js-commons/sdk";
29
+ import { ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE, ReporterRuntime, createDefaultWriter, escapeRegExp, getEnvironmentLabels, md5, parseTestPlan, readImageAsBase64 } from "allure-js-commons/sdk/reporter";
30
+ import { allurePlaywrightLegacyApi } from "./legacy.js";
31
+ import { statusToAllureStats } from "./utils.js";
32
+
33
+ // TODO: move to utils.ts
34
+ var diffEndRegexp = /-((expected)|(diff)|(actual))\.png$/;
35
+ export var AllureReporter = /*#__PURE__*/function () {
36
+ function AllureReporter(config) {
37
+ _classCallCheck(this, AllureReporter);
38
+ _defineProperty(this, "config", void 0);
39
+ _defineProperty(this, "suite", void 0);
40
+ _defineProperty(this, "options", void 0);
41
+ _defineProperty(this, "allureRuntime", void 0);
42
+ _defineProperty(this, "hostname", process.env.ALLURE_HOST_NAME || os.hostname());
43
+ _defineProperty(this, "globalStartTime", new Date());
44
+ _defineProperty(this, "processedDiffs", []);
45
+ _defineProperty(this, "startedTestCasesTitlesCache", []);
46
+ _defineProperty(this, "allureResultsUuids", new Map());
47
+ _defineProperty(this, "attachmentSteps", new Map());
48
+ this.options = _objectSpread({
49
+ suiteTitle: true,
50
+ detail: true
51
+ }, config);
52
+ }
53
+ return _createClass(AllureReporter, [{
54
+ key: "onConfigure",
55
+ value: function onConfigure(config) {
56
+ this.config = config;
57
+ var testPlan = parseTestPlan();
58
+ if (!testPlan) {
59
+ return;
60
+ }
61
+
62
+ // @ts-ignore
63
+ var configElement = config[Object.getOwnPropertySymbols(config)[0]];
64
+ if (!configElement) {
65
+ return;
66
+ }
67
+ var testsWithSelectors = testPlan.tests.filter(function (test) {
68
+ return test.selector;
69
+ });
70
+ var v1ReporterTests = [];
71
+ var v2ReporterTests = [];
72
+ var cliArgs = [];
73
+ testsWithSelectors.forEach(function (test) {
74
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
75
+ if (!/#/.test(test.selector)) {
76
+ v2ReporterTests.push(test);
77
+ return;
78
+ }
79
+ v1ReporterTests.push(test);
80
+ });
81
+ if (v2ReporterTests.length) {
82
+ // we need to cut off column because playwright works only with line number
83
+ var v2SelectorsArgs = v2ReporterTests
84
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
85
+ .map(function (test) {
86
+ return test.selector.replace(/:\d+$/, "");
87
+ }).map(function (selector) {
88
+ return escapeRegExp(selector);
89
+ });
90
+ cliArgs.push.apply(cliArgs, _toConsumableArray(v2SelectorsArgs));
91
+ }
92
+ if (v1ReporterTests.length) {
93
+ var v1SelectorsArgs = v1ReporterTests
94
+ // we can filter tests only by absolute path, so we need to cut off test name
95
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
96
+ .map(function (test) {
97
+ return test.selector.split("#")[0];
98
+ }).map(function (selector) {
99
+ return escapeRegExp(selector);
100
+ });
101
+ cliArgs.push.apply(cliArgs, _toConsumableArray(v1SelectorsArgs));
102
+ }
103
+ if (!cliArgs.length) {
104
+ return;
105
+ }
106
+ configElement.cliArgs = cliArgs.map(function (selector) {
107
+ return "/".concat(selector);
108
+ });
109
+ }
110
+ }, {
111
+ key: "onError",
112
+ value: function onError() {}
113
+ }, {
114
+ key: "onExit",
115
+ value: function onExit() {}
116
+ }, {
117
+ key: "onStdErr",
118
+ value: function onStdErr() {}
119
+ }, {
120
+ key: "onStdOut",
121
+ value: function onStdOut() {}
122
+ }, {
123
+ key: "onBegin",
124
+ value: function onBegin(suite) {
125
+ this.suite = suite;
126
+ this.allureRuntime = new ReporterRuntime(_objectSpread(_objectSpread({}, this.options), {}, {
127
+ writer: createDefaultWriter({
128
+ resultsDir: this.options.resultsDir
129
+ })
130
+ }));
131
+ }
132
+ }, {
133
+ key: "onTestBegin",
134
+ value: function onTestBegin(test) {
135
+ var suite = test.parent;
136
+ var titleMetadata = extractMetadataFromString(test.title);
137
+ var project = suite.project();
138
+ var pathElements = path.relative(project === null || project === void 0 ? void 0 : project.testDir, test.location.file).split(path.sep);
139
+ var relativeFile = pathElements.join("/");
140
+ // root > project > file path > test.describe...
141
+ var _suite$titlePath = suite.titlePath(),
142
+ _suite$titlePath2 = _toArray(_suite$titlePath),
143
+ suiteTitles = _suite$titlePath2.slice(3);
144
+ var nameSuites = suiteTitles.length > 0 ? "".concat(suiteTitles.join(" "), " ") : "";
145
+ var testCaseIdBase = "".concat(relativeFile, "#").concat(nameSuites).concat(test.title);
146
+ var result = {
147
+ name: titleMetadata.cleanTitle,
148
+ labels: [].concat(_toConsumableArray(titleMetadata.labels), _toConsumableArray(getEnvironmentLabels())),
149
+ links: [],
150
+ parameters: [],
151
+ testCaseId: md5(testCaseIdBase),
152
+ fullName: "".concat(relativeFile, ":").concat(test.location.line, ":").concat(test.location.column)
153
+ };
154
+ result.labels.push({
155
+ name: LabelName.LANGUAGE,
156
+ value: "JavaScript"
157
+ });
158
+ result.labels.push({
159
+ name: LabelName.FRAMEWORK,
160
+ value: "Playwright"
161
+ });
162
+ result.labels.push({
163
+ name: "titlePath",
164
+ value: suite.titlePath().join(" > ")
165
+ });
166
+ result.labels.push({
167
+ name: LabelName.PACKAGE,
168
+ value: pathElements.join(".")
169
+ });
170
+
171
+ // support for earlier playwright versions
172
+ if ("tags" in test) {
173
+ var _ref;
174
+ var tags = test.tags.map(function (tag) {
175
+ return {
176
+ name: LabelName.TAG,
177
+ value: tag.startsWith("@") ? tag.substring(1) : tag
178
+ };
179
+ });
180
+ (_ref = result.labels).push.apply(_ref, _toConsumableArray(tags));
181
+ }
182
+ if (project !== null && project !== void 0 && project.name) {
183
+ result.parameters.push({
184
+ name: "Project",
185
+ value: project.name
186
+ });
187
+ }
188
+ if ((project === null || project === void 0 ? void 0 : project.repeatEach) > 1) {
189
+ result.parameters.push({
190
+ name: "Repetition",
191
+ value: "".concat(test.repeatEachIndex + 1)
192
+ });
193
+ }
194
+ var testUuid = this.allureRuntime.startTest(result);
195
+ this.allureResultsUuids.set(test.id, testUuid);
196
+ this.startedTestCasesTitlesCache.push(titleMetadata.cleanTitle);
197
+ }
198
+ }, {
199
+ key: "onStepBegin",
200
+ value: function onStepBegin(test, _result, step) {
201
+ var testUuid = this.allureResultsUuids.get(test.id);
202
+ if (step.category === "attach") {
203
+ var _this$allureRuntime, _this$attachmentSteps;
204
+ var currentStep = (_this$allureRuntime = this.allureRuntime) === null || _this$allureRuntime === void 0 ? void 0 : _this$allureRuntime.currentStep(testUuid);
205
+ this.attachmentSteps.set(testUuid, [].concat(_toConsumableArray((_this$attachmentSteps = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps !== void 0 ? _this$attachmentSteps : []), [currentStep]));
206
+ return;
207
+ }
208
+
209
+ // TODO fix the details disable, e.g. only ignore pw:api steps
210
+ if (!this.options.detail && step.category !== "test.step") {
211
+ return;
212
+ }
213
+ this.allureRuntime.startStep(testUuid, undefined, {
214
+ name: step.title,
215
+ start: step.startTime.getTime()
216
+ });
217
+ }
218
+ }, {
219
+ key: "onStepEnd",
220
+ value: function onStepEnd(test, _result, step) {
221
+ if (!this.options.detail && step.category !== "test.step") {
222
+ return;
223
+ }
224
+
225
+ // ignore attach steps since attachments are already in the report
226
+ if (step.category === "attach") {
227
+ return;
228
+ }
229
+ var testUuid = this.allureResultsUuids.get(test.id);
230
+ var currentStep = this.allureRuntime.currentStep(testUuid);
231
+ if (!currentStep) {
232
+ return;
233
+ }
234
+ this.allureRuntime.updateStep(currentStep, function (stepResult) {
235
+ stepResult.status = step.error ? Status.FAILED : Status.PASSED;
236
+ stepResult.stage = Stage.FINISHED;
237
+ if (step.error) {
238
+ stepResult.statusDetails = _objectSpread({}, getMessageAndTraceFromError(step.error));
239
+ }
240
+ });
241
+ this.allureRuntime.stopStep(currentStep, {
242
+ duration: step.duration
243
+ });
244
+ }
245
+ }, {
246
+ key: "onTestEnd",
247
+ value: function () {
248
+ var _onTestEnd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(test, result) {
249
+ var _this = this,
250
+ _this$attachmentSteps2;
251
+ var testUuid, threadId, thread, error, _test$parent$titlePat, _test$parent$titlePat2, projectSuiteTitle, fileSuiteTitle, suiteTitles, attachmentSteps, i, attachment, attachmentStep;
252
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
253
+ while (1) switch (_context.prev = _context.next) {
254
+ case 0:
255
+ testUuid = this.allureResultsUuids.get(test.id); // We need to check parallelIndex first because pw introduced this field only in v1.30.0
256
+ threadId = result.parallelIndex !== undefined ? result.parallelIndex : result.workerIndex;
257
+ thread = process.env.ALLURE_THREAD_NAME || "".concat(this.hostname, "-").concat(process.pid, "-playwright-worker-").concat(threadId);
258
+ error = result.error; // only apply default suites if not set by user
259
+ _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);
260
+ this.allureRuntime.updateTest(testUuid, function (testResult) {
261
+ testResult.labels.push({
262
+ name: LabelName.HOST,
263
+ value: _this.hostname
264
+ });
265
+ testResult.labels.push({
266
+ name: LabelName.THREAD,
267
+ value: thread
268
+ });
269
+ if (projectSuiteTitle && !hasLabel(testResult, LabelName.PARENT_SUITE)) {
270
+ testResult.labels.push({
271
+ name: LabelName.PARENT_SUITE,
272
+ value: projectSuiteTitle
273
+ });
274
+ }
275
+ if (_this.options.suiteTitle && fileSuiteTitle && !hasLabel(testResult, LabelName.SUITE)) {
276
+ testResult.labels.push({
277
+ name: LabelName.SUITE,
278
+ value: fileSuiteTitle
279
+ });
280
+ }
281
+ if (suiteTitles.length > 0 && !hasLabel(testResult, LabelName.SUB_SUITE)) {
282
+ testResult.labels.push({
283
+ name: LabelName.SUB_SUITE,
284
+ value: suiteTitles.join(" > ")
285
+ });
286
+ }
287
+ if (error) {
288
+ testResult.statusDetails = _objectSpread({}, getMessageAndTraceFromError(error));
289
+ } else {
290
+ var _test$annotations;
291
+ var skipReason = (_test$annotations = test.annotations) === null || _test$annotations === void 0 || (_test$annotations = _test$annotations.find(function (annotation) {
292
+ return annotation.type === "skip" || annotation.type === "fixme";
293
+ })) === null || _test$annotations === void 0 ? void 0 : _test$annotations.description;
294
+ if (skipReason) {
295
+ testResult.statusDetails = _objectSpread(_objectSpread({}, testResult.statusDetails), {}, {
296
+ message: skipReason
297
+ });
298
+ }
299
+ }
300
+ testResult.status = statusToAllureStats(result.status, test.expectedStatus);
301
+ testResult.stage = Stage.FINISHED;
302
+ });
303
+ attachmentSteps = (_this$attachmentSteps2 = this.attachmentSteps.get(testUuid)) !== null && _this$attachmentSteps2 !== void 0 ? _this$attachmentSteps2 : [];
304
+ i = 0;
305
+ case 8:
306
+ if (!(i < result.attachments.length)) {
307
+ _context.next = 16;
308
+ break;
309
+ }
310
+ attachment = result.attachments[i];
311
+ attachmentStep = attachmentSteps.length > i ? attachmentSteps[i] : undefined;
312
+ _context.next = 13;
313
+ return this.processAttachment(testUuid, attachmentStep, attachment);
314
+ case 13:
315
+ i++;
316
+ _context.next = 8;
317
+ break;
318
+ case 16:
319
+ if (result.stdout.length > 0) {
320
+ this.allureRuntime.writeAttachment(testUuid, undefined, "stdout", Buffer.from(stripAnsi(result.stdout.join("")), "utf-8"), {
321
+ contentType: ContentType.TEXT
322
+ });
323
+ }
324
+ if (result.stderr.length > 0) {
325
+ this.allureRuntime.writeAttachment(testUuid, undefined, "stderr", Buffer.from(stripAnsi(result.stderr.join("")), "utf-8"), {
326
+ contentType: ContentType.TEXT
327
+ });
328
+ }
329
+
330
+ // FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
331
+ // in next iterations we need to implement the logic for every javascript integration
332
+ this.allureRuntime.updateTest(testUuid, function (testResult) {
333
+ var mappedLabels = testResult.labels.reduce(function (acc, label) {
334
+ if (!acc[label.name]) {
335
+ acc[label.name] = [];
336
+ }
337
+ acc[label.name].push(label);
338
+ return acc;
339
+ }, {});
340
+ var newLabels = Object.keys(mappedLabels).flatMap(function (labelName) {
341
+ var labelsGroup = mappedLabels[labelName];
342
+ if (labelName === LabelName.SUITE || labelName === LabelName.PARENT_SUITE || labelName === LabelName.SUB_SUITE) {
343
+ return labelsGroup.slice(-1);
344
+ }
345
+ return labelsGroup;
346
+ });
347
+ testResult.labels = newLabels;
348
+ });
349
+ this.allureRuntime.stopTest(testUuid, {
350
+ duration: result.duration
351
+ });
352
+ this.allureRuntime.writeTest(testUuid);
353
+ case 21:
354
+ case "end":
355
+ return _context.stop();
356
+ }
357
+ }, _callee, this);
358
+ }));
359
+ function onTestEnd(_x, _x2) {
360
+ return _onTestEnd.apply(this, arguments);
361
+ }
362
+ return onTestEnd;
363
+ }()
364
+ }, {
365
+ key: "addSkippedResults",
366
+ value: function () {
367
+ var _addSkippedResults = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
368
+ var _this2 = this;
369
+ var unprocessedCases, _iterator, _step, testCase;
370
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
371
+ while (1) switch (_context2.prev = _context2.next) {
372
+ case 0:
373
+ unprocessedCases = this.suite.allTests().filter(function (_ref2) {
374
+ var title = _ref2.title;
375
+ var titleMetadata = extractMetadataFromString(title);
376
+ return !_this2.startedTestCasesTitlesCache.includes(titleMetadata.cleanTitle);
377
+ });
378
+ _iterator = _createForOfIteratorHelper(unprocessedCases);
379
+ _context2.prev = 2;
380
+ _iterator.s();
381
+ case 4:
382
+ if ((_step = _iterator.n()).done) {
383
+ _context2.next = 11;
384
+ break;
385
+ }
386
+ testCase = _step.value;
387
+ this.onTestBegin(testCase);
388
+ _context2.next = 9;
389
+ return this.onTestEnd(testCase, {
390
+ status: Status.SKIPPED,
391
+ attachments: [],
392
+ duration: 0,
393
+ errors: [],
394
+ parallelIndex: 0,
395
+ workerIndex: 0,
396
+ retry: 0,
397
+ steps: [],
398
+ stderr: [],
399
+ stdout: [],
400
+ startTime: this.globalStartTime
401
+ });
402
+ case 9:
403
+ _context2.next = 4;
404
+ break;
405
+ case 11:
406
+ _context2.next = 16;
407
+ break;
408
+ case 13:
409
+ _context2.prev = 13;
410
+ _context2.t0 = _context2["catch"](2);
411
+ _iterator.e(_context2.t0);
412
+ case 16:
413
+ _context2.prev = 16;
414
+ _iterator.f();
415
+ return _context2.finish(16);
416
+ case 19:
417
+ case "end":
418
+ return _context2.stop();
419
+ }
420
+ }, _callee2, this, [[2, 13, 16, 19]]);
421
+ }));
422
+ function addSkippedResults() {
423
+ return _addSkippedResults.apply(this, arguments);
424
+ }
425
+ return addSkippedResults;
426
+ }()
427
+ }, {
428
+ key: "onEnd",
429
+ value: function () {
430
+ var _onEnd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
431
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
432
+ while (1) switch (_context3.prev = _context3.next) {
433
+ case 0:
434
+ _context3.next = 2;
435
+ return this.addSkippedResults();
436
+ case 2:
437
+ this.allureRuntime.writeEnvironmentInfo();
438
+ this.allureRuntime.writeCategoriesDefinitions();
439
+ case 4:
440
+ case "end":
441
+ return _context3.stop();
442
+ }
443
+ }, _callee3, this);
444
+ }));
445
+ function onEnd() {
446
+ return _onEnd.apply(this, arguments);
447
+ }
448
+ return onEnd;
449
+ }()
450
+ }, {
451
+ key: "printsToStdio",
452
+ value: function printsToStdio() {
453
+ return false;
454
+ }
455
+ }, {
456
+ key: "processAttachment",
457
+ value: function () {
458
+ var _processAttachment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(testUuid, attachmentStepUuid, attachment) {
459
+ var allureRuntimeMessage, message, parentUuid, pathWithoutEnd, actualBase64, expectedBase64, diffBase64, diffName;
460
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
461
+ while (1) switch (_context4.prev = _context4.next) {
462
+ case 0:
463
+ if (!(!attachment.body && !attachment.path)) {
464
+ _context4.next = 2;
465
+ break;
466
+ }
467
+ return _context4.abrupt("return");
468
+ case 2:
469
+ allureRuntimeMessage = attachment.contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE;
470
+ if (!(allureRuntimeMessage && !attachment.body)) {
471
+ _context4.next = 5;
472
+ break;
473
+ }
474
+ return _context4.abrupt("return");
475
+ case 5:
476
+ if (!allureRuntimeMessage) {
477
+ _context4.next = 9;
478
+ break;
479
+ }
480
+ message = JSON.parse(attachment.body.toString()); // TODO fix step metadata messages
481
+ this.allureRuntime.applyRuntimeMessages(testUuid, [message]);
482
+ return _context4.abrupt("return");
483
+ case 9:
484
+ parentUuid = this.allureRuntime.startStep(testUuid, attachmentStepUuid, {
485
+ name: attachment.name
486
+ }); // only stop if step is created. Step may not be created only if test with specified uuid doesn't exists.
487
+ // usually, missing test by uuid means we should completely skip result processing;
488
+ // the later operations are safe and will only produce console warnings
489
+ if (parentUuid) {
490
+ this.allureRuntime.stopStep(parentUuid, undefined);
491
+ }
492
+ if (!attachment.body) {
493
+ _context4.next = 15;
494
+ break;
495
+ }
496
+ this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.body, {
497
+ contentType: attachment.contentType
498
+ });
499
+ _context4.next = 20;
500
+ break;
501
+ case 15:
502
+ if (existsSync(attachment.path)) {
503
+ _context4.next = 19;
504
+ break;
505
+ }
506
+ return _context4.abrupt("return");
507
+ case 19:
508
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
509
+ this.allureRuntime.writeAttachment(testUuid, parentUuid, attachment.name, attachment.path, {
510
+ contentType: attachment.contentType
511
+ });
512
+ case 20:
513
+ if (attachment.name.match(diffEndRegexp)) {
514
+ _context4.next = 22;
515
+ break;
516
+ }
517
+ return _context4.abrupt("return");
518
+ case 22:
519
+ pathWithoutEnd = attachment.path.replace(diffEndRegexp, "");
520
+ if (!this.processedDiffs.includes(pathWithoutEnd)) {
521
+ _context4.next = 25;
522
+ break;
523
+ }
524
+ return _context4.abrupt("return");
525
+ case 25:
526
+ _context4.next = 27;
527
+ return readImageAsBase64("".concat(pathWithoutEnd, "-actual.png"));
528
+ case 27:
529
+ actualBase64 = _context4.sent;
530
+ _context4.next = 30;
531
+ return readImageAsBase64("".concat(pathWithoutEnd, "-expected.png"));
532
+ case 30:
533
+ expectedBase64 = _context4.sent;
534
+ _context4.next = 33;
535
+ return readImageAsBase64("".concat(pathWithoutEnd, "-diff.png"));
536
+ case 33:
537
+ diffBase64 = _context4.sent;
538
+ diffName = attachment.name.replace(diffEndRegexp, "");
539
+ this.allureRuntime.writeAttachment(testUuid, undefined, diffName, Buffer.from(JSON.stringify({
540
+ expected: expectedBase64,
541
+ actual: actualBase64,
542
+ diff: diffBase64,
543
+ name: diffName
544
+ }), "utf-8"), {
545
+ contentType: ContentType.IMAGEDIFF,
546
+ fileExtension: ".imagediff"
547
+ });
548
+ this.processedDiffs.push(pathWithoutEnd);
549
+ case 37:
550
+ case "end":
551
+ return _context4.stop();
552
+ }
553
+ }, _callee4, this);
554
+ }));
555
+ function processAttachment(_x3, _x4, _x5) {
556
+ return _processAttachment.apply(this, arguments);
557
+ }
558
+ return processAttachment;
559
+ }()
560
+ }, {
561
+ key: "version",
562
+ value: function version() {
563
+ return "v2";
564
+ }
565
+ }]);
566
+ }();
567
+
568
+ /**
569
+ * @deprecated for removal, import functions directly from "allure-js-commons".
570
+ */
571
+ export var allure = allurePlaywrightLegacyApi;
572
+
573
+ /**
574
+ * @deprecated for removal, import functions directly from "@playwright/test".
575
+ */
576
+ export { test, expect } from "@playwright/test";
577
+ export default AllureReporter;
578
+ //# sourceMappingURL=index.js.map