@flakiness/sdk 0.150.1 → 0.151.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.
package/lib/browser.js CHANGED
@@ -1,7 +1,154 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/browser.ts
1
8
  import { FlakinessReport } from "@flakiness/flakiness-report";
2
- import * as ReportUtils from "./reportUtilsBrowser.js";
9
+
10
+ // src/reportUtilsBrowser.ts
11
+ var reportUtilsBrowser_exports = {};
12
+ __export(reportUtilsBrowser_exports, {
13
+ normalizeReport: () => normalizeReport,
14
+ stripAnsi: () => stripAnsi,
15
+ visitTests: () => visitTests
16
+ });
17
+
18
+ // src/normalizeReport.ts
19
+ import stableObjectHash from "stable-hash";
20
+ var Multimap = class {
21
+ _map = /* @__PURE__ */ new Map();
22
+ set(key, value) {
23
+ const set = this._map.get(key) ?? /* @__PURE__ */ new Set();
24
+ this._map.set(key, set);
25
+ set.add(value);
26
+ }
27
+ getAll(key) {
28
+ return Array.from(this._map.get(key) ?? []);
29
+ }
30
+ };
31
+ function normalizeReport(report) {
32
+ const gEnvs = /* @__PURE__ */ new Map();
33
+ const gSuites = /* @__PURE__ */ new Map();
34
+ const gTests = new Multimap();
35
+ const gSuiteIds = /* @__PURE__ */ new Map();
36
+ const gTestIds = /* @__PURE__ */ new Map();
37
+ const gEnvIds = /* @__PURE__ */ new Map();
38
+ const gSuiteChildren = new Multimap();
39
+ const gSuiteTests = new Multimap();
40
+ for (const env of report.environments) {
41
+ const envId = computeEnvId(env);
42
+ gEnvs.set(envId, env);
43
+ gEnvIds.set(env, envId);
44
+ }
45
+ const usedEnvIds = /* @__PURE__ */ new Set();
46
+ function visitTests2(tests, suiteId) {
47
+ for (const test of tests ?? []) {
48
+ const testId = computeTestId(test, suiteId);
49
+ gTests.set(testId, test);
50
+ gTestIds.set(test, testId);
51
+ gSuiteTests.set(suiteId, test);
52
+ for (const attempt of test.attempts) {
53
+ const env = report.environments[attempt.environmentIdx];
54
+ const envId = gEnvIds.get(env);
55
+ usedEnvIds.add(envId);
56
+ }
57
+ }
58
+ }
59
+ function visitSuite(suite, parentSuiteId) {
60
+ const suiteId = computeSuiteId(suite, parentSuiteId);
61
+ gSuites.set(suiteId, suite);
62
+ gSuiteIds.set(suite, suiteId);
63
+ for (const childSuite of suite.suites ?? []) {
64
+ visitSuite(childSuite, suiteId);
65
+ gSuiteChildren.set(suiteId, childSuite);
66
+ }
67
+ visitTests2(suite.tests ?? [], suiteId);
68
+ }
69
+ function transformTests(tests) {
70
+ const testIds = new Set(tests.map((test) => gTestIds.get(test)));
71
+ return [...testIds].map((testId) => {
72
+ const tests2 = gTests.getAll(testId);
73
+ const tags = tests2.map((test) => test.tags ?? []).flat();
74
+ return {
75
+ location: tests2[0].location,
76
+ title: tests2[0].title,
77
+ tags: tags.length ? tags : void 0,
78
+ attempts: tests2.map((t) => t.attempts).flat().map((attempt) => ({
79
+ ...attempt,
80
+ environmentIdx: envIdToIndex.get(gEnvIds.get(report.environments[attempt.environmentIdx]))
81
+ }))
82
+ };
83
+ });
84
+ }
85
+ function transformSuites(suites) {
86
+ const suiteIds = new Set(suites.map((suite) => gSuiteIds.get(suite)));
87
+ return [...suiteIds].map((suiteId) => {
88
+ const suite = gSuites.get(suiteId);
89
+ return {
90
+ location: suite.location,
91
+ title: suite.title,
92
+ type: suite.type,
93
+ suites: transformSuites(gSuiteChildren.getAll(suiteId)),
94
+ tests: transformTests(gSuiteTests.getAll(suiteId))
95
+ };
96
+ });
97
+ }
98
+ visitTests2(report.tests ?? [], "suiteless");
99
+ for (const suite of report.suites)
100
+ visitSuite(suite);
101
+ const newEnvironments = [...usedEnvIds];
102
+ const envIdToIndex = new Map(newEnvironments.map((envId, index) => [envId, index]));
103
+ return {
104
+ ...report,
105
+ environments: newEnvironments.map((envId) => gEnvs.get(envId)),
106
+ suites: transformSuites(report.suites),
107
+ tests: transformTests(report.tests ?? [])
108
+ };
109
+ }
110
+ function computeEnvId(env) {
111
+ return stableObjectHash(env);
112
+ }
113
+ function computeSuiteId(suite, parentSuiteId) {
114
+ return stableObjectHash({
115
+ parentSuiteId: parentSuiteId ?? "",
116
+ type: suite.type,
117
+ file: suite.location?.file ?? "",
118
+ title: suite.title
119
+ });
120
+ }
121
+ function computeTestId(test, suiteId) {
122
+ return stableObjectHash({
123
+ suiteId,
124
+ file: test.location?.file ?? "",
125
+ title: test.title
126
+ });
127
+ }
128
+
129
+ // src/stripAnsi.ts
130
+ var ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
131
+ function stripAnsi(str) {
132
+ return str.replace(ansiRegex, "");
133
+ }
134
+
135
+ // src/visitTests.ts
136
+ function visitTests(report, testVisitor) {
137
+ function visitSuite(suite, parents) {
138
+ parents.push(suite);
139
+ for (const test of suite.tests ?? [])
140
+ testVisitor(test, parents);
141
+ for (const childSuite of suite.suites ?? [])
142
+ visitSuite(childSuite, parents);
143
+ parents.pop();
144
+ }
145
+ for (const test of report.tests ?? [])
146
+ testVisitor(test, []);
147
+ for (const suite of report.suites)
148
+ visitSuite(suite, []);
149
+ }
3
150
  export {
4
151
  FlakinessReport,
5
- ReportUtils
152
+ reportUtilsBrowser_exports as ReportUtils
6
153
  };
7
154
  //# sourceMappingURL=browser.js.map