@allurereport/core 3.0.0-beta.19 → 3.0.0-beta.20

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.
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ export type * from "./api.js";
2
2
  export * from "./utils/misc.js";
3
3
  export * from "./utils/crypto.js";
4
4
  export * from "./utils/path.js";
5
- export * from "./utils/stats.js";
6
5
  export * from "./utils/git.js";
7
6
  export * from "./utils/new.js";
8
7
  export * from "./utils/flaky.js";
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./utils/misc.js";
2
2
  export * from "./utils/crypto.js";
3
3
  export * from "./utils/path.js";
4
- export * from "./utils/stats.js";
5
4
  export * from "./utils/git.js";
6
5
  export * from "./utils/new.js";
7
6
  export * from "./utils/flaky.js";
@@ -1,8 +1,8 @@
1
- import { type AllureHistory, type AttachmentLink, type DefaultLabelsConfig, type EnvironmentsConfig, type HistoryDataPoint, type HistoryTestResult, type KnownTestFailure, type RepoData, type ReportVariables, type TestCase, type TestEnvGroup, type TestError, type TestFixtureResult, type TestResult } from "@allurereport/core-api";
1
+ import { type AllureHistory, type AttachmentLink, type DefaultLabelsConfig, type EnvironmentsConfig, type HistoryDataPoint, type HistoryTestResult, type KnownTestFailure, type RepoData, type ReportVariables, type Statistic, type TestCase, type TestEnvGroup, type TestError, type TestFixtureResult, type TestResult } from "@allurereport/core-api";
2
2
  import { type AllureStore, type AllureStoreDump, type ExitCode, type QualityGateValidationResult, type RealtimeEventsDispatcher, type RealtimeSubscriber, type ResultFile, type TestResultFilter } from "@allurereport/plugin-api";
3
3
  import type { RawFixtureResult, RawMetadata, RawTestResult, ReaderContext, ResultsVisitor } from "@allurereport/reader-api";
4
4
  export declare const mapToObject: <K extends string | number | symbol, T = any>(map: Map<K, T>) => Record<K, T>;
5
- export declare const mergeMapWithRecord: <K extends string | number | symbol, T = any>(map: Map<K, T>, record: Record<K, T>) => Map<K, T>;
5
+ export declare const updateMapWithRecord: <K extends string | number | symbol, T = any>(map: Map<K, T>, record: Record<K, T>) => Map<K, T>;
6
6
  export declare class DefaultAllureStore implements AllureStore, ResultsVisitor {
7
7
  #private;
8
8
  readonly indexTestResultByTestCase: Map<string, TestResult[]>;
@@ -64,7 +64,7 @@ export declare class DefaultAllureStore implements AllureStore, ResultsVisitor {
64
64
  [x: string]: TestResult[];
65
65
  _: TestResult[];
66
66
  }>;
67
- testsStatistic(filter?: TestResultFilter): Promise<import("@allurereport/core-api").Statistic>;
67
+ testsStatistic(filter?: TestResultFilter): Promise<Statistic>;
68
68
  allEnvironments(): Promise<string[]>;
69
69
  testResultsByEnvironment(env: string, options?: {
70
70
  includeHidden: boolean;
@@ -15,7 +15,6 @@ import { md5, } from "@allurereport/plugin-api";
15
15
  import { isFlaky } from "../utils/flaky.js";
16
16
  import { getGitBranch, getGitRepoName } from "../utils/git.js";
17
17
  import { getStatusTransition } from "../utils/new.js";
18
- import { getTestResultsStats } from "../utils/stats.js";
19
18
  import { testFixtureResultRawToState, testResultRawToState } from "./convert.js";
20
19
  const index = (indexMap, key, ...items) => {
21
20
  if (key) {
@@ -58,28 +57,9 @@ export const mapToObject = (map) => {
58
57
  });
59
58
  return result;
60
59
  };
61
- export const mergeMapWithRecord = (map, record) => {
60
+ export const updateMapWithRecord = (map, record) => {
62
61
  Object.entries(record).forEach(([key, value]) => {
63
- const existingValue = map.get(key);
64
- if (existingValue !== undefined) {
65
- if (Array.isArray(existingValue) && Array.isArray(value)) {
66
- map.set(key, [...existingValue, ...value]);
67
- }
68
- else if (typeof existingValue === "object" &&
69
- existingValue !== null &&
70
- typeof value === "object" &&
71
- value !== null &&
72
- !Array.isArray(existingValue) &&
73
- !Array.isArray(value)) {
74
- map.set(key, { ...existingValue, ...value });
75
- }
76
- else {
77
- map.set(key, value);
78
- }
79
- }
80
- else {
81
- map.set(key, value);
82
- }
62
+ map.set(key, value);
83
63
  });
84
64
  return map;
85
65
  };
@@ -281,15 +261,28 @@ export class DefaultAllureStore {
281
261
  }
282
262
  async allTestResults(options = { includeHidden: false }) {
283
263
  const { includeHidden } = options;
284
- const result = Array.from(__classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f").values());
285
- return includeHidden ? result : result.filter((tr) => !tr.hidden);
264
+ const result = [];
265
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
266
+ if (!includeHidden && tr.hidden) {
267
+ continue;
268
+ }
269
+ result.push(tr);
270
+ }
271
+ return result;
286
272
  }
287
273
  async allAttachments(options = {}) {
288
274
  const { includeMissed = false, includeUnused = false } = options;
289
- const attachments = Array.from(__classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f").values());
290
- return attachments
291
- .filter((link) => (!includeMissed ? !link.missed : true))
292
- .filter((link) => (!includeUnused ? link.used : true));
275
+ const filteredAttachments = [];
276
+ for (const [, attachment] of __classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f")) {
277
+ if (!includeMissed && attachment.missed) {
278
+ continue;
279
+ }
280
+ if (!includeUnused && !attachment.used) {
281
+ continue;
282
+ }
283
+ filteredAttachments.push(attachment);
284
+ }
285
+ return filteredAttachments;
293
286
  }
294
287
  async allMetadata() {
295
288
  const result = {};
@@ -306,14 +299,21 @@ export class DefaultAllureStore {
306
299
  return __classPrivateFieldGet(this, _DefaultAllureStore_known, "f");
307
300
  }
308
301
  async allNewTestResults() {
309
- const allTrs = await this.allTestResults();
302
+ const newTrs = [];
310
303
  const allHistoryDps = await this.allHistoryDataPoints();
311
- return allTrs.filter((tr) => {
304
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
305
+ if (tr.hidden) {
306
+ continue;
307
+ }
312
308
  if (!tr.historyId) {
313
- return true;
309
+ newTrs.push(tr);
310
+ continue;
314
311
  }
315
- return !allHistoryDps.some((dp) => dp.testResults[tr.historyId]);
316
- });
312
+ if (!allHistoryDps.some((dp) => dp.testResults[tr.historyId])) {
313
+ newTrs.push(tr);
314
+ }
315
+ }
316
+ return newTrs;
317
317
  }
318
318
  async testCaseById(tcId) {
319
319
  return __classPrivateFieldGet(this, _DefaultAllureStore_testCases, "f").get(tcId);
@@ -359,8 +359,16 @@ export class DefaultAllureStore {
359
359
  return this.indexFixturesByTestResult.get(trId) ?? [];
360
360
  }
361
361
  async failedTestResults() {
362
- const allTestResults = await this.allTestResults();
363
- return allTestResults.filter(({ status }) => status === "failed" || status === "broken");
362
+ const failedTrs = [];
363
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
364
+ if (tr.hidden) {
365
+ continue;
366
+ }
367
+ if (tr.status === "failed" || tr.status === "broken") {
368
+ failedTrs.push(tr);
369
+ }
370
+ }
371
+ return failedTrs;
364
372
  }
365
373
  async unknownFailedTestResults() {
366
374
  const failedTestResults = await this.failedTestResults();
@@ -374,12 +382,14 @@ export class DefaultAllureStore {
374
382
  const results = {
375
383
  _: [],
376
384
  };
377
- const all = await this.allTestResults();
378
- all.forEach((test) => {
385
+ for (const [, test] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
386
+ if (test.hidden) {
387
+ continue;
388
+ }
379
389
  const targetLabels = (test.labels ?? []).filter((label) => label.name === labelName);
380
390
  if (targetLabels.length === 0) {
381
391
  results._.push(test);
382
- return;
392
+ continue;
383
393
  }
384
394
  targetLabels.forEach((label) => {
385
395
  if (!results[label.value]) {
@@ -387,42 +397,65 @@ export class DefaultAllureStore {
387
397
  }
388
398
  results[label.value].push(test);
389
399
  });
390
- });
400
+ }
391
401
  return results;
392
402
  }
393
403
  async testsStatistic(filter) {
394
- const all = await this.allTestResults();
395
- const allWithStats = await Promise.all(all.map(async (tr) => {
404
+ const statistic = { total: 0 };
405
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
406
+ if (tr.hidden) {
407
+ continue;
408
+ }
409
+ if (filter && !filter(tr)) {
410
+ continue;
411
+ }
412
+ statistic.total++;
396
413
  const retries = await this.retriesByTr(tr);
397
- return {
398
- ...tr,
399
- retries,
400
- };
401
- }));
402
- return getTestResultsStats(allWithStats, filter);
414
+ if (retries.length > 0) {
415
+ statistic.retries = (statistic.retries ?? 0) + 1;
416
+ }
417
+ if (tr.flaky) {
418
+ statistic.flaky = (statistic.flaky ?? 0) + 1;
419
+ }
420
+ if (tr.transition === "new") {
421
+ statistic.new = (statistic.new ?? 0) + 1;
422
+ }
423
+ if (!statistic[tr.status]) {
424
+ statistic[tr.status] = 0;
425
+ }
426
+ statistic[tr.status]++;
427
+ }
428
+ return statistic;
403
429
  }
404
430
  async allEnvironments() {
405
431
  return __classPrivateFieldGet(this, _DefaultAllureStore_environments, "f");
406
432
  }
407
433
  async testResultsByEnvironment(env, options = { includeHidden: false }) {
408
- const allTrs = await this.allTestResults(options);
409
- return allTrs.filter((tr) => tr.environment === env);
434
+ const trs = [];
435
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
436
+ if (!options.includeHidden && tr.hidden) {
437
+ continue;
438
+ }
439
+ if (tr.environment === env) {
440
+ trs.push(tr);
441
+ }
442
+ }
443
+ return trs;
410
444
  }
411
445
  async allTestEnvGroups() {
412
- const allTr = await this.allTestResults({ includeHidden: true });
413
- const trByTestCaseId = allTr.reduce((acc, tr) => {
446
+ const trByTestCaseId = {};
447
+ for (const [, tr] of __classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f")) {
414
448
  const testCaseId = tr?.testCase?.id;
415
449
  if (!testCaseId) {
416
- return acc;
450
+ continue;
417
451
  }
418
- if (acc[testCaseId]) {
419
- acc[testCaseId].push(tr);
452
+ if (trByTestCaseId[testCaseId]) {
453
+ trByTestCaseId[testCaseId].push(tr);
420
454
  }
421
455
  else {
422
- acc[testCaseId] = [tr];
456
+ trByTestCaseId[testCaseId] = [tr];
423
457
  }
424
- return acc;
425
- }, {});
458
+ }
426
459
  return Object.entries(trByTestCaseId).reduce((acc, [testCaseId, trs]) => {
427
460
  if (trs.length === 0) {
428
461
  return acc;
@@ -497,11 +530,11 @@ export class DefaultAllureStore {
497
530
  }
498
531
  async restoreState(stateDump, attachmentsContents = {}) {
499
532
  const { testResults, attachments, testCases, fixtures, reportVariables, environments, globalAttachments = [], globalErrors = [], indexAttachmentByTestResult = {}, indexTestResultByHistoryId = {}, indexTestResultByTestCase = {}, indexLatestEnvTestResultByHistoryId = {}, indexAttachmentByFixture = {}, indexFixturesByTestResult = {}, indexKnownByHistoryId = {}, } = stateDump;
500
- mergeMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f"), testResults);
501
- mergeMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f"), attachments);
502
- mergeMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_testCases, "f"), testCases);
503
- mergeMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_fixtures, "f"), fixtures);
504
- mergeMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_attachmentContents, "f"), attachmentsContents);
533
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_testResults, "f"), testResults);
534
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_attachments, "f"), attachments);
535
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_testCases, "f"), testCases);
536
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_fixtures, "f"), fixtures);
537
+ updateMapWithRecord(__classPrivateFieldGet(this, _DefaultAllureStore_attachmentContents, "f"), attachmentsContents);
505
538
  __classPrivateFieldGet(this, _DefaultAllureStore_instances, "m", _DefaultAllureStore_addEnvironments).call(this, environments);
506
539
  __classPrivateFieldGet(this, _DefaultAllureStore_globalAttachments, "f").push(...globalAttachments);
507
540
  __classPrivateFieldGet(this, _DefaultAllureStore_globalErrors, "f").push(...globalErrors);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/core",
3
- "version": "3.0.0-beta.19",
3
+ "version": "3.0.0-beta.20",
4
4
  "description": "Collection of generic Allure utilities used across the entire project",
5
5
  "keywords": [
6
6
  "allure"
@@ -25,22 +25,22 @@
25
25
  "test": "vitest run"
26
26
  },
27
27
  "dependencies": {
28
- "@allurereport/ci": "3.0.0-beta.19",
29
- "@allurereport/core-api": "3.0.0-beta.19",
30
- "@allurereport/plugin-allure2": "3.0.0-beta.19",
31
- "@allurereport/plugin-api": "3.0.0-beta.19",
32
- "@allurereport/plugin-awesome": "3.0.0-beta.19",
33
- "@allurereport/plugin-classic": "3.0.0-beta.19",
34
- "@allurereport/plugin-csv": "3.0.0-beta.19",
35
- "@allurereport/plugin-dashboard": "3.0.0-beta.19",
36
- "@allurereport/plugin-log": "3.0.0-beta.19",
37
- "@allurereport/plugin-progress": "3.0.0-beta.19",
38
- "@allurereport/plugin-slack": "3.0.0-beta.19",
39
- "@allurereport/plugin-testplan": "3.0.0-beta.19",
40
- "@allurereport/reader": "3.0.0-beta.19",
41
- "@allurereport/reader-api": "3.0.0-beta.19",
42
- "@allurereport/service": "3.0.0-beta.19",
43
- "@allurereport/summary": "3.0.0-beta.19",
28
+ "@allurereport/ci": "3.0.0-beta.20",
29
+ "@allurereport/core-api": "3.0.0-beta.20",
30
+ "@allurereport/plugin-allure2": "3.0.0-beta.20",
31
+ "@allurereport/plugin-api": "3.0.0-beta.20",
32
+ "@allurereport/plugin-awesome": "3.0.0-beta.20",
33
+ "@allurereport/plugin-classic": "3.0.0-beta.20",
34
+ "@allurereport/plugin-csv": "3.0.0-beta.20",
35
+ "@allurereport/plugin-dashboard": "3.0.0-beta.20",
36
+ "@allurereport/plugin-log": "3.0.0-beta.20",
37
+ "@allurereport/plugin-progress": "3.0.0-beta.20",
38
+ "@allurereport/plugin-slack": "3.0.0-beta.20",
39
+ "@allurereport/plugin-testplan": "3.0.0-beta.20",
40
+ "@allurereport/reader": "3.0.0-beta.20",
41
+ "@allurereport/reader-api": "3.0.0-beta.20",
42
+ "@allurereport/service": "3.0.0-beta.20",
43
+ "@allurereport/summary": "3.0.0-beta.20",
44
44
  "handlebars": "^4.7.8",
45
45
  "markdown-it": "^14.1.0",
46
46
  "node-stream-zip": "^1.15.0",
@@ -1,2 +0,0 @@
1
- import type { Statistic, TestResult } from "@allurereport/core-api";
2
- export declare const getTestResultsStats: (trs: TestResult[], filter?: (tr: TestResult) => boolean) => Statistic;
@@ -1,22 +0,0 @@
1
- export const getTestResultsStats = (trs, filter = () => true) => {
2
- const trsToProcess = trs.filter(filter);
3
- return trsToProcess.reduce((acc, tr) => {
4
- if (filter && !filter(tr)) {
5
- return acc;
6
- }
7
- if (tr.retries && tr.retries?.length > 0) {
8
- acc.retries = (acc.retries ?? 0) + 1;
9
- }
10
- if (tr.flaky) {
11
- acc.flaky = (acc.flaky ?? 0) + 1;
12
- }
13
- if (tr.transition === "new") {
14
- acc.new = (acc.new ?? 0) + 1;
15
- }
16
- if (!acc[tr.status]) {
17
- acc[tr.status] = 0;
18
- }
19
- acc[tr.status]++;
20
- return acc;
21
- }, { total: trsToProcess.length });
22
- };