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