allure-js-commons 3.0.0-beta.2 → 3.0.0-beta.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.
Files changed (84) hide show
  1. package/dist/cjs/facade.js +0 -2
  2. package/dist/cjs/facade.js.map +1 -1
  3. package/dist/cjs/index.js +6 -0
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/model.js +1 -0
  6. package/dist/cjs/model.js.map +1 -1
  7. package/dist/cjs/sdk/index.js.map +1 -1
  8. package/dist/cjs/sdk/reporter/LifecycleState.js +8 -9
  9. package/dist/cjs/sdk/reporter/LifecycleState.js.map +1 -1
  10. package/dist/cjs/sdk/reporter/ReporterRuntime.js +304 -755
  11. package/dist/cjs/sdk/reporter/ReporterRuntime.js.map +1 -1
  12. package/dist/cjs/sdk/reporter/index.js +0 -7
  13. package/dist/cjs/sdk/reporter/index.js.map +1 -1
  14. package/dist/cjs/sdk/reporter/testplan.js +19 -1
  15. package/dist/cjs/sdk/reporter/testplan.js.map +1 -1
  16. package/dist/cjs/sdk/reporter/types.js +1 -2
  17. package/dist/cjs/sdk/reporter/types.js.map +1 -1
  18. package/dist/cjs/sdk/reporter/utils.js +56 -2
  19. package/dist/cjs/sdk/reporter/utils.js.map +1 -1
  20. package/dist/cjs/sdk/reporter/writer/FileSystemWriter.js +1 -3
  21. package/dist/cjs/sdk/reporter/writer/FileSystemWriter.js.map +1 -1
  22. package/dist/cjs/sdk/reporter/writer/MessageReader.js +39 -0
  23. package/dist/cjs/sdk/reporter/writer/MessageReader.js.map +1 -1
  24. package/dist/cjs/sdk/reporter/writer/MessageWriter.js +1 -3
  25. package/dist/cjs/sdk/reporter/writer/MessageWriter.js.map +1 -1
  26. package/dist/cjs/sdk/runtime/MessageTestRuntime.js +4 -4
  27. package/dist/cjs/sdk/runtime/MessageTestRuntime.js.map +1 -1
  28. package/dist/cjs/sdk/types.js.map +1 -1
  29. package/dist/esm/facade.js +0 -3
  30. package/dist/esm/facade.js.map +1 -1
  31. package/dist/esm/index.js +1 -1
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/model.js +1 -0
  34. package/dist/esm/model.js.map +1 -1
  35. package/dist/esm/sdk/index.js.map +1 -1
  36. package/dist/esm/sdk/reporter/LifecycleState.js +8 -9
  37. package/dist/esm/sdk/reporter/LifecycleState.js.map +1 -1
  38. package/dist/esm/sdk/reporter/ReporterRuntime.js +305 -757
  39. package/dist/esm/sdk/reporter/ReporterRuntime.js.map +1 -1
  40. package/dist/esm/sdk/reporter/index.js +1 -1
  41. package/dist/esm/sdk/reporter/index.js.map +1 -1
  42. package/dist/esm/sdk/reporter/testplan.js +17 -0
  43. package/dist/esm/sdk/reporter/testplan.js.map +1 -1
  44. package/dist/esm/sdk/reporter/types.js +0 -1
  45. package/dist/esm/sdk/reporter/types.js.map +1 -1
  46. package/dist/esm/sdk/reporter/utils.js +52 -2
  47. package/dist/esm/sdk/reporter/utils.js.map +1 -1
  48. package/dist/esm/sdk/reporter/writer/FileSystemWriter.js +1 -3
  49. package/dist/esm/sdk/reporter/writer/FileSystemWriter.js.map +1 -1
  50. package/dist/esm/sdk/reporter/writer/MessageReader.js +40 -1
  51. package/dist/esm/sdk/reporter/writer/MessageReader.js.map +1 -1
  52. package/dist/esm/sdk/reporter/writer/MessageWriter.js +1 -3
  53. package/dist/esm/sdk/reporter/writer/MessageWriter.js.map +1 -1
  54. package/dist/esm/sdk/runtime/MessageTestRuntime.js +5 -5
  55. package/dist/esm/sdk/runtime/MessageTestRuntime.js.map +1 -1
  56. package/dist/esm/sdk/types.js.map +1 -1
  57. package/dist/types/facade.d.ts +1 -1
  58. package/dist/types/index.d.ts +1 -1
  59. package/dist/types/model.d.ts +1 -0
  60. package/dist/types/sdk/index.d.ts +1 -1
  61. package/dist/types/sdk/reporter/LifecycleState.d.ts +4 -4
  62. package/dist/types/sdk/reporter/ReporterRuntime.d.ts +26 -239
  63. package/dist/types/sdk/reporter/index.d.ts +1 -1
  64. package/dist/types/sdk/reporter/testplan.d.ts +5 -0
  65. package/dist/types/sdk/reporter/types.d.ts +8 -39
  66. package/dist/types/sdk/reporter/utils.d.ts +6 -3
  67. package/dist/types/sdk/reporter/writer/MessageReader.d.ts +1 -0
  68. package/dist/types/sdk/types.d.ts +5 -8
  69. package/package.json +1 -1
  70. package/dist/cjs/sdk/reporter/context/AllureContextProviderBase.js +0 -83
  71. package/dist/cjs/sdk/reporter/context/AllureContextProviderBase.js.map +0 -1
  72. package/dist/cjs/sdk/reporter/context/StaticAllureContextProvider.js +0 -122
  73. package/dist/cjs/sdk/reporter/context/StaticAllureContextProvider.js.map +0 -1
  74. package/dist/cjs/sdk/reporter/context/types.js +0 -2
  75. package/dist/cjs/sdk/reporter/context/types.js.map +0 -1
  76. package/dist/esm/sdk/reporter/context/AllureContextProviderBase.js +0 -76
  77. package/dist/esm/sdk/reporter/context/AllureContextProviderBase.js.map +0 -1
  78. package/dist/esm/sdk/reporter/context/StaticAllureContextProvider.js +0 -113
  79. package/dist/esm/sdk/reporter/context/StaticAllureContextProvider.js.map +0 -1
  80. package/dist/esm/sdk/reporter/context/types.js +0 -2
  81. package/dist/esm/sdk/reporter/context/types.js.map +0 -1
  82. package/dist/types/sdk/reporter/context/AllureContextProviderBase.d.ts +0 -31
  83. package/dist/types/sdk/reporter/context/StaticAllureContextProvider.d.ts +0 -52
  84. package/dist/types/sdk/reporter/context/types.d.ts +0 -43
@@ -8,489 +8,289 @@ var _path = require("path");
8
8
  var _model = require("../../model.js");
9
9
  var _LifecycleState = require("./LifecycleState.js");
10
10
  var _Notifier = require("./Notifier.js");
11
- var _StaticAllureContextProvider = require("./context/StaticAllureContextProvider.js");
12
11
  var _factory = require("./factory.js");
13
12
  var _utils = require("./utils.js");
14
13
  var _attachments = require("./utils/attachments.js");
15
14
  var _loader = require("./writer/loader.js");
16
- var _excluded = ["links", "attachments", "displayName", "parameters", "labels"],
17
- _excluded2 = ["status", "stage", "stop"];
15
+ var _excluded = ["links", "labels", "parameters", "displayName"];
18
16
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
19
17
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
20
18
  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; }
21
19
  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; }
20
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
21
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
22
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
23
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
22
24
  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; }
23
25
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
24
26
  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); } /* eslint max-lines: 0 */
27
+ class DefaultStepStack {
28
+ constructor() {
29
+ _defineProperty(this, "stepsByRoot", new Map());
30
+ _defineProperty(this, "rootsByStep", new Map());
31
+ _defineProperty(this, "clear", () => {
32
+ this.stepsByRoot.clear();
33
+ this.rootsByStep.clear();
34
+ });
35
+ _defineProperty(this, "removeRoot", rootUuid => {
36
+ var maybeValue = this.stepsByRoot.get(rootUuid);
37
+ this.stepsByRoot.delete(rootUuid);
38
+ if (maybeValue) {
39
+ maybeValue.forEach(stepUuid => this.rootsByStep.delete(stepUuid));
40
+ }
41
+ });
42
+ _defineProperty(this, "currentStep", rootUuid => {
43
+ var maybeValue = this.stepsByRoot.get(rootUuid);
44
+ if (!maybeValue) {
45
+ return;
46
+ }
47
+ return maybeValue[maybeValue.length - 1];
48
+ });
49
+ _defineProperty(this, "addStep", (rootUuid, stepUuid) => {
50
+ var maybeValue = this.stepsByRoot.get(rootUuid);
51
+ if (!maybeValue) {
52
+ this.stepsByRoot.set(rootUuid, [stepUuid]);
53
+ } else {
54
+ maybeValue.push(stepUuid);
55
+ }
56
+ this.rootsByStep.set(stepUuid, rootUuid);
57
+ });
58
+ }
59
+ removeStep(stepUuid) {
60
+ var rootUuid = this.rootsByStep.get(stepUuid);
61
+ if (!rootUuid) {
62
+ return;
63
+ }
64
+ var maybeValue = this.stepsByRoot.get(rootUuid);
65
+ if (!maybeValue) {
66
+ return;
67
+ }
68
+ var newValue = maybeValue.filter(value => value !== stepUuid);
69
+ this.stepsByRoot.set(rootUuid, newValue);
70
+ }
71
+ }
72
+ var _handleMetadataMessage = /*#__PURE__*/new WeakMap();
73
+ var _handleStepMetadataMessage = /*#__PURE__*/new WeakMap();
74
+ var _handleStartStepMessage = /*#__PURE__*/new WeakMap();
75
+ var _handleStopStepMessage = /*#__PURE__*/new WeakMap();
76
+ var _handleAttachmentContentMessage = /*#__PURE__*/new WeakMap();
77
+ var _handleAttachmentPathMessage = /*#__PURE__*/new WeakMap();
78
+ var _findParent = /*#__PURE__*/new WeakMap();
79
+ var _writeFixturesOfScope = /*#__PURE__*/new WeakMap();
80
+ var _writeContainer = /*#__PURE__*/new WeakMap();
25
81
  class ReporterRuntime {
26
82
  constructor(_ref) {
27
83
  var _this = this;
28
84
  var {
29
85
  writer,
30
86
  listeners = [],
31
- links: _links = [],
32
87
  environmentInfo,
33
88
  categories,
34
- contextProvider = _StaticAllureContextProvider.StaticContextProvider.wrap(new _StaticAllureContextProvider.MutableAllureContextHolder())
89
+ links: _links
35
90
  } = _ref;
36
91
  _defineProperty(this, "state", new _LifecycleState.LifecycleState());
37
92
  _defineProperty(this, "notifier", void 0);
38
- _defineProperty(this, "links", []);
39
- _defineProperty(this, "contextProvider", void 0);
93
+ _defineProperty(this, "stepStack", new DefaultStepStack());
40
94
  _defineProperty(this, "writer", void 0);
41
95
  _defineProperty(this, "categories", void 0);
42
96
  _defineProperty(this, "environmentInfo", void 0);
43
- _defineProperty(this, "hasScope", () => !!this.contextProvider.getScope());
44
- _defineProperty(this, "hasFixture", () => !!this.contextProvider.getFixture());
45
- _defineProperty(this, "hasTest", () => !!this.contextProvider.getTest());
46
- _defineProperty(this, "hasSteps", () => !!this.contextProvider.getStep());
47
- _defineProperty(this, "getCurrentTest", () => {
48
- var testUuid = this.contextProvider.getTest();
49
- return testUuid ? this.state.getTest(testUuid) : undefined;
50
- });
51
- _defineProperty(this, "getCurrentFixture", () => {
52
- var fixtureUuid = this.contextProvider.getFixture();
53
- return fixtureUuid ? this.state.getFixture(fixtureUuid) : undefined;
54
- });
55
- _defineProperty(this, "getCurrentStep", root => {
56
- var stepUuid = this.contextProvider.getStep(root);
57
- return stepUuid ? this.state.getStep(stepUuid) : undefined;
58
- });
59
- _defineProperty(this, "getCurrentExecutingItem", root => {
60
- var uuid = this.contextProvider.getExecutingItem(root);
61
- return uuid ? this.state.getExecutionItem(uuid) : undefined;
62
- });
63
- _defineProperty(this, "getCurrentScope", () => {
64
- var scopeUuid = this.contextProvider.getScope();
65
- return scopeUuid ? this.state.getScope(scopeUuid) : undefined;
66
- });
67
- /**
68
- * Creates a new scope. The scope is pushed into the context unless the `manual`
69
- * option is set to `true`.
70
- *
71
- * @param opts
72
- * @returns
73
- */
74
- _defineProperty(this, "startScope", function () {
75
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
76
- return _this.startScopeWithUuid((0, _utils.randomUuid)(), opts);
77
- });
78
- _defineProperty(this, "updateScope", (updateFunc, uuid) => {
79
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : this.contextProvider.getScope();
80
- if (!resolvedUuid) {
81
- // eslint-disable-next-line no-console
82
- console.error("No current scope to update!");
83
- return;
84
- }
85
- var scope = this.state.getScope(resolvedUuid);
97
+ _defineProperty(this, "linkConfig", void 0);
98
+ _defineProperty(this, "startScope", () => {
99
+ var uuid = (0, _utils.randomUuid)();
100
+ this.state.setScope(uuid);
101
+ return uuid;
102
+ });
103
+ _defineProperty(this, "updateScope", (uuid, updateFunc) => {
104
+ var scope = this.state.getScope(uuid);
86
105
  if (!scope) {
87
106
  // eslint-disable-next-line no-console
88
- console.error("No scope ".concat(resolvedUuid, " to update!"));
107
+ console.error("count not update scope: no scope with uuid ".concat(uuid, " is found"));
89
108
  return;
90
109
  }
91
110
  updateFunc(scope);
92
111
  });
93
- /**
94
- * Removes a scope from the context. Use `writeScope` to emit its fixtures on disk then.
95
- *
96
- * If you just want to write the current stop, you may omit the call to this method and
97
- * call `writeScope` with no uuid.
98
- *
99
- * @param uuid The UUID of the scope. If not provided, the current scope will be stopped.
100
- *
101
- * @returns The UUID of the scope that has been stopped.
102
- */
103
- _defineProperty(this, "stopScope", uuid => {
104
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : this.contextProvider.getScope();
105
- if (!resolvedUuid) {
106
- // eslint-disable-next-line no-console
107
- console.error("No current scope to stop!");
108
- return;
109
- }
110
- this.contextProvider.removeScope(uuid);
111
- return resolvedUuid;
112
- });
113
- /**
114
- * Writes all fixtures of a scope on disk.
115
- *
116
- * @param uuid The UUID of the scope. If not provided, the current scope will
117
- * be written and removed from the context. Don't call `stopScope` in that case.
118
- */
119
112
  _defineProperty(this, "writeScope", uuid => {
120
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : this.stopScope();
121
- if (!resolvedUuid) {
122
- return;
123
- }
124
- var scope = this.state.getScope(resolvedUuid);
113
+ var scope = this.state.getScope(uuid);
125
114
  if (!scope) {
126
115
  // eslint-disable-next-line no-console
127
- console.error("No scope ".concat(resolvedUuid, " to write!"));
116
+ console.error("count not write scope: no scope with uuid ".concat(uuid, " is found"));
128
117
  return;
129
118
  }
130
- this.writeAllFixturesOfScope(scope);
131
- this.removeScopeFromParent(scope);
132
- this.state.deleteScope(resolvedUuid);
133
- });
134
- /**
135
- * Creates a new fixture result and puts it in the context as the current one.
136
- *
137
- * Use the `scope` parameter to control the fixture's scope. Use `updateScope`
138
- * or `linkFixtures` to associate fixtures with tests that can't be linked
139
- * automatically.
140
- *
141
- * Use `stopFixture` once the fixture is completed.
142
- *
143
- * Use `writeScope` or `writeFixture` to emit fixtures on disk.
144
- *
145
- * @param type The type of the fixture. It's either `"before"` or `"after"`.
146
- * @param fixtureResult The fixture result data.
147
- * @param scope
148
- * @param dedicatedScope
149
- * @param tests
150
- * @returns The UUID of the new fixture.
151
- */
152
- _defineProperty(this, "startFixture", function (type, fixtureResult) {
153
- var {
154
- scope,
155
- dedicatedScope,
156
- tests
157
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
158
- dedicatedScope = dedicatedScope || scope === null && !!tests;
159
- var scopeObj = _this.resolveScope(scope);
160
- if (scopeObj === undefined) {
119
+ _classPrivateFieldGet(_writeFixturesOfScope, this).call(this, scope);
120
+ this.state.deleteScope(scope.uuid);
121
+ });
122
+ _defineProperty(this, "startFixture", (scopeUuid, type, fixtureResult) => {
123
+ var scope = this.state.getScope(scopeUuid);
124
+ if (!scope) {
161
125
  // eslint-disable-next-line no-console
162
- console.error("Can't resolve the scope for a new fixture");
126
+ console.error("count not start fixture: no scope with uuid ".concat(scopeUuid, " is found"));
163
127
  return;
164
128
  }
165
129
  var uuid = (0, _utils.randomUuid)();
166
- var wrappedFixture = _this.state.setFixtureResult(uuid, type, _objectSpread(_objectSpread({}, (0, _factory.createFixtureResult)()), {}, {
130
+ var wrappedFixture = this.state.setFixtureResult(uuid, type, _objectSpread(_objectSpread({}, (0, _factory.createFixtureResult)()), {}, {
167
131
  start: Date.now()
168
132
  }, fixtureResult));
169
- if (dedicatedScope || tests && scopeObj === null) {
170
- _this.setUpFixtureDedicatedScope(wrappedFixture, tests, scopeObj);
171
- } else if (scopeObj !== null) {
172
- _this.linkFixtureToScope(wrappedFixture, scopeObj, tests);
173
- }
174
- _this.contextProvider.setFixture(uuid);
133
+ scope.fixtures.push(wrappedFixture);
175
134
  return uuid;
176
135
  });
177
- _defineProperty(this, "updateFixture", (updateFunc, uuid) => {
178
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : this.contextProvider.getFixture();
179
- if (!resolvedUuid) {
180
- // eslint-disable-next-line no-console
181
- console.error("No current fixture to update!");
182
- return;
183
- }
184
- var fixture = this.state.getFixture(resolvedUuid);
136
+ _defineProperty(this, "updateFixture", (uuid, updateFunc) => {
137
+ var fixture = this.state.getFixtureResult(uuid);
185
138
  if (!fixture) {
186
139
  // eslint-disable-next-line no-console
187
- console.error("No fixture (".concat(resolvedUuid, ") to update!"));
140
+ console.error("could not update fixture: no fixture with uuid ".concat(uuid, " is found"));
188
141
  return;
189
142
  }
190
143
  updateFunc(fixture);
191
144
  });
192
- /**
193
- * Stops a fixture and removes it from the context. The fixture result will persist in
194
- * the storage until it's written on disk with `writeScope` or `writeFixture`.
195
- *
196
- * @returns The UUID of the stopped fixture.
197
- */
198
- _defineProperty(this, "stopFixture", function () {
199
- var {
200
- uuid,
201
- stop
202
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
203
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : _this.contextProvider.getFixture();
204
- if (!resolvedUuid) {
205
- // eslint-disable-next-line no-console
206
- console.error("No current fixture to stop!");
207
- return;
208
- }
209
- var fixture = _this.state.getFixture(resolvedUuid);
145
+ _defineProperty(this, "stopFixture", (uuid, stop) => {
146
+ var fixture = this.state.getFixtureResult(uuid);
210
147
  if (!fixture) {
211
148
  // eslint-disable-next-line no-console
212
- console.error("No fixture (".concat(resolvedUuid, ") to stop!"));
213
- return;
214
- }
215
- _this.stopFixtureObj(fixture, uuid, stop);
216
- return resolvedUuid;
217
- });
218
- /**
219
- * Use to associate fixtures, scopes, and tests with each other.
220
- *
221
- * At least two arguments must be provided.
222
- */
223
- _defineProperty(this, "linkFixtures", _ref2 => {
224
- var {
225
- fixtures = [],
226
- scope,
227
- tests = []
228
- } = _ref2;
229
- var wrappedFixtures = fixtures.map(f => {
230
- var obj = this.state.getWrappedFixture(f);
231
- if (obj === undefined) {
232
- // eslint-disable-next-line no-console
233
- console.error("No fixture (".concat(f, ") to link!"));
234
- }
235
- return obj;
236
- }).filter(f => f);
237
- var scopeObj = scope ? this.state.getScope(scope) : null;
238
- if (scopeObj === undefined) {
239
- // eslint-disable-next-line no-console
240
- console.error("No scope (".concat(scope, ") to link!"));
241
- return;
242
- }
243
- if (wrappedFixtures.length && scopeObj) {
244
- this.linkFixturesToScope(wrappedFixtures, scopeObj, tests);
245
- return;
246
- }
247
- if (wrappedFixtures.length && tests.length) {
248
- for (var fixture of wrappedFixtures) {
249
- if (fixture.scope) {
250
- this.linkTestsToScope(fixture.scope, tests);
251
- } else {
252
- this.setUpFixtureDedicatedScope(fixture, tests);
253
- }
254
- }
255
- return;
256
- }
257
- if (scopeObj && tests) {
258
- this.linkTestsToScope(scopeObj, tests);
259
- return;
260
- }
261
-
262
- // eslint-disable-next-line no-console
263
- console.error("Provide at least two arguments to link!");
264
- });
265
- /**
266
- * Emits a fixture on disk. Calls `stopFixture` prior to that in case the fixture
267
- * hasn't been stopped yet. Use this method if you want to manage fixtures manually.
268
- * Otherwise, use `writeScope`.
269
- *
270
- * If called without parameters, implicitly calls `stopFixture`. Make sure you don't call
271
- * `stopFixture` by yourself in that case.
272
- *
273
- * The method has no effect if the fixture isn't associated with at least one test.
274
- *
275
- * @param uuid The UUID of the fixture. If not provided, the current fixture will
276
- * be stopped and emitted. Don't call `stopFixture` in that case.
277
- */
278
- _defineProperty(this, "writeFixture", uuid => {
279
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : this.stopFixture();
280
- if (!resolvedUuid) {
281
- // eslint-disable-next-line no-console
282
- console.error("Unable to stop the current fixture before write!");
149
+ console.error("could not stop fixture: no fixture with uuid ".concat(uuid, " is found"));
283
150
  return;
284
151
  }
285
- var wrappedFixture = this.state.getWrappedFixture(resolvedUuid);
286
- if (!wrappedFixture) {
287
- // eslint-disable-next-line no-console
288
- console.error("No fixture (".concat(resolvedUuid, ") to write!"));
289
- return;
290
- }
291
- var fixture = wrappedFixture.value;
292
- if (fixture.stage !== _model.Stage.FINISHED) {
293
- this.stopFixtureObj(wrappedFixture.value, resolvedUuid);
294
- }
295
- var {
296
- scope
297
- } = wrappedFixture;
298
- if (scope) {
299
- this.writeContainer(scope.tests, wrappedFixture);
300
- this.removeFixtureFromScope(scope, wrappedFixture);
301
- }
302
- this.state.deleteFixtureResult(resolvedUuid);
152
+ fixture.stop = stop !== null && stop !== void 0 ? stop : Date.now();
153
+ fixture.stage = _model.Stage.FINISHED;
303
154
  });
304
155
  _defineProperty(this, "startTest", function (result) {
305
- var {
306
- scope,
307
- dedicatedScope
308
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
309
- var stateObject = _this.createTestResult(result);
310
- var uuid = stateObject.uuid;
311
- _this.notifier.beforeTestResultStart(stateObject);
312
- var resolvedScope = dedicatedScope ? _this.startScopeWithUuid(uuid, {
313
- manual: scope !== undefined,
314
- parent: scope !== null && scope !== void 0 ? scope : undefined
315
- }) : scope !== null && scope !== void 0 ? scope : _this.contextProvider.getScope();
316
- if (resolvedScope) {
317
- _this.introduceTestIntoScopes(uuid, resolvedScope);
318
- }
319
- _this.state.setTestResult(uuid, stateObject);
320
- _this.contextProvider.setTest(uuid);
321
- _this.notifier.afterTestResultStart(stateObject);
156
+ var scopeUuids = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
157
+ var uuid = (0, _utils.randomUuid)();
158
+ var testResult = _objectSpread(_objectSpread({}, (0, _factory.createTestResult)(uuid)), {}, {
159
+ start: Date.now()
160
+ }, (0, _utils.deepClone)(result));
161
+ _this.notifier.beforeTestResultStart(testResult);
162
+ scopeUuids.forEach(scopeUuid => {
163
+ var scope = _this.state.getScope(scopeUuid);
164
+ if (!scope) {
165
+ // eslint-disable-next-line no-console
166
+ console.error("count not link test to the scope: no scope with uuid ".concat(uuid, " is found"));
167
+ return;
168
+ }
169
+ scope.tests.push(uuid);
170
+ });
171
+ _this.state.setTestResult(uuid, testResult);
172
+ _this.notifier.afterTestResultStart(testResult);
322
173
  return uuid;
323
174
  });
324
- /**
325
- * Updates test result by uuid
326
- * @example
327
- * ```ts
328
- * runtime.update(uuid, (result) => {
329
- * // change the result directly, you don't need to return anything
330
- * result.name = "foo";
331
- * });
332
- * ```
333
- * @param updateFunc - a function that updates the test result; the result is passed as a single argument and should be mutated to apply the changes
334
- * @param uuid - test result uuid
335
- */
336
- _defineProperty(this, "updateTest", (updateFunc, uuid) => {
337
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : this.contextProvider.getTest();
338
- if (!resolvedUuid) {
339
- // eslint-disable-next-line no-console
340
- console.error("No current test to update!");
341
- return;
342
- }
343
- var targetResult = this.state.getTest(resolvedUuid);
344
- if (!targetResult) {
175
+ _defineProperty(this, "updateTest", (uuid, updateFunc) => {
176
+ var testResult = this.state.getTestResult(uuid);
177
+ if (!testResult) {
345
178
  // eslint-disable-next-line no-console
346
- console.error("No test (".concat(resolvedUuid, ") to update!"));
179
+ console.error("could not update test result: no test with uuid ".concat(uuid, ") is found"));
347
180
  return;
348
181
  }
349
- this.notifier.beforeTestResultUpdate(targetResult);
350
- updateFunc(targetResult);
351
- this.notifier.afterTestResultUpdate(targetResult);
182
+ this.notifier.beforeTestResultUpdate(testResult);
183
+ updateFunc(testResult);
184
+ this.notifier.afterTestResultUpdate(testResult);
352
185
  });
353
- _defineProperty(this, "stopTest", function () {
354
- var _targetResult$testCas, _targetResult$history;
355
- var {
356
- uuid,
357
- stop
358
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
359
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : _this.contextProvider.getTest();
360
- if (!resolvedUuid) {
361
- // eslint-disable-next-line no-console
362
- console.error("No current test to stop!");
363
- return;
364
- }
365
- var targetResult = _this.state.getTest(resolvedUuid);
366
- if (!targetResult) {
186
+ _defineProperty(this, "stopTest", (uuid, stop) => {
187
+ var _testResult$testCaseI, _testResult$historyId;
188
+ var testResult = this.state.getTestResult(uuid);
189
+ if (!testResult) {
367
190
  // eslint-disable-next-line no-console
368
- console.error("No test (".concat(resolvedUuid, ") to stop!"));
191
+ console.error("could not stop test result: no test with uuid ".concat(uuid, ") is found"));
369
192
  return;
370
193
  }
371
- _this.notifier.beforeTestResultStop(targetResult);
372
- (_targetResult$testCas = targetResult.testCaseId) !== null && _targetResult$testCas !== void 0 ? _targetResult$testCas : targetResult.testCaseId = (0, _utils.getTestResultTestCaseId)(targetResult);
373
- (_targetResult$history = targetResult.historyId) !== null && _targetResult$history !== void 0 ? _targetResult$history : targetResult.historyId = (0, _utils.getTestResultHistoryId)(targetResult);
374
- targetResult.stop = stop || Date.now();
375
- _this.notifier.afterTestResultStop(targetResult);
376
- });
377
- /**
378
- * Writes a test result on disk and removes it from the storage and the context.
379
- * @param uuid The UUID of the test. If not set, the current test result is written.
380
- */
194
+ this.notifier.beforeTestResultStop(testResult);
195
+ (_testResult$testCaseI = testResult.testCaseId) !== null && _testResult$testCaseI !== void 0 ? _testResult$testCaseI : testResult.testCaseId = (0, _utils.getTestResultTestCaseId)(testResult);
196
+ (_testResult$historyId = testResult.historyId) !== null && _testResult$historyId !== void 0 ? _testResult$historyId : testResult.historyId = (0, _utils.getTestResultHistoryId)(testResult);
197
+ testResult.stop = stop !== null && stop !== void 0 ? stop : Date.now();
198
+ this.notifier.afterTestResultStop(testResult);
199
+ });
381
200
  _defineProperty(this, "writeTest", uuid => {
382
- var resolvedUuid = uuid !== null && uuid !== void 0 ? uuid : this.contextProvider.getTest();
383
- if (!resolvedUuid) {
201
+ var testResult = this.state.testResults.get(uuid);
202
+ if (!testResult) {
384
203
  // eslint-disable-next-line no-console
385
- console.error("No current test to write!");
204
+ console.error("could not write test result: no test with uuid ".concat(uuid, " is found"));
386
205
  return;
387
206
  }
388
- var testResult = this.state.testResults.get(resolvedUuid);
389
- if (!testResult) {
390
- // eslint-disable-next-line no-console
391
- console.error("No test (".concat(resolvedUuid, ") to write!"));
207
+ if (testResult.labels.find(label => label.name === "ALLURE_TESTPLAN_SKIP")) {
208
+ this.state.deleteTestResult(uuid);
392
209
  return;
393
210
  }
394
211
  this.notifier.beforeTestResultWrite(testResult);
395
212
  this.writer.writeResult(testResult);
396
- this.contextProvider.removeTest(uuid);
397
- this.state.deleteTestResult(resolvedUuid);
398
- var currentScope = this.contextProvider.getScope();
399
- if (currentScope === resolvedUuid) {
400
- // Writes the scope introduced into the context by `startTest` with
401
- // `dedicatedScope` set to `true`.
402
- this.writeScope();
403
- }
213
+ this.state.deleteTestResult(uuid);
404
214
  this.notifier.afterTestResultWrite(testResult);
405
215
  });
406
- /**
407
- * Starts a new step and pushes it into the context.
408
- *
409
- * @param result Data to be put into the step result object.
410
- * @param uuid The UUID of a test or fixture to attach the step to. If not set, the UUID of the current fixture is used.
411
- * If no fixture is running, the UUID of the current test is used.
412
- *
413
- * @returns The UUID of the step.
414
- */
415
- _defineProperty(this, "startStep", (result, uuid) => {
416
- var parentUuid = this.contextProvider.getExecutingItem(uuid);
417
- if (!parentUuid) {
418
- // eslint-disable-next-line no-console
419
- console.error("No current step, fixture, or test to start a new step!");
420
- return;
421
- }
422
- var parent = this.state.getExecutionItem(parentUuid);
216
+ _defineProperty(this, "currentStep", rootUuid => {
217
+ return this.stepStack.currentStep(rootUuid);
218
+ });
219
+ _defineProperty(this, "startStep", (rootUuid, parentStepUuid, result) => {
220
+ var parent = _classPrivateFieldGet(_findParent, this).call(this, rootUuid, parentStepUuid);
423
221
  if (!parent) {
424
222
  // eslint-disable-next-line no-console
425
- console.error("No execution item (".concat(parentUuid, ") to start a step!"));
223
+ console.error("could not start test step: no context for root ".concat(rootUuid, " and parentStepUuid ").concat(JSON.stringify(parentStepUuid), " is found"));
426
224
  return;
427
225
  }
428
- return this.addStepToItem(result, uuid, parent);
226
+ var stepResult = _objectSpread(_objectSpread({}, (0, _factory.createStepResult)()), {}, {
227
+ start: Date.now()
228
+ }, result);
229
+ parent.steps.push(stepResult);
230
+ var stepUuid = (0, _utils.randomUuid)();
231
+ this.state.setStepResult(stepUuid, stepResult);
232
+ this.stepStack.addStep(rootUuid, stepUuid);
233
+ return stepUuid;
429
234
  });
430
- _defineProperty(this, "updateStep", (updateFunc, uuid) => {
431
- var stepUuid = this.contextProvider.getStep(uuid);
432
- if (!stepUuid) {
433
- this.logMissingStepRoot(uuid, "update");
434
- return;
435
- }
436
- var step = this.state.getStep(stepUuid);
235
+ _defineProperty(this, "updateStep", (uuid, updateFunc) => {
236
+ var step = this.state.getStepResult(uuid);
437
237
  if (!step) {
438
238
  // eslint-disable-next-line no-console
439
- console.error("No step ".concat(stepUuid, " to update!"));
239
+ console.error("could not update test step: no step with uuid ".concat(uuid, " is found"));
440
240
  return;
441
241
  }
442
242
  updateFunc(step);
443
243
  });
444
- _defineProperty(this, "stopStep", function () {
445
- var {
446
- uuid,
447
- stop
448
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
449
- var stepUuid = _this.contextProvider.getStep(uuid);
450
- if (!stepUuid) {
451
- _this.logMissingStepRoot(uuid, "stop");
452
- return;
453
- }
454
- var step = _this.state.getStep(stepUuid);
244
+ _defineProperty(this, "stopStep", (uuid, stop) => {
245
+ var step = this.state.getStepResult(uuid);
455
246
  if (!step) {
456
247
  // eslint-disable-next-line no-console
457
- console.error("No step ".concat(stepUuid, " to stop!"));
248
+ console.error("could not stop test step: no step with uuid ".concat(uuid, " is found"));
458
249
  return;
459
250
  }
460
- _this.notifier.beforeStepStop(step);
251
+ this.notifier.beforeStepStop(step);
461
252
  step.stop = stop !== null && stop !== void 0 ? stop : Date.now();
462
253
  step.stage = _model.Stage.FINISHED;
463
- _this.state.deleteStepResult(stepUuid);
464
- _this.contextProvider.removeStep(uuid);
465
- _this.notifier.afterStepStop(step);
466
- });
467
- _defineProperty(this, "writeAttachment", (attachmentName, attachmentContent, options, uuid) => {
468
- var target = this.getCurrentExecutingItem(uuid);
469
- if (!target) {
470
- if (uuid) {
471
- // eslint-disable-next-line no-console
472
- console.error("No test or fixture ".concat(uuid, " to attach!"));
473
- } else {
474
- // eslint-disable-next-line no-console
475
- console.error("No current test or fixture to attach!");
476
- }
477
- return;
478
- }
479
- this.writeAttachmentForItem(attachmentName, attachmentContent, options, target);
254
+ this.stepStack.removeStep(uuid);
255
+ this.notifier.afterStepStop(step);
480
256
  });
481
- _defineProperty(this, "writeAttachmentFromPath", (attachmentName, attachmentPath, options, uuid) => {
482
- var target = this.getCurrentExecutingItem(uuid);
483
- if (!target) {
484
- if (uuid) {
485
- // eslint-disable-next-line no-console
486
- console.error("No test or fixture ".concat(uuid, " to attach!"));
487
- } else {
488
- // eslint-disable-next-line no-console
489
- console.error("No current test or fixture to attach!");
490
- }
257
+ _defineProperty(this, "writeAttachment", (rootUuid, parentStepUuid, attachmentName, attachmentContentOrPath, options) => {
258
+ var _options$fileExtensio;
259
+ var parent = _classPrivateFieldGet(_findParent, this).call(this, rootUuid, parentStepUuid);
260
+ if (!parent) {
261
+ // eslint-disable-next-line no-console
262
+ console.error("could not write test attachment: no context for root ".concat(rootUuid, " and parentStepUuid ").concat(JSON.stringify(parentStepUuid), " is found"));
491
263
  return;
492
264
  }
493
- this.writeAttachmentForItem(attachmentName, attachmentPath, options, target);
265
+ var isPath = typeof attachmentContentOrPath === "string";
266
+ var fileExtension = (_options$fileExtensio = options.fileExtension) !== null && _options$fileExtensio !== void 0 ? _options$fileExtensio : isPath ? (0, _path.extname)(attachmentContentOrPath) : undefined;
267
+ var attachmentFileName = (0, _attachments.buildAttachmentFileName)({
268
+ contentType: options.contentType,
269
+ fileExtension
270
+ });
271
+ if (isPath) {
272
+ this.writer.writeAttachmentFromPath(attachmentFileName, attachmentContentOrPath);
273
+ } else {
274
+ this.writer.writeAttachment(attachmentFileName, attachmentContentOrPath);
275
+ }
276
+ var attachment = {
277
+ name: attachmentName,
278
+ source: attachmentFileName,
279
+ type: options.contentType
280
+ };
281
+ if (options.wrapInStep) {
282
+ var {
283
+ timestamp = Date.now()
284
+ } = options;
285
+ parent.steps.push({
286
+ name: attachmentName,
287
+ attachments: [attachment],
288
+ start: timestamp,
289
+ stop: timestamp
290
+ });
291
+ } else {
292
+ parent.attachments.push(attachment);
293
+ }
494
294
  });
495
295
  _defineProperty(this, "writeEnvironmentInfo", () => {
496
296
  if (!this.environmentInfo) {
@@ -513,425 +313,174 @@ class ReporterRuntime {
513
313
  });
514
314
  this.writer.writeCategoriesDefinitions(serializedCategories);
515
315
  });
516
- _defineProperty(this, "applyRuntimeMessages", function () {
517
- var _ref3;
518
- var messages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
519
- var {
520
- testUuid,
521
- fixtureUuid,
522
- customHandler
523
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
524
- var resolvedTestUuid = testUuid !== null && testUuid !== void 0 ? testUuid : _this.contextProvider.getTest();
525
- var resolvedFixtureUuid = fixtureUuid !== null && fixtureUuid !== void 0 ? fixtureUuid : _this.contextProvider.getFixture();
526
- var resolvedRootUuid = (_ref3 = resolvedFixtureUuid !== null && resolvedFixtureUuid !== void 0 ? resolvedFixtureUuid : resolvedTestUuid) !== null && _ref3 !== void 0 ? _ref3 : _this.contextProvider.getStepRoot();
527
- if (!resolvedRootUuid) {
528
- // eslint-disable-next-line no-console
529
- console.error("No current fixture or test to apply runtime messages to!");
530
- return;
531
- }
532
- var fixture = resolvedFixtureUuid ? _this.state.getFixture(resolvedFixtureUuid) : undefined;
533
- var test = resolvedTestUuid ? _this.state.getTest(resolvedTestUuid) : undefined;
534
- var root = fixture !== null && fixture !== void 0 ? fixture : test;
535
- if (!root) {
536
- // eslint-disable-next-line no-console
537
- console.error("No fixture or test (".concat(resolvedRootUuid, ") to apply runtime messages to!"));
538
- return;
539
- }
540
- var targets = {
541
- fixtureUuid: resolvedFixtureUuid !== null && resolvedFixtureUuid !== void 0 ? resolvedFixtureUuid : undefined,
542
- fixture,
543
- testUuid: resolvedTestUuid !== null && resolvedTestUuid !== void 0 ? resolvedTestUuid : undefined,
544
- test,
545
- rootUuid: resolvedRootUuid,
546
- root
547
- };
548
- for (var message of messages) {
549
- var step = _this.getCurrentStep(resolvedRootUuid);
550
- targets.step = step;
551
- var unhandledMessage = _this.handleBuiltInMessage(message, targets);
552
- if (unhandledMessage && customHandler) {
553
- customHandler(unhandledMessage, fixture, test, step);
316
+ _defineProperty(this, "applyRuntimeMessages", (rootUuid, messages) => {
317
+ messages.forEach(message => {
318
+ switch (message.type) {
319
+ case "metadata":
320
+ _classPrivateFieldGet(_handleMetadataMessage, this).call(this, rootUuid, message.data);
321
+ return;
322
+ case "step_metadata":
323
+ _classPrivateFieldGet(_handleStepMetadataMessage, this).call(this, rootUuid, message.data);
324
+ return;
325
+ case "step_start":
326
+ _classPrivateFieldGet(_handleStartStepMessage, this).call(this, rootUuid, message.data);
327
+ return;
328
+ case "step_stop":
329
+ _classPrivateFieldGet(_handleStopStepMessage, this).call(this, rootUuid, message.data);
330
+ return;
331
+ case "attachment_content":
332
+ _classPrivateFieldGet(_handleAttachmentContentMessage, this).call(this, rootUuid, message.data);
333
+ return;
334
+ case "attachment_path":
335
+ _classPrivateFieldGet(_handleAttachmentPathMessage, this).call(this, rootUuid, message.data);
336
+ return;
337
+ default:
338
+ // eslint-disable-next-line no-console
339
+ console.error("could not apply runtime messages: unknown message ".concat(JSON.stringify(message)));
340
+ return;
554
341
  }
555
- }
556
- });
557
- _defineProperty(this, "handleBuiltInMessage", (message, targets) => {
558
- switch (message.type) {
559
- case "metadata":
560
- this.handleMetadataMessage(message, targets);
561
- return;
562
- case "step_start":
563
- this.handleStepStartMessage(message, targets);
564
- return;
565
- case "step_metadata":
566
- this.handleStepMetadataMessage(message, targets);
567
- return;
568
- case "step_stop":
569
- this.handleStepStopMessage(message, targets);
570
- return;
571
- case "attachment_content":
572
- this.handleAttachmentContentMessage(message, targets);
573
- return;
574
- case "attachment_path":
575
- this.handleAttachmentPathMessage(message, targets);
576
- return;
577
- default:
578
- return message;
579
- }
342
+ });
580
343
  });
581
- _defineProperty(this, "handleMetadataMessage", (message, _ref4) => {
582
- var {
583
- test,
584
- root,
585
- step
586
- } = _ref4;
587
- var _message$data = message.data,
588
- {
589
- links = [],
590
- attachments = [],
591
- displayName,
592
- parameters = [],
593
- labels = []
594
- } = _message$data,
595
- rest = _objectWithoutProperties(_message$data, _excluded);
596
- var formattedLinks = this.formatLinks(links);
597
- if (displayName) {
598
- root.name = displayName;
599
- }
600
- if (test) {
601
- test.links = test.links.concat(formattedLinks);
602
- test.labels = test.labels.concat(labels);
603
- test.parameters = test.parameters.concat(parameters);
604
- Object.assign(test, rest);
344
+ _classPrivateFieldInitSpec(this, _handleMetadataMessage, (rootUuid, message) => {
345
+ // only display name could be set to fixture.
346
+ var fixtureResult = this.state.getFixtureResult(rootUuid);
347
+ if (fixtureResult) {
348
+ this.updateFixture(rootUuid, result => {
349
+ if (message.displayName) {
350
+ result.name = message.displayName;
351
+ }
352
+ });
353
+ return;
605
354
  }
606
- var attachmentTarget = step || root;
607
- attachmentTarget.attachments = attachmentTarget.attachments.concat(attachments);
608
- });
609
- _defineProperty(this, "handleStepStartMessage", (message, _ref5) => {
610
355
  var {
611
- rootUuid,
612
- root,
613
- step
614
- } = _ref5;
615
- return this.addStepToItem(_objectSpread({}, message.data), rootUuid, step !== null && step !== void 0 ? step : root);
356
+ links,
357
+ labels,
358
+ parameters,
359
+ displayName
360
+ } = message,
361
+ rest = _objectWithoutProperties(message, _excluded);
362
+ this.updateTest(rootUuid, result => {
363
+ if (links) {
364
+ result.links = [...result.links, ...(this.linkConfig ? (0, _utils.formatLinks)(this.linkConfig, links) : links)];
365
+ }
366
+ if (labels) {
367
+ result.labels = [...result.labels, ...labels];
368
+ }
369
+ if (parameters) {
370
+ result.parameters = [...result.parameters, ...parameters];
371
+ }
372
+ if (displayName) {
373
+ result.name = displayName;
374
+ }
375
+ Object.assign(result, rest);
376
+ });
616
377
  });
617
- _defineProperty(this, "handleStepMetadataMessage", (message, _ref6) => {
618
- var {
619
- rootUuid,
620
- step
621
- } = _ref6;
622
- if (!step) {
378
+ _classPrivateFieldInitSpec(this, _handleStepMetadataMessage, (rootUuid, message) => {
379
+ var stepUuid = this.currentStep(rootUuid);
380
+ if (!stepUuid) {
623
381
  // eslint-disable-next-line no-console
624
- console.error("No current step of ".concat(rootUuid, " to apply the metadata"));
382
+ console.error("could not handle step metadata message: no step is running");
625
383
  return;
626
384
  }
627
385
  var {
628
386
  name,
629
387
  parameters
630
- } = message.data;
631
- if (name) {
632
- step.name = name;
633
- }
634
- if (parameters !== null && parameters !== void 0 && parameters.length) {
635
- step.parameters = step.parameters.concat(parameters);
636
- }
637
- });
638
- _defineProperty(this, "handleStepStopMessage", (message, _ref7) => {
639
- var {
640
- rootUuid,
641
- step
642
- } = _ref7;
643
- if (!step) {
644
- // eslint-disable-next-line no-console
645
- console.error("No current step of ".concat(rootUuid, " to stop"));
646
- return;
647
- }
648
- var _message$data2 = message.data,
649
- {
650
- status,
651
- stage,
652
- stop
653
- } = _message$data2,
654
- rest = _objectWithoutProperties(_message$data2, _excluded2);
655
-
656
- // we should not override the status and stage if they are already set
657
- if (step.status === undefined) {
658
- step.status = status;
659
- }
660
- if (step.stage === undefined) {
661
- step.stage = stage;
662
- }
663
- Object.assign(step, rest);
664
- this.stopStep({
665
- uuid: rootUuid,
666
- stop
388
+ } = message;
389
+ this.updateStep(stepUuid, stepResult => {
390
+ if (name) {
391
+ stepResult.name = name;
392
+ }
393
+ if (parameters) {
394
+ stepResult.parameters = [...stepResult.parameters, ...parameters];
395
+ }
667
396
  });
668
397
  });
669
- _defineProperty(this, "handleAttachmentContentMessage", (message, _ref8) => {
670
- var {
671
- root,
672
- step
673
- } = _ref8;
674
- var item = step !== null && step !== void 0 ? step : root;
675
- var {
676
- name,
677
- content,
678
- encoding,
679
- contentType,
680
- fileExtension,
681
- wrapInStep
682
- } = message.data;
683
- this.writeAttachmentForItem(name, Buffer.from(content, encoding), {
684
- contentType,
685
- fileExtension
686
- }, item, wrapInStep);
687
- });
688
- _defineProperty(this, "handleAttachmentPathMessage", (message, _ref9) => {
689
- var {
690
- root,
691
- step
692
- } = _ref9;
693
- var item = step !== null && step !== void 0 ? step : root;
694
- var {
695
- name,
696
- path,
697
- contentType,
698
- fileExtension,
699
- wrapInStep
700
- } = message.data;
701
- this.writeAttachmentForItem(name, path, {
702
- contentType,
703
- fileExtension
704
- }, item, wrapInStep);
705
- });
706
- _defineProperty(this, "writeAttachmentForItem", function (attachmentName, attachmentContentOrPath, options, item) {
707
- var _options$fileExtensio;
708
- var wrapInStepAttachment = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
709
- var isPath = typeof attachmentContentOrPath === "string";
710
- var fileExtension = (_options$fileExtensio = options.fileExtension) !== null && _options$fileExtensio !== void 0 ? _options$fileExtensio : isPath ? (0, _path.extname)(attachmentContentOrPath) : undefined;
711
- var attachmentFileName = (0, _attachments.buildAttachmentFileName)({
712
- contentType: options.contentType,
713
- fileExtension
714
- });
715
- if (isPath) {
716
- _this.writer.writeAttachmentFromPath(attachmentFileName, attachmentContentOrPath);
717
- } else {
718
- _this.writer.writeAttachment(attachmentFileName, attachmentContentOrPath);
719
- }
720
- var attachment = {
721
- name: attachmentName,
722
- source: attachmentFileName,
723
- type: options.contentType
724
- };
725
- if (wrapInStepAttachment) {
726
- item.steps.push({
727
- name: attachmentName,
728
- attachments: [attachment]
729
- });
730
- } else {
731
- item.attachments.push(attachment);
732
- }
398
+ _classPrivateFieldInitSpec(this, _handleStartStepMessage, (rootUuid, message) => {
399
+ this.startStep(rootUuid, undefined, _objectSpread({}, message));
733
400
  });
734
- _defineProperty(this, "startScopeWithUuid", function (uuid) {
735
- var {
736
- manual,
737
- parent
738
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
739
- var newScope = _this.state.setScope(uuid);
740
- if (!manual) {
741
- var _this$contextProvider;
742
- parent = (_this$contextProvider = _this.contextProvider.getScope()) !== null && _this$contextProvider !== void 0 ? _this$contextProvider : undefined;
743
- _this.contextProvider.addScope(uuid);
401
+ _classPrivateFieldInitSpec(this, _handleStopStepMessage, (rootUuid, message) => {
402
+ var stepUuid = this.currentStep(rootUuid);
403
+ if (!stepUuid) {
404
+ // eslint-disable-next-line no-console
405
+ console.error("could not handle step stop message: no step is running");
406
+ return;
744
407
  }
745
- if (parent) {
746
- var parentScope = _this.state.getScope(parent);
747
- if (parentScope) {
748
- _this.linkScopes(parentScope, newScope);
408
+ this.updateStep(stepUuid, result => {
409
+ if (message.status && !result.status) {
410
+ result.status = message.status;
749
411
  }
750
- }
751
- return uuid;
752
- });
753
- _defineProperty(this, "resolveScope", scopeUuid => {
754
- var _scopeUuid;
755
- if (scopeUuid === null) {
756
- return null;
757
- }
758
- scopeUuid = (_scopeUuid = scopeUuid) !== null && _scopeUuid !== void 0 ? _scopeUuid : this.contextProvider.getScope();
759
- return scopeUuid ? this.state.getScope(scopeUuid) : null;
760
- });
761
- _defineProperty(this, "removeScopeFromParent", scope => {
762
- var _scope$parent;
763
- var {
764
- subScopes
765
- } = (_scope$parent = scope.parent) !== null && _scope$parent !== void 0 ? _scope$parent : {};
766
- if (subScopes) {
767
- var scopeIndex = subScopes.indexOf(scope);
768
- if (scopeIndex !== -1) {
769
- subScopes.splice(scopeIndex, 1);
412
+ if (message.statusDetails) {
413
+ result.statusDetails = _objectSpread(_objectSpread({}, result.statusDetails), message.statusDetails);
770
414
  }
771
- }
772
- });
773
- _defineProperty(this, "removeFixtureFromScope", (_ref10, wrappedFixture) => {
774
- var {
775
- fixtures
776
- } = _ref10;
777
- var fixtureIndex = fixtures.indexOf(wrappedFixture);
778
- if (fixtureIndex !== -1) {
779
- fixtures.splice(fixtureIndex, 1);
780
- }
781
- });
782
- _defineProperty(this, "setUpFixtureDedicatedScope", (wrappedFixture, tests, parentScope) => {
783
- var scope = this.state.setScope(wrappedFixture.uuid, {
784
- fixtures: [wrappedFixture],
785
- tests: [...(tests !== null && tests !== void 0 ? tests : [])]
786
415
  });
787
- wrappedFixture.scope = scope;
788
- if (parentScope) {
789
- this.linkScopes(parentScope, scope);
790
- }
791
- });
792
- _defineProperty(this, "linkScopes", (parent, child) => {
793
- child.parent = parent;
794
- parent.subScopes.push(child);
416
+ this.stopStep(stepUuid, message.stop);
417
+ });
418
+ _classPrivateFieldInitSpec(this, _handleAttachmentContentMessage, (rootUuid, message) => {
419
+ this.writeAttachment(rootUuid, undefined, message.name, Buffer.from(message.content, message.encoding), {
420
+ encoding: message.encoding,
421
+ contentType: message.contentType,
422
+ fileExtension: message.fileExtension,
423
+ wrapInStep: message.wrapInStep,
424
+ timestamp: message.timestamp
425
+ });
795
426
  });
796
- _defineProperty(this, "linkFixturesToScope", (wrappedFixtures, scope, extraTests) => {
797
- for (var fixture of wrappedFixtures) {
798
- this.linkFixtureToScope(fixture, scope, extraTests);
799
- }
427
+ _classPrivateFieldInitSpec(this, _handleAttachmentPathMessage, (rootUuid, message) => {
428
+ this.writeAttachment(rootUuid, undefined, message.name, message.path, {
429
+ contentType: message.contentType,
430
+ fileExtension: message.fileExtension,
431
+ wrapInStep: message.wrapInStep,
432
+ timestamp: message.timestamp
433
+ });
800
434
  });
801
- _defineProperty(this, "linkFixtureToScope", (wrappedFixture, scope, extraTests) => {
802
- if (wrappedFixture.scope) {
803
- var fixtureIndex = wrappedFixture.scope.fixtures.indexOf(wrappedFixture);
804
- if (fixtureIndex !== -1) {
805
- wrappedFixture.scope.fixtures.splice(fixtureIndex, 1);
806
- }
807
- }
808
- wrappedFixture.scope = scope;
809
- scope.fixtures.push(wrappedFixture);
810
- if (extraTests) {
811
- this.linkTestsToScope(scope, extraTests);
435
+ _classPrivateFieldInitSpec(this, _findParent, (rootUuid, parentStepUuid) => {
436
+ var root = this.state.getExecutionItem(rootUuid);
437
+ if (!root) {
438
+ return;
812
439
  }
813
- });
814
- _defineProperty(this, "stopFixtureObj", (fixture, uuid, stop) => {
815
- fixture.stop = stop !== null && stop !== void 0 ? stop : Date.now();
816
- fixture.stage = _model.Stage.FINISHED;
817
- this.contextProvider.removeFixture(uuid);
818
- });
819
- _defineProperty(this, "writeAllFixturesOfScope", root => {
820
- var stack = [root];
821
- for (var scope = stack.pop(); scope; scope = stack.pop()) {
822
- this.writeFixturesOfScope(scope);
823
- this.state.deleteScope(scope.uuid);
440
+ if (parentStepUuid === null) {
441
+ return root;
442
+ } else if (parentStepUuid === undefined) {
443
+ var _stepUuid = this.currentStep(rootUuid);
444
+ return _stepUuid ? this.state.getStepResult(_stepUuid) : root;
445
+ } else {
446
+ return this.state.getStepResult(parentStepUuid);
824
447
  }
825
448
  });
826
- _defineProperty(this, "writeFixturesOfScope", _ref11 => {
449
+ _classPrivateFieldInitSpec(this, _writeFixturesOfScope, _ref2 => {
827
450
  var {
828
451
  fixtures,
829
452
  tests
830
- } = _ref11;
453
+ } = _ref2;
831
454
  var writtenFixtures = new Set();
832
455
  if (tests.length) {
833
456
  for (var wrappedFixture of fixtures) {
834
457
  if (!writtenFixtures.has(wrappedFixture.uuid)) {
835
- this.writeContainer(tests, wrappedFixture);
458
+ _classPrivateFieldGet(_writeContainer, this).call(this, tests, wrappedFixture);
836
459
  this.state.deleteFixtureResult(wrappedFixture.uuid);
837
460
  writtenFixtures.add(wrappedFixture.uuid);
838
461
  }
839
462
  }
840
463
  }
841
464
  });
842
- _defineProperty(this, "writeContainer", (tests, wrappedFixture) => {
465
+ _classPrivateFieldInitSpec(this, _writeContainer, (tests, wrappedFixture) => {
843
466
  var fixture = wrappedFixture.value;
844
467
  var befores = wrappedFixture.type === "before" ? [wrappedFixture.value] : [];
845
468
  var afters = wrappedFixture.type === "after" ? [wrappedFixture.value] : [];
846
469
  this.writer.writeGroup({
847
- uuid: (0, _utils.randomUuid)(),
470
+ uuid: wrappedFixture.uuid,
848
471
  name: fixture.name,
849
472
  children: [...new Set(tests)],
850
473
  befores,
851
474
  afters
852
475
  });
853
476
  });
854
- _defineProperty(this, "addStepToItem", (data, rootUuid, parent) => {
855
- var stepResult = _objectSpread(_objectSpread({}, (0, _factory.createStepResult)()), {}, {
856
- start: Date.now()
857
- }, data);
858
- parent.steps.push(stepResult);
859
- var stepUuid = (0, _utils.randomUuid)();
860
- this.state.setStepResult(stepUuid, stepResult);
861
- this.contextProvider.addStep(stepUuid, rootUuid);
862
- return stepUuid;
863
- });
864
- _defineProperty(this, "logMissingStepRoot", (uuid, op) => {
865
- if (uuid) {
866
- // eslint-disable-next-line no-console
867
- console.error("No test or fixture of (".concat(uuid, ") to ").concat(op, " the step!"));
868
- } else {
869
- // eslint-disable-next-line no-console
870
- console.error("No current step to ".concat(op, "!"));
871
- }
872
- });
873
- _defineProperty(this, "formatLinks", links => {
874
- if (!this.links.length) {
875
- return links;
876
- }
877
- return links.map(link => {
878
- var _this$links, _this$links$find;
879
- // TODO:
880
- // @ts-ignore
881
- var matcher = (_this$links = this.links) === null || _this$links === void 0 || (_this$links$find = _this$links.find) === null || _this$links$find === void 0 ? void 0 : _this$links$find.call(_this$links, _ref12 => {
882
- var {
883
- type
884
- } = _ref12;
885
- return type === link.type;
886
- });
887
-
888
- // TODO:
889
- if (!matcher || link.url.startsWith("http")) {
890
- return link;
891
- }
892
- var url = matcher.urlTemplate.replace("%s", link.url);
893
-
894
- // we shouldn't need to reassign already assigned name
895
- if (link.name || !matcher.nameTemplate) {
896
- return _objectSpread(_objectSpread({}, link), {}, {
897
- url
898
- });
899
- }
900
- var name = matcher.nameTemplate.replace("%s", link.url);
901
- return _objectSpread(_objectSpread({}, link), {}, {
902
- name,
903
- url
904
- });
905
- });
906
- });
907
- _defineProperty(this, "introduceTestIntoScopes", (testUuid, scopeUuid) => {
908
- var scope = this.state.getScope(scopeUuid);
909
- if (!scope) {
910
- // eslint-disable-next-line no-console
911
- console.error("No scope ".concat(scopeUuid, " to introduce the test into"));
912
- return;
913
- }
914
- this.linkTestsToScope(scope, [testUuid]);
915
- });
916
- _defineProperty(this, "linkTestsToScope", (scope, testUuids) => {
917
- for (var curScope = scope; curScope; curScope = curScope.parent) {
918
- curScope.tests.splice(curScope.tests.length, 0, ...testUuids);
919
- }
920
- });
921
477
  this.writer = (0, _loader.resolveWriter)(writer);
922
478
  this.notifier = new _Notifier.Notifier({
923
479
  listeners
924
480
  });
925
- this.links = _links;
926
481
  this.categories = categories;
927
482
  this.environmentInfo = environmentInfo;
928
- this.contextProvider = contextProvider;
929
- }
930
- createTestResult(result) {
931
- var uuid = (0, _utils.randomUuid)();
932
- return _objectSpread(_objectSpread({}, (0, _factory.createTestResult)(uuid)), {}, {
933
- start: Date.now()
934
- }, (0, _utils.deepClone)(result));
483
+ this.linkConfig = _links;
935
484
  }
936
485
  }
937
486
  exports.ReporterRuntime = ReporterRuntime;