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