@allurereport/core 3.0.0-beta.9 → 3.0.0

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.
@@ -9,9 +9,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _DefaultAllureStore_testResults, _DefaultAllureStore_attachments, _DefaultAllureStore_attachmentContents, _DefaultAllureStore_testCases, _DefaultAllureStore_metadata, _DefaultAllureStore_history, _DefaultAllureStore_known, _DefaultAllureStore_fixtures, _DefaultAllureStore_defaultLabels, _DefaultAllureStore_eventEmitter;
13
- import { compareBy, nullsLast, ordinal, reverse } from "@allurereport/core-api";
14
- import { md5 } from "@allurereport/plugin-api";
12
+ var _DefaultAllureStore_instances, _DefaultAllureStore_testResults, _DefaultAllureStore_attachments, _DefaultAllureStore_attachmentContents, _DefaultAllureStore_testCases, _DefaultAllureStore_metadata, _DefaultAllureStore_history, _DefaultAllureStore_known, _DefaultAllureStore_fixtures, _DefaultAllureStore_defaultLabels, _DefaultAllureStore_environment, _DefaultAllureStore_environmentsConfig, _DefaultAllureStore_reportVariables, _DefaultAllureStore_realtimeDispatcher, _DefaultAllureStore_realtimeSubscriber, _DefaultAllureStore_globalAttachments, _DefaultAllureStore_globalErrors, _DefaultAllureStore_globalExitCode, _DefaultAllureStore_qualityGateResultsByRules, _DefaultAllureStore_historyPoints, _DefaultAllureStore_environments, _DefaultAllureStore_addEnvironments;
13
+ import { DEFAULT_ENVIRONMENT, compareBy, getWorstStatus, htrsByTr, matchEnvironment, nullsLast, ordinal, reverse, } from "@allurereport/core-api";
14
+ import { md5, } from "@allurereport/plugin-api";
15
+ import { isFlaky } from "../utils/flaky.js";
16
+ import { getStatusTransition } from "../utils/new.js";
15
17
  import { testFixtureResultRawToState, testResultRawToState } from "./convert.js";
16
18
  const index = (indexMap, key, ...items) => {
17
19
  if (key) {
@@ -22,8 +24,47 @@ const index = (indexMap, key, ...items) => {
22
24
  current.push(...items);
23
25
  }
24
26
  };
27
+ const wasStartedEarlier = (first, second) => first.start === undefined || second.start === undefined || first.start < second.start;
28
+ const hidePreviousAttempt = (state, testResult) => {
29
+ const { environment, historyId } = testResult;
30
+ if (environment) {
31
+ if (!state.has(environment)) {
32
+ state.set(environment, new Map());
33
+ }
34
+ if (historyId) {
35
+ const historyIdToLastAttemptResult = state.get(environment);
36
+ const currentLastAttemptResult = historyIdToLastAttemptResult.get(historyId);
37
+ if (currentLastAttemptResult) {
38
+ if (wasStartedEarlier(currentLastAttemptResult, testResult)) {
39
+ historyIdToLastAttemptResult.set(historyId, testResult);
40
+ currentLastAttemptResult.hidden = true;
41
+ }
42
+ else {
43
+ testResult.hidden = true;
44
+ }
45
+ }
46
+ else {
47
+ historyIdToLastAttemptResult.set(historyId, testResult);
48
+ }
49
+ }
50
+ }
51
+ };
52
+ export const mapToObject = (map) => {
53
+ const result = {};
54
+ map.forEach((value, key) => {
55
+ result[key] = value;
56
+ });
57
+ return result;
58
+ };
59
+ export const updateMapWithRecord = (map, record) => {
60
+ Object.entries(record).forEach(([key, value]) => {
61
+ map.set(key, value);
62
+ });
63
+ return map;
64
+ };
25
65
  export class DefaultAllureStore {
26
66
  constructor(params) {
67
+ _DefaultAllureStore_instances.add(this);
27
68
  _DefaultAllureStore_testResults.set(this, void 0);
28
69
  _DefaultAllureStore_attachments.set(this, void 0);
29
70
  _DefaultAllureStore_attachmentContents.set(this, void 0);
@@ -33,26 +74,95 @@ export class DefaultAllureStore {
33
74
  _DefaultAllureStore_known.set(this, void 0);
34
75
  _DefaultAllureStore_fixtures.set(this, void 0);
35
76
  _DefaultAllureStore_defaultLabels.set(this, {});
36
- _DefaultAllureStore_eventEmitter.set(this, void 0);
77
+ _DefaultAllureStore_environment.set(this, void 0);
78
+ _DefaultAllureStore_environmentsConfig.set(this, {});
79
+ _DefaultAllureStore_reportVariables.set(this, {});
80
+ _DefaultAllureStore_realtimeDispatcher.set(this, void 0);
81
+ _DefaultAllureStore_realtimeSubscriber.set(this, void 0);
37
82
  this.indexTestResultByTestCase = new Map();
38
- this.indexLatestTestResultByHistoryId = new Map();
83
+ this.indexLatestEnvTestResultByHistoryId = new Map();
39
84
  this.indexTestResultByHistoryId = new Map();
40
85
  this.indexAttachmentByTestResult = new Map();
41
86
  this.indexAttachmentByFixture = new Map();
42
87
  this.indexFixturesByTestResult = new Map();
43
88
  this.indexKnownByHistoryId = new Map();
44
- const { history = [], known = [], eventEmitter, defaultLabels } = params ?? {};
89
+ _DefaultAllureStore_globalAttachments.set(this, []);
90
+ _DefaultAllureStore_globalErrors.set(this, []);
91
+ _DefaultAllureStore_globalExitCode.set(this, void 0);
92
+ _DefaultAllureStore_qualityGateResultsByRules.set(this, {});
93
+ _DefaultAllureStore_historyPoints.set(this, []);
94
+ _DefaultAllureStore_environments.set(this, []);
95
+ const { history, known = [], realtimeDispatcher, realtimeSubscriber, defaultLabels = {}, environment, environmentsConfig = {}, reportVariables = {}, } = params ?? {};
96
+ const environments = Object.keys(environmentsConfig)
97
+ .concat(environment ?? "")
98
+ .filter(Boolean);
45
99
  __classPrivateFieldSet(this, _DefaultAllureStore_testResults, new Map(), "f");
46
100
  __classPrivateFieldSet(this, _DefaultAllureStore_attachments, new Map(), "f");
47
101
  __classPrivateFieldSet(this, _DefaultAllureStore_attachmentContents, new Map(), "f");
48
102
  __classPrivateFieldSet(this, _DefaultAllureStore_testCases, new Map(), "f");
49
103
  __classPrivateFieldSet(this, _DefaultAllureStore_metadata, new Map(), "f");
50
104
  __classPrivateFieldSet(this, _DefaultAllureStore_fixtures, new Map(), "f");
51
- __classPrivateFieldSet(this, _DefaultAllureStore_history, [...history].sort(compareBy("timestamp", reverse(ordinal()))), "f");
105
+ __classPrivateFieldSet(this, _DefaultAllureStore_history, history, "f");
52
106
  __classPrivateFieldSet(this, _DefaultAllureStore_known, [...known], "f");
53
107
  __classPrivateFieldGet(this, _DefaultAllureStore_known, "f").forEach((ktf) => index(this.indexKnownByHistoryId, ktf.historyId, ktf));
54
- __classPrivateFieldSet(this, _DefaultAllureStore_eventEmitter, eventEmitter, "f");
55
- __classPrivateFieldSet(this, _DefaultAllureStore_defaultLabels, defaultLabels ?? {}, "f");
108
+ __classPrivateFieldSet(this, _DefaultAllureStore_realtimeDispatcher, realtimeDispatcher, "f");
109
+ __classPrivateFieldSet(this, _DefaultAllureStore_realtimeSubscriber, realtimeSubscriber, "f");
110
+ __classPrivateFieldSet(this, _DefaultAllureStore_defaultLabels, defaultLabels, "f");
111
+ __classPrivateFieldSet(this, _DefaultAllureStore_environmentsConfig, environmentsConfig, "f");
112
+ __classPrivateFieldSet(this, _DefaultAllureStore_environment, environment, "f");
113
+ __classPrivateFieldSet(this, _DefaultAllureStore_reportVariables, reportVariables, "f");
114
+ __classPrivateFieldGet(this, _DefaultAllureStore_instances, "m", _DefaultAllureStore_addEnvironments).call(this, environments);
115
+ __classPrivateFieldGet(this, _DefaultAllureStore_realtimeSubscriber, "f")?.onQualityGateResults(async (results) => {
116
+ results.forEach((result) => {
117
+ __classPrivateFieldGet(this, _DefaultAllureStore_qualityGateResultsByRules, "f")[result.rule] = result;
118
+ });
119
+ });
120
+ __classPrivateFieldGet(this, _DefaultAllureStore_realtimeSubscriber, "f")?.onGlobalExitCode(async (exitCode) => {
121
+ __classPrivateFieldSet(this, _DefaultAllureStore_globalExitCode, exitCode, "f");
122
+ });
123
+ __classPrivateFieldGet(this, _DefaultAllureStore_realtimeSubscriber, "f")?.onGlobalError(async (error) => {
124
+ __classPrivateFieldGet(this, _DefaultAllureStore_globalErrors, "f").push(error);
125
+ });
126
+ __classPrivateFieldGet(this, _DefaultAllureStore_realtimeSubscriber, "f")?.onGlobalAttachment(async (attachment) => {
127
+ const attachmentLink = {
128
+ id: md5(attachment.getOriginalFileName()),
129
+ missed: false,
130
+ used: false,
131
+ ext: attachment.getExtension(),
132
+ originalFileName: attachment.getOriginalFileName(),
133
+ contentType: attachment.getContentType(),
134
+ contentLength: attachment.getContentLength(),
135
+ };
136
+ __classPrivateFieldGet(this, _DefaultAllureStore_attachmentContents, "f").set(attachmentLink.id, attachment);
137
+ __classPrivateFieldGet(this, _DefaultAllureStore_globalAttachments, "f").push(attachmentLink);
138
+ });
139
+ }
140
+ async readHistory() {
141
+ if (!__classPrivateFieldGet(this, _DefaultAllureStore_history, "f")) {
142
+ return [];
143
+ }
144
+ __classPrivateFieldSet(this, _DefaultAllureStore_historyPoints, (await __classPrivateFieldGet(this, _DefaultAllureStore_history, "f").readHistory()) ?? [], "f");
145
+ __classPrivateFieldGet(this, _DefaultAllureStore_historyPoints, "f").sort(compareBy("timestamp", reverse(ordinal())));
146
+ return __classPrivateFieldGet(this, _DefaultAllureStore_historyPoints, "f");
147
+ }
148
+ async appendHistory(history) {
149
+ if (!__classPrivateFieldGet(this, _DefaultAllureStore_history, "f")) {
150
+ return;
151
+ }
152
+ __classPrivateFieldGet(this, _DefaultAllureStore_historyPoints, "f").push(history);
153
+ await __classPrivateFieldGet(this, _DefaultAllureStore_history, "f").appendHistory(history);
154
+ }
155
+ async qualityGateResults() {
156
+ return Object.values(__classPrivateFieldGet(this, _DefaultAllureStore_qualityGateResultsByRules, "f"));
157
+ }
158
+ async globalExitCode() {
159
+ return __classPrivateFieldGet(this, _DefaultAllureStore_globalExitCode, "f");
160
+ }
161
+ async allGlobalErrors() {
162
+ return __classPrivateFieldGet(this, _DefaultAllureStore_globalErrors, "f");
163
+ }
164
+ async allGlobalAttachments() {
165
+ return __classPrivateFieldGet(this, _DefaultAllureStore_globalAttachments, "f");
56
166
  }
57
167
  async visitTestResult(raw, context) {
58
168
  const attachmentLinks = [];
@@ -75,26 +185,18 @@ export class DefaultAllureStore {
75
185
  }
76
186
  });
77
187
  }
78
- __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f").set(testResult.id, testResult);
79
- if (testResult.historyId) {
80
- const maybeOther = this.indexLatestTestResultByHistoryId.get(testResult.historyId);
81
- if (maybeOther) {
82
- if (maybeOther.start === undefined || testResult.start === undefined || maybeOther.start < testResult.start) {
83
- this.indexLatestTestResultByHistoryId.set(testResult.historyId, testResult);
84
- maybeOther.hidden = true;
85
- }
86
- else {
87
- testResult.hidden = true;
88
- }
89
- }
90
- else {
91
- this.indexLatestTestResultByHistoryId.set(testResult.historyId, testResult);
92
- }
188
+ testResult.environment = __classPrivateFieldGet(this, _DefaultAllureStore_environment, "f") || matchEnvironment(__classPrivateFieldGet(this, _DefaultAllureStore_environmentsConfig, "f"), testResult);
189
+ const trHistory = await this.historyByTr(testResult);
190
+ if (trHistory) {
191
+ testResult.transition = getStatusTransition(testResult, trHistory);
192
+ testResult.flaky = isFlaky(testResult, trHistory);
93
193
  }
194
+ __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f").set(testResult.id, testResult);
195
+ hidePreviousAttempt(this.indexLatestEnvTestResultByHistoryId, testResult);
94
196
  index(this.indexTestResultByTestCase, testResult.testCase?.id, testResult);
95
197
  index(this.indexTestResultByHistoryId, testResult.historyId, testResult);
96
198
  index(this.indexAttachmentByTestResult, testResult.id, ...attachmentLinks);
97
- __classPrivateFieldGet(this, _DefaultAllureStore_eventEmitter, "f")?.emit("testResult", testResult.id);
199
+ __classPrivateFieldGet(this, _DefaultAllureStore_realtimeDispatcher, "f")?.sendTestResult(testResult.id);
98
200
  }
99
201
  async visitTestFixtureResult(result, context) {
100
202
  const attachmentLinks = [];
@@ -107,7 +209,7 @@ export class DefaultAllureStore {
107
209
  index(this.indexFixturesByTestResult, trId, testFixtureResult);
108
210
  });
109
211
  index(this.indexAttachmentByFixture, testFixtureResult.id, ...attachmentLinks);
110
- __classPrivateFieldGet(this, _DefaultAllureStore_eventEmitter, "f")?.emit("testFixtureResult", testFixtureResult.id);
212
+ __classPrivateFieldGet(this, _DefaultAllureStore_realtimeDispatcher, "f")?.sendTestFixtureResult(testFixtureResult.id);
111
213
  }
112
214
  async visitAttachmentFile(resultFile, context) {
113
215
  const originalFileName = resultFile.getOriginalFileName();
@@ -132,7 +234,7 @@ export class DefaultAllureStore {
132
234
  contentLength: resultFile.getContentLength(),
133
235
  });
134
236
  }
135
- __classPrivateFieldGet(this, _DefaultAllureStore_eventEmitter, "f")?.emit("attachmentFile", id);
237
+ __classPrivateFieldGet(this, _DefaultAllureStore_realtimeDispatcher, "f")?.sendAttachmentFile(id);
136
238
  }
137
239
  async visitMetadata(metadata) {
138
240
  Object.keys(metadata).forEach((key) => __classPrivateFieldGet(this, _DefaultAllureStore_metadata, "f").set(key, metadata[key]));
@@ -142,15 +244,28 @@ export class DefaultAllureStore {
142
244
  }
143
245
  async allTestResults(options = { includeHidden: false }) {
144
246
  const { includeHidden } = options;
145
- const result = Array.from(__classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f").values());
146
- return includeHidden ? result : result.filter((tr) => !tr.hidden);
247
+ const result = [];
248
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
249
+ if (!includeHidden && tr.hidden) {
250
+ continue;
251
+ }
252
+ result.push(tr);
253
+ }
254
+ return result;
147
255
  }
148
256
  async allAttachments(options = {}) {
149
257
  const { includeMissed = false, includeUnused = false } = options;
150
- const attachments = Array.from(__classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f").values());
151
- return attachments
152
- .filter((link) => (!includeMissed ? !link.missed : true))
153
- .filter((link) => (!includeUnused ? link.used : true));
258
+ const filteredAttachments = [];
259
+ for (const [, attachment] of __classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f")) {
260
+ if (!includeMissed && attachment.missed) {
261
+ continue;
262
+ }
263
+ if (!includeUnused && !attachment.used) {
264
+ continue;
265
+ }
266
+ filteredAttachments.push(attachment);
267
+ }
268
+ return filteredAttachments;
154
269
  }
155
270
  async allMetadata() {
156
271
  const result = {};
@@ -161,11 +276,53 @@ export class DefaultAllureStore {
161
276
  return Array.from(__classPrivateFieldGet(this, _DefaultAllureStore_fixtures, "f").values());
162
277
  }
163
278
  async allHistoryDataPoints() {
164
- return __classPrivateFieldGet(this, _DefaultAllureStore_history, "f");
279
+ return __classPrivateFieldGet(this, _DefaultAllureStore_historyPoints, "f");
280
+ }
281
+ async allHistoryDataPointsByEnvironment(environment) {
282
+ return __classPrivateFieldGet(this, _DefaultAllureStore_historyPoints, "f").reduce((result, dp) => {
283
+ const filteredTestResults = [];
284
+ for (const tr of Object.values(dp.testResults)) {
285
+ const hasLabels = tr.labels && tr.labels.length > 0;
286
+ const trEnvironment = tr.environment ??
287
+ (hasLabels ? matchEnvironment(__classPrivateFieldGet(this, _DefaultAllureStore_environmentsConfig, "f"), tr) : undefined);
288
+ if (trEnvironment === environment) {
289
+ filteredTestResults.push(tr);
290
+ }
291
+ }
292
+ const hasNoEnvironmentTestResults = filteredTestResults.length === 0;
293
+ result.push({
294
+ ...dp,
295
+ testResults: hasNoEnvironmentTestResults
296
+ ? {}
297
+ : filteredTestResults.reduce((acc, tr) => {
298
+ acc[tr.historyId] = tr;
299
+ return acc;
300
+ }, {}),
301
+ knownTestCaseIds: hasNoEnvironmentTestResults ? [] : filteredTestResults.map((tr) => tr.id),
302
+ });
303
+ return result;
304
+ }, []);
165
305
  }
166
306
  async allKnownIssues() {
167
307
  return __classPrivateFieldGet(this, _DefaultAllureStore_known, "f");
168
308
  }
309
+ async allNewTestResults() {
310
+ const newTrs = [];
311
+ const allHistoryDps = await this.allHistoryDataPoints();
312
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
313
+ if (tr.hidden) {
314
+ continue;
315
+ }
316
+ if (!tr.historyId) {
317
+ newTrs.push(tr);
318
+ continue;
319
+ }
320
+ if (!allHistoryDps.some((dp) => dp.testResults[tr.historyId])) {
321
+ newTrs.push(tr);
322
+ }
323
+ }
324
+ return newTrs;
325
+ }
169
326
  async testCaseById(tcId) {
170
327
  return __classPrivateFieldGet(this, _DefaultAllureStore_testCases, "f").get(tcId);
171
328
  }
@@ -187,8 +344,7 @@ export class DefaultAllureStore {
187
344
  async attachmentsByTrId(trId) {
188
345
  return this.indexAttachmentByTestResult.get(trId) ?? [];
189
346
  }
190
- async retriesByTrId(trId) {
191
- const tr = await this.testResultById(trId);
347
+ async retriesByTr(tr) {
192
348
  if (!tr || tr.hidden || !tr.historyId) {
193
349
  return [];
194
350
  }
@@ -196,21 +352,37 @@ export class DefaultAllureStore {
196
352
  .filter((r) => r.hidden)
197
353
  .sort(nullsLast(compareBy("start", reverse(ordinal()))));
198
354
  }
355
+ async retriesByTrId(trId) {
356
+ const tr = await this.testResultById(trId);
357
+ return tr ? this.retriesByTr(tr) : [];
358
+ }
359
+ async historyByTr(tr) {
360
+ if (!__classPrivateFieldGet(this, _DefaultAllureStore_history, "f")) {
361
+ return undefined;
362
+ }
363
+ return htrsByTr(__classPrivateFieldGet(this, _DefaultAllureStore_historyPoints, "f"), tr);
364
+ }
199
365
  async historyByTrId(trId) {
200
366
  const tr = await this.testResultById(trId);
201
- if (!tr?.historyId) {
202
- return [];
367
+ if (!tr) {
368
+ return undefined;
203
369
  }
204
- return [...__classPrivateFieldGet(this, _DefaultAllureStore_history, "f")]
205
- .filter((dp) => !!dp.testResults[tr.historyId])
206
- .map((dp) => ({ ...dp.testResults[tr.historyId] }));
370
+ return this.historyByTr(tr);
207
371
  }
208
372
  async fixturesByTrId(trId) {
209
373
  return this.indexFixturesByTestResult.get(trId) ?? [];
210
374
  }
211
375
  async failedTestResults() {
212
- const allTestResults = await this.allTestResults();
213
- return allTestResults.filter(({ status }) => status === "failed" || status === "broken");
376
+ const failedTrs = [];
377
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
378
+ if (tr.hidden) {
379
+ continue;
380
+ }
381
+ if (tr.status === "failed" || tr.status === "broken") {
382
+ failedTrs.push(tr);
383
+ }
384
+ }
385
+ return failedTrs;
214
386
  }
215
387
  async unknownFailedTestResults() {
216
388
  const failedTestResults = await this.failedTestResults();
@@ -224,12 +396,14 @@ export class DefaultAllureStore {
224
396
  const results = {
225
397
  _: [],
226
398
  };
227
- const all = await this.allTestResults();
228
- all.forEach((test) => {
399
+ for (const [, test] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
400
+ if (test.hidden) {
401
+ continue;
402
+ }
229
403
  const targetLabels = (test.labels ?? []).filter((label) => label.name === labelName);
230
404
  if (targetLabels.length === 0) {
231
405
  results._.push(test);
232
- return;
406
+ continue;
233
407
  }
234
408
  targetLabels.forEach((label) => {
235
409
  if (!results[label.value]) {
@@ -237,18 +411,235 @@ export class DefaultAllureStore {
237
411
  }
238
412
  results[label.value].push(test);
239
413
  });
240
- });
414
+ }
241
415
  return results;
242
416
  }
243
- async testsStatistic() {
244
- const all = await this.allTestResults();
245
- return all.reduce((acc, test) => {
246
- if (!acc[test.status]) {
247
- acc[test.status] = 0;
417
+ async testsStatistic(filter) {
418
+ const statistic = { total: 0 };
419
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
420
+ if (tr.hidden) {
421
+ continue;
248
422
  }
249
- acc[test.status]++;
423
+ if (filter && !filter(tr)) {
424
+ continue;
425
+ }
426
+ statistic.total++;
427
+ const retries = await this.retriesByTr(tr);
428
+ if (retries.length > 0) {
429
+ statistic.retries = (statistic.retries ?? 0) + 1;
430
+ }
431
+ if (tr.flaky) {
432
+ statistic.flaky = (statistic.flaky ?? 0) + 1;
433
+ }
434
+ if (tr.transition === "new") {
435
+ statistic.new = (statistic.new ?? 0) + 1;
436
+ }
437
+ if (!statistic[tr.status]) {
438
+ statistic[tr.status] = 0;
439
+ }
440
+ statistic[tr.status]++;
441
+ }
442
+ return statistic;
443
+ }
444
+ async allEnvironments() {
445
+ return __classPrivateFieldGet(this, _DefaultAllureStore_environments, "f");
446
+ }
447
+ async testResultsByEnvironment(env, options = { includeHidden: false }) {
448
+ const trs = [];
449
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
450
+ if (!options.includeHidden && tr.hidden) {
451
+ continue;
452
+ }
453
+ if (tr.environment === env) {
454
+ trs.push(tr);
455
+ }
456
+ }
457
+ return trs;
458
+ }
459
+ async allTestEnvGroups() {
460
+ const trByTestCaseId = {};
461
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
462
+ const testCaseId = tr?.testCase?.id;
463
+ if (!testCaseId) {
464
+ continue;
465
+ }
466
+ if (trByTestCaseId[testCaseId]) {
467
+ trByTestCaseId[testCaseId].push(tr);
468
+ }
469
+ else {
470
+ trByTestCaseId[testCaseId] = [tr];
471
+ }
472
+ }
473
+ return Object.entries(trByTestCaseId).reduce((acc, [testCaseId, trs]) => {
474
+ if (trs.length === 0) {
475
+ return acc;
476
+ }
477
+ const { fullName, name } = trs[0];
478
+ const envGroup = {
479
+ id: testCaseId,
480
+ fullName,
481
+ name,
482
+ status: getWorstStatus(trs.map(({ status }) => status)) ?? "passed",
483
+ testResultsByEnv: {},
484
+ };
485
+ trs.forEach((tr) => {
486
+ const env = tr.environment || __classPrivateFieldGet(this, _DefaultAllureStore_environment, "f") || matchEnvironment(__classPrivateFieldGet(this, _DefaultAllureStore_environmentsConfig, "f"), tr);
487
+ envGroup.testResultsByEnv[env] = tr.id;
488
+ });
489
+ acc.push(envGroup);
250
490
  return acc;
251
- }, { total: all.length });
491
+ }, []);
492
+ }
493
+ async allVariables() {
494
+ return __classPrivateFieldGet(this, _DefaultAllureStore_reportVariables, "f");
495
+ }
496
+ async envVariables(env) {
497
+ return {
498
+ ...__classPrivateFieldGet(this, _DefaultAllureStore_reportVariables, "f"),
499
+ ...(__classPrivateFieldGet(this, _DefaultAllureStore_environmentsConfig, "f")?.[env]?.variables ?? {}),
500
+ };
501
+ }
502
+ dumpState() {
503
+ const storeDump = {
504
+ testResults: mapToObject(__classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")),
505
+ attachments: mapToObject(__classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f")),
506
+ testCases: mapToObject(__classPrivateFieldGet(this, _DefaultAllureStore_testCases, "f")),
507
+ fixtures: mapToObject(__classPrivateFieldGet(this, _DefaultAllureStore_fixtures, "f")),
508
+ environments: __classPrivateFieldGet(this, _DefaultAllureStore_environments, "f"),
509
+ reportVariables: __classPrivateFieldGet(this, _DefaultAllureStore_reportVariables, "f"),
510
+ globalAttachments: __classPrivateFieldGet(this, _DefaultAllureStore_globalAttachments, "f"),
511
+ globalErrors: __classPrivateFieldGet(this, _DefaultAllureStore_globalErrors, "f"),
512
+ indexLatestEnvTestResultByHistoryId: {},
513
+ indexAttachmentByTestResult: {},
514
+ indexTestResultByHistoryId: {},
515
+ indexTestResultByTestCase: {},
516
+ indexAttachmentByFixture: {},
517
+ indexFixturesByTestResult: {},
518
+ indexKnownByHistoryId: {},
519
+ qualityGateResultsByRules: __classPrivateFieldGet(this, _DefaultAllureStore_qualityGateResultsByRules, "f"),
520
+ };
521
+ this.indexLatestEnvTestResultByHistoryId.forEach((envMap) => {
522
+ envMap.forEach((tr, historyId) => {
523
+ storeDump.indexLatestEnvTestResultByHistoryId[historyId] = tr.id;
524
+ });
525
+ });
526
+ this.indexAttachmentByFixture.forEach((link, fxId) => {
527
+ storeDump.indexAttachmentByFixture[fxId] = link.map((l) => l.id);
528
+ });
529
+ this.indexAttachmentByTestResult.forEach((links, trId) => {
530
+ storeDump.indexAttachmentByTestResult[trId] = links.map((l) => l.id);
531
+ });
532
+ this.indexTestResultByHistoryId.forEach((trs, historyId) => {
533
+ storeDump.indexTestResultByHistoryId[historyId] = trs.map((tr) => tr.id);
534
+ });
535
+ this.indexTestResultByTestCase.forEach((trs, tcId) => {
536
+ storeDump.indexTestResultByTestCase[tcId] = trs.map((tr) => tr.id);
537
+ });
538
+ this.indexFixturesByTestResult.forEach((fixtures, trId) => {
539
+ storeDump.indexFixturesByTestResult[trId] = fixtures.map((f) => f.id);
540
+ });
541
+ this.indexKnownByHistoryId.forEach((known, historyId) => {
542
+ storeDump.indexKnownByHistoryId[historyId] = known;
543
+ });
544
+ return storeDump;
545
+ }
546
+ async restoreState(stateDump, attachmentsContents = {}) {
547
+ const { testResults, attachments, testCases, fixtures, reportVariables, environments, globalAttachments = [], globalErrors = [], indexAttachmentByTestResult = {}, indexTestResultByHistoryId = {}, indexTestResultByTestCase = {}, indexLatestEnvTestResultByHistoryId = {}, indexAttachmentByFixture = {}, indexFixturesByTestResult = {}, indexKnownByHistoryId = {}, qualityGateResultsByRules = {}, } = stateDump;
548
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f"), testResults);
549
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f"), attachments);
550
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_testCases, "f"), testCases);
551
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_fixtures, "f"), fixtures);
552
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_attachmentContents, "f"), attachmentsContents);
553
+ __classPrivateFieldGet(this, _DefaultAllureStore_instances, "m", _DefaultAllureStore_addEnvironments).call(this, environments);
554
+ __classPrivateFieldGet(this, _DefaultAllureStore_globalAttachments, "f").push(...globalAttachments);
555
+ __classPrivateFieldGet(this, _DefaultAllureStore_globalErrors, "f").push(...globalErrors);
556
+ Object.assign(__classPrivateFieldGet(this, _DefaultAllureStore_reportVariables, "f"), reportVariables);
557
+ Object.entries(indexAttachmentByTestResult).forEach(([trId, links]) => {
558
+ const attachmentsLinks = links.map((id) => __classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f").get(id)).filter(Boolean);
559
+ if (attachmentsLinks.length === 0) {
560
+ return;
561
+ }
562
+ const existingLinks = this.indexAttachmentByTestResult.get(trId);
563
+ if (!existingLinks) {
564
+ this.indexAttachmentByTestResult.set(trId, attachmentsLinks);
565
+ return;
566
+ }
567
+ existingLinks.push(...attachmentsLinks);
568
+ });
569
+ Object.entries(indexTestResultByHistoryId).forEach(([historyId, trIds]) => {
570
+ const trs = trIds.map((id) => __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f").get(id)).filter(Boolean);
571
+ if (trs.length === 0) {
572
+ return;
573
+ }
574
+ const existingTrs = this.indexTestResultByHistoryId.get(historyId);
575
+ if (!existingTrs) {
576
+ this.indexTestResultByHistoryId.set(historyId, trs);
577
+ return;
578
+ }
579
+ existingTrs.push(...trs);
580
+ });
581
+ Object.entries(indexTestResultByTestCase).forEach(([tcId, trIds]) => {
582
+ const trs = trIds.map((id) => __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f").get(id)).filter(Boolean);
583
+ if (trs.length === 0) {
584
+ return;
585
+ }
586
+ const existingTrs = this.indexTestResultByTestCase.get(tcId);
587
+ if (!existingTrs) {
588
+ this.indexTestResultByTestCase.set(tcId, trs);
589
+ return;
590
+ }
591
+ existingTrs.push(...trs);
592
+ });
593
+ Object.entries(indexAttachmentByFixture).forEach(([fxId, attachmentIds]) => {
594
+ const attachmentsLinks = attachmentIds.map((id) => __classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f").get(id)).filter(Boolean);
595
+ if (attachmentsLinks.length === 0) {
596
+ return;
597
+ }
598
+ const existingLinks = this.indexAttachmentByFixture.get(fxId);
599
+ if (!existingLinks) {
600
+ this.indexAttachmentByFixture.set(fxId, attachmentsLinks);
601
+ return;
602
+ }
603
+ existingLinks.push(...attachmentsLinks);
604
+ });
605
+ Object.entries(indexFixturesByTestResult).forEach(([trId, fixtureIds]) => {
606
+ const fxs = fixtureIds.map((id) => __classPrivateFieldGet(this, _DefaultAllureStore_fixtures, "f").get(id)).filter(Boolean);
607
+ if (fxs.length === 0) {
608
+ return;
609
+ }
610
+ const existingFixtures = this.indexFixturesByTestResult.get(trId);
611
+ if (!existingFixtures) {
612
+ this.indexFixturesByTestResult.set(trId, fxs);
613
+ return;
614
+ }
615
+ existingFixtures.push(...fxs);
616
+ });
617
+ Object.entries(indexKnownByHistoryId).forEach(([historyId, knownFailures]) => {
618
+ const existingKnown = this.indexKnownByHistoryId.get(historyId);
619
+ if (!existingKnown) {
620
+ this.indexKnownByHistoryId.set(historyId, knownFailures);
621
+ return;
622
+ }
623
+ existingKnown.push(...knownFailures);
624
+ });
625
+ Object.values(indexLatestEnvTestResultByHistoryId).forEach((trId) => {
626
+ const tr = __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f").get(trId);
627
+ if (!tr) {
628
+ return;
629
+ }
630
+ hidePreviousAttempt(this.indexLatestEnvTestResultByHistoryId, tr);
631
+ });
632
+ Object.assign(__classPrivateFieldGet(this, _DefaultAllureStore_qualityGateResultsByRules, "f"), qualityGateResultsByRules);
252
633
  }
253
634
  }
254
- _DefaultAllureStore_testResults = new WeakMap(), _DefaultAllureStore_attachments = new WeakMap(), _DefaultAllureStore_attachmentContents = new WeakMap(), _DefaultAllureStore_testCases = new WeakMap(), _DefaultAllureStore_metadata = new WeakMap(), _DefaultAllureStore_history = new WeakMap(), _DefaultAllureStore_known = new WeakMap(), _DefaultAllureStore_fixtures = new WeakMap(), _DefaultAllureStore_defaultLabels = new WeakMap(), _DefaultAllureStore_eventEmitter = new WeakMap();
635
+ _DefaultAllureStore_testResults = new WeakMap(), _DefaultAllureStore_attachments = new WeakMap(), _DefaultAllureStore_attachmentContents = new WeakMap(), _DefaultAllureStore_testCases = new WeakMap(), _DefaultAllureStore_metadata = new WeakMap(), _DefaultAllureStore_history = new WeakMap(), _DefaultAllureStore_known = new WeakMap(), _DefaultAllureStore_fixtures = new WeakMap(), _DefaultAllureStore_defaultLabels = new WeakMap(), _DefaultAllureStore_environment = new WeakMap(), _DefaultAllureStore_environmentsConfig = new WeakMap(), _DefaultAllureStore_reportVariables = new WeakMap(), _DefaultAllureStore_realtimeDispatcher = new WeakMap(), _DefaultAllureStore_realtimeSubscriber = new WeakMap(), _DefaultAllureStore_globalAttachments = new WeakMap(), _DefaultAllureStore_globalErrors = new WeakMap(), _DefaultAllureStore_globalExitCode = new WeakMap(), _DefaultAllureStore_qualityGateResultsByRules = new WeakMap(), _DefaultAllureStore_historyPoints = new WeakMap(), _DefaultAllureStore_environments = new WeakMap(), _DefaultAllureStore_instances = new WeakSet(), _DefaultAllureStore_addEnvironments = function _DefaultAllureStore_addEnvironments(envs) {
636
+ if (__classPrivateFieldGet(this, _DefaultAllureStore_environments, "f").length === 0) {
637
+ __classPrivateFieldGet(this, _DefaultAllureStore_environments, "f").push(DEFAULT_ENVIRONMENT);
638
+ }
639
+ __classPrivateFieldSet(this, _DefaultAllureStore_environments, Array.from(new Set([...__classPrivateFieldGet(this, _DefaultAllureStore_environments, "f"), ...envs])), "f");
640
+ envs.forEach((key) => {
641
+ if (!this.indexLatestEnvTestResultByHistoryId.has(key)) {
642
+ this.indexLatestEnvTestResultByHistoryId.set(key, new Map());
643
+ }
644
+ });
645
+ };