flakiness 0.0.0 → 0.147.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.
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/flakinessSession.ts
4
+ import fs from "fs/promises";
5
+ import os from "os";
6
+ import path from "path";
7
+
8
+ // src/serverapi.ts
9
+ import { TypedHTTP } from "@flakiness/shared/common/typedHttp.js";
10
+
11
+ // src/utils.ts
12
+ import { ReportUtils } from "@flakiness/sdk";
13
+ import http from "http";
14
+ import https from "https";
15
+ var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
16
+ function errorText(error) {
17
+ return FLAKINESS_DBG ? error.stack : error.message;
18
+ }
19
+ async function retryWithBackoff(job, backoff = []) {
20
+ for (const timeout of backoff) {
21
+ try {
22
+ return await job();
23
+ } catch (e) {
24
+ if (e instanceof AggregateError)
25
+ console.error(`[flakiness.io err]`, errorText(e.errors[0]));
26
+ else if (e instanceof Error)
27
+ console.error(`[flakiness.io err]`, errorText(e));
28
+ else
29
+ console.error(`[flakiness.io err]`, e);
30
+ await new Promise((x) => setTimeout(x, timeout));
31
+ }
32
+ }
33
+ return await job();
34
+ }
35
+ var httpUtils;
36
+ ((httpUtils2) => {
37
+ function createRequest({ url, method = "get", headers = {} }) {
38
+ let resolve;
39
+ let reject;
40
+ const responseDataPromise = new Promise((a, b) => {
41
+ resolve = a;
42
+ reject = b;
43
+ });
44
+ const protocol = url.startsWith("https") ? https : http;
45
+ headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
46
+ const request = protocol.request(url, { method, headers }, (res) => {
47
+ const chunks = [];
48
+ res.on("data", (chunk) => chunks.push(chunk));
49
+ res.on("end", () => {
50
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
51
+ resolve(Buffer.concat(chunks));
52
+ else
53
+ reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
54
+ });
55
+ res.on("error", (error) => reject(error));
56
+ });
57
+ request.on("error", reject);
58
+ return { request, responseDataPromise };
59
+ }
60
+ httpUtils2.createRequest = createRequest;
61
+ async function getBuffer(url, backoff) {
62
+ return await retryWithBackoff(async () => {
63
+ const { request, responseDataPromise } = createRequest({ url });
64
+ request.end();
65
+ return await responseDataPromise;
66
+ }, backoff);
67
+ }
68
+ httpUtils2.getBuffer = getBuffer;
69
+ async function getText(url, backoff) {
70
+ const buffer = await getBuffer(url, backoff);
71
+ return buffer.toString("utf-8");
72
+ }
73
+ httpUtils2.getText = getText;
74
+ async function getJSON(url) {
75
+ return JSON.parse(await getText(url));
76
+ }
77
+ httpUtils2.getJSON = getJSON;
78
+ async function postText(url, text, backoff) {
79
+ const headers = {
80
+ "Content-Type": "application/json",
81
+ "Content-Length": Buffer.byteLength(text) + ""
82
+ };
83
+ return await retryWithBackoff(async () => {
84
+ const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
85
+ request.write(text);
86
+ request.end();
87
+ return await responseDataPromise;
88
+ }, backoff);
89
+ }
90
+ httpUtils2.postText = postText;
91
+ async function postJSON(url, json, backoff) {
92
+ const buffer = await postText(url, JSON.stringify(json), backoff);
93
+ return JSON.parse(buffer.toString("utf-8"));
94
+ }
95
+ httpUtils2.postJSON = postJSON;
96
+ })(httpUtils || (httpUtils = {}));
97
+ 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");
98
+ var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
99
+ var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
100
+
101
+ // src/serverapi.ts
102
+ function createServerAPI(endpoint, options) {
103
+ endpoint += "/api/";
104
+ const fetcher = options?.auth ? (url, init) => fetch(url, {
105
+ ...init,
106
+ headers: {
107
+ ...init.headers,
108
+ "Authorization": `Bearer ${options.auth}`
109
+ }
110
+ }) : fetch;
111
+ if (options?.retries)
112
+ return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
113
+ return TypedHTTP.createClient(endpoint, fetcher);
114
+ }
115
+
116
+ // src/flakinessSession.ts
117
+ var CONFIG_DIR = (() => {
118
+ const configDir = process.platform === "darwin" ? path.join(os.homedir(), "Library", "Application Support", "flakiness") : process.platform === "win32" ? path.join(os.homedir(), "AppData", "Roaming", "flakiness") : path.join(os.homedir(), ".config", "flakiness");
119
+ return configDir;
120
+ })();
121
+ var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
122
+ var FlakinessSession = class _FlakinessSession {
123
+ constructor(_config) {
124
+ this._config = _config;
125
+ this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
126
+ }
127
+ static async loadOrDie() {
128
+ const session = await _FlakinessSession.load();
129
+ if (!session)
130
+ throw new Error(`Please login first with 'npx flakiness login'`);
131
+ return session;
132
+ }
133
+ static async load() {
134
+ const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
135
+ if (!data)
136
+ return void 0;
137
+ const json = JSON.parse(data);
138
+ return new _FlakinessSession(json);
139
+ }
140
+ static async remove() {
141
+ await fs.unlink(CONFIG_PATH).catch((e) => void 0);
142
+ }
143
+ api;
144
+ endpoint() {
145
+ return this._config.endpoint;
146
+ }
147
+ path() {
148
+ return CONFIG_PATH;
149
+ }
150
+ sessionToken() {
151
+ return this._config.token;
152
+ }
153
+ async save() {
154
+ await fs.mkdir(CONFIG_DIR, { recursive: true });
155
+ await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
156
+ }
157
+ };
158
+
159
+ // src/cli/cmd-whoami.ts
160
+ async function cmdWhoami() {
161
+ const session = await FlakinessSession.load();
162
+ if (!session) {
163
+ console.log('Not logged in. Run "flakiness login" first.');
164
+ process.exit(1);
165
+ }
166
+ console.log(`Logged into ${session.endpoint()}`);
167
+ const user = await session.api.user.whoami.GET();
168
+ console.log(user);
169
+ }
170
+ export {
171
+ cmdWhoami
172
+ };
173
+ //# sourceMappingURL=cmd-whoami.js.map
@@ -0,0 +1,159 @@
1
+ // src/flakinessSession.ts
2
+ import fs from "fs/promises";
3
+ import os from "os";
4
+ import path from "path";
5
+
6
+ // src/serverapi.ts
7
+ import { TypedHTTP } from "@flakiness/shared/common/typedHttp.js";
8
+
9
+ // src/utils.ts
10
+ import { ReportUtils } from "@flakiness/sdk";
11
+ import http from "http";
12
+ import https from "https";
13
+ var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
14
+ function errorText(error) {
15
+ return FLAKINESS_DBG ? error.stack : error.message;
16
+ }
17
+ async function retryWithBackoff(job, backoff = []) {
18
+ for (const timeout of backoff) {
19
+ try {
20
+ return await job();
21
+ } catch (e) {
22
+ if (e instanceof AggregateError)
23
+ console.error(`[flakiness.io err]`, errorText(e.errors[0]));
24
+ else if (e instanceof Error)
25
+ console.error(`[flakiness.io err]`, errorText(e));
26
+ else
27
+ console.error(`[flakiness.io err]`, e);
28
+ await new Promise((x) => setTimeout(x, timeout));
29
+ }
30
+ }
31
+ return await job();
32
+ }
33
+ var httpUtils;
34
+ ((httpUtils2) => {
35
+ function createRequest({ url, method = "get", headers = {} }) {
36
+ let resolve;
37
+ let reject;
38
+ const responseDataPromise = new Promise((a, b) => {
39
+ resolve = a;
40
+ reject = b;
41
+ });
42
+ const protocol = url.startsWith("https") ? https : http;
43
+ headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
44
+ const request = protocol.request(url, { method, headers }, (res) => {
45
+ const chunks = [];
46
+ res.on("data", (chunk) => chunks.push(chunk));
47
+ res.on("end", () => {
48
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
49
+ resolve(Buffer.concat(chunks));
50
+ else
51
+ reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
52
+ });
53
+ res.on("error", (error) => reject(error));
54
+ });
55
+ request.on("error", reject);
56
+ return { request, responseDataPromise };
57
+ }
58
+ httpUtils2.createRequest = createRequest;
59
+ async function getBuffer(url, backoff) {
60
+ return await retryWithBackoff(async () => {
61
+ const { request, responseDataPromise } = createRequest({ url });
62
+ request.end();
63
+ return await responseDataPromise;
64
+ }, backoff);
65
+ }
66
+ httpUtils2.getBuffer = getBuffer;
67
+ async function getText(url, backoff) {
68
+ const buffer = await getBuffer(url, backoff);
69
+ return buffer.toString("utf-8");
70
+ }
71
+ httpUtils2.getText = getText;
72
+ async function getJSON(url) {
73
+ return JSON.parse(await getText(url));
74
+ }
75
+ httpUtils2.getJSON = getJSON;
76
+ async function postText(url, text, backoff) {
77
+ const headers = {
78
+ "Content-Type": "application/json",
79
+ "Content-Length": Buffer.byteLength(text) + ""
80
+ };
81
+ return await retryWithBackoff(async () => {
82
+ const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
83
+ request.write(text);
84
+ request.end();
85
+ return await responseDataPromise;
86
+ }, backoff);
87
+ }
88
+ httpUtils2.postText = postText;
89
+ async function postJSON(url, json, backoff) {
90
+ const buffer = await postText(url, JSON.stringify(json), backoff);
91
+ return JSON.parse(buffer.toString("utf-8"));
92
+ }
93
+ httpUtils2.postJSON = postJSON;
94
+ })(httpUtils || (httpUtils = {}));
95
+ 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");
96
+ var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
97
+ var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
98
+
99
+ // src/serverapi.ts
100
+ function createServerAPI(endpoint, options) {
101
+ endpoint += "/api/";
102
+ const fetcher = options?.auth ? (url, init) => fetch(url, {
103
+ ...init,
104
+ headers: {
105
+ ...init.headers,
106
+ "Authorization": `Bearer ${options.auth}`
107
+ }
108
+ }) : fetch;
109
+ if (options?.retries)
110
+ return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
111
+ return TypedHTTP.createClient(endpoint, fetcher);
112
+ }
113
+
114
+ // src/flakinessSession.ts
115
+ var CONFIG_DIR = (() => {
116
+ const configDir = process.platform === "darwin" ? path.join(os.homedir(), "Library", "Application Support", "flakiness") : process.platform === "win32" ? path.join(os.homedir(), "AppData", "Roaming", "flakiness") : path.join(os.homedir(), ".config", "flakiness");
117
+ return configDir;
118
+ })();
119
+ var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
120
+ var FlakinessSession = class _FlakinessSession {
121
+ constructor(_config) {
122
+ this._config = _config;
123
+ this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
124
+ }
125
+ static async loadOrDie() {
126
+ const session = await _FlakinessSession.load();
127
+ if (!session)
128
+ throw new Error(`Please login first with 'npx flakiness login'`);
129
+ return session;
130
+ }
131
+ static async load() {
132
+ const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
133
+ if (!data)
134
+ return void 0;
135
+ const json = JSON.parse(data);
136
+ return new _FlakinessSession(json);
137
+ }
138
+ static async remove() {
139
+ await fs.unlink(CONFIG_PATH).catch((e) => void 0);
140
+ }
141
+ api;
142
+ endpoint() {
143
+ return this._config.endpoint;
144
+ }
145
+ path() {
146
+ return CONFIG_PATH;
147
+ }
148
+ sessionToken() {
149
+ return this._config.token;
150
+ }
151
+ async save() {
152
+ await fs.mkdir(CONFIG_DIR, { recursive: true });
153
+ await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
154
+ }
155
+ };
156
+ export {
157
+ FlakinessSession
158
+ };
159
+ //# sourceMappingURL=flakinessSession.js.map
package/lib/junit.js ADDED
@@ -0,0 +1,310 @@
1
+ // src/junit.ts
2
+ import { ReportUtils as ReportUtils2 } from "@flakiness/sdk";
3
+ import { parseXml, XmlElement, XmlText } from "@rgrove/parse-xml";
4
+ import assert from "assert";
5
+ import fs2 from "fs";
6
+ import path from "path";
7
+
8
+ // src/utils.ts
9
+ import { ReportUtils } from "@flakiness/sdk";
10
+ import crypto from "crypto";
11
+ import fs from "fs";
12
+ import http from "http";
13
+ import https from "https";
14
+ function sha1File(filePath) {
15
+ return new Promise((resolve, reject) => {
16
+ const hash = crypto.createHash("sha1");
17
+ const stream = fs.createReadStream(filePath);
18
+ stream.on("data", (chunk) => {
19
+ hash.update(chunk);
20
+ });
21
+ stream.on("end", () => {
22
+ resolve(hash.digest("hex"));
23
+ });
24
+ stream.on("error", (err) => {
25
+ reject(err);
26
+ });
27
+ });
28
+ }
29
+ var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
30
+ function errorText(error) {
31
+ return FLAKINESS_DBG ? error.stack : error.message;
32
+ }
33
+ function sha1Buffer(data) {
34
+ const hash = crypto.createHash("sha1");
35
+ hash.update(data);
36
+ return hash.digest("hex");
37
+ }
38
+ async function retryWithBackoff(job, backoff = []) {
39
+ for (const timeout of backoff) {
40
+ try {
41
+ return await job();
42
+ } catch (e) {
43
+ if (e instanceof AggregateError)
44
+ console.error(`[flakiness.io err]`, errorText(e.errors[0]));
45
+ else if (e instanceof Error)
46
+ console.error(`[flakiness.io err]`, errorText(e));
47
+ else
48
+ console.error(`[flakiness.io err]`, e);
49
+ await new Promise((x) => setTimeout(x, timeout));
50
+ }
51
+ }
52
+ return await job();
53
+ }
54
+ var httpUtils;
55
+ ((httpUtils2) => {
56
+ function createRequest({ url, method = "get", headers = {} }) {
57
+ let resolve;
58
+ let reject;
59
+ const responseDataPromise = new Promise((a, b) => {
60
+ resolve = a;
61
+ reject = b;
62
+ });
63
+ const protocol = url.startsWith("https") ? https : http;
64
+ headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
65
+ const request = protocol.request(url, { method, headers }, (res) => {
66
+ const chunks = [];
67
+ res.on("data", (chunk) => chunks.push(chunk));
68
+ res.on("end", () => {
69
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
70
+ resolve(Buffer.concat(chunks));
71
+ else
72
+ reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
73
+ });
74
+ res.on("error", (error) => reject(error));
75
+ });
76
+ request.on("error", reject);
77
+ return { request, responseDataPromise };
78
+ }
79
+ httpUtils2.createRequest = createRequest;
80
+ async function getBuffer(url, backoff) {
81
+ return await retryWithBackoff(async () => {
82
+ const { request, responseDataPromise } = createRequest({ url });
83
+ request.end();
84
+ return await responseDataPromise;
85
+ }, backoff);
86
+ }
87
+ httpUtils2.getBuffer = getBuffer;
88
+ async function getText(url, backoff) {
89
+ const buffer = await getBuffer(url, backoff);
90
+ return buffer.toString("utf-8");
91
+ }
92
+ httpUtils2.getText = getText;
93
+ async function getJSON(url) {
94
+ return JSON.parse(await getText(url));
95
+ }
96
+ httpUtils2.getJSON = getJSON;
97
+ async function postText(url, text, backoff) {
98
+ const headers = {
99
+ "Content-Type": "application/json",
100
+ "Content-Length": Buffer.byteLength(text) + ""
101
+ };
102
+ return await retryWithBackoff(async () => {
103
+ const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
104
+ request.write(text);
105
+ request.end();
106
+ return await responseDataPromise;
107
+ }, backoff);
108
+ }
109
+ httpUtils2.postText = postText;
110
+ async function postJSON(url, json, backoff) {
111
+ const buffer = await postText(url, JSON.stringify(json), backoff);
112
+ return JSON.parse(buffer.toString("utf-8"));
113
+ }
114
+ httpUtils2.postJSON = postJSON;
115
+ })(httpUtils || (httpUtils = {}));
116
+ 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");
117
+ var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
118
+ var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
119
+
120
+ // src/junit.ts
121
+ function getProperties(element) {
122
+ const propertiesNodes = element.children.filter((node) => node instanceof XmlElement).filter((node) => node.name === "properties");
123
+ if (!propertiesNodes.length)
124
+ return [];
125
+ const result = [];
126
+ for (const propertiesNode of propertiesNodes) {
127
+ const properties = propertiesNode.children.filter((node) => node instanceof XmlElement).filter((node) => node.name === "property");
128
+ for (const property of properties) {
129
+ const name = property.attributes["name"];
130
+ const innerText = property.children.find((node) => node instanceof XmlText);
131
+ const value = property.attributes["value"] ?? innerText?.text ?? "";
132
+ result.push([name, value]);
133
+ }
134
+ }
135
+ return result;
136
+ }
137
+ function extractErrors(testcase) {
138
+ const xmlErrors = testcase.children.filter((e) => e instanceof XmlElement).filter((element) => element.name === "error" || element.name === "failure");
139
+ if (!xmlErrors.length)
140
+ return void 0;
141
+ const errors = [];
142
+ for (const xmlErr of xmlErrors) {
143
+ const message = [xmlErr.attributes["type"], xmlErr.attributes["message"]].filter((x) => !!x).join(" ");
144
+ const xmlStackNodes = xmlErr.children.filter((child) => child instanceof XmlText);
145
+ const stack = xmlStackNodes ? xmlStackNodes.map((node) => node.text).join("\n") : void 0;
146
+ errors.push({
147
+ message,
148
+ stack
149
+ });
150
+ }
151
+ return errors;
152
+ }
153
+ function extractStdout(testcase, stdio) {
154
+ const xmlStdio = testcase.children.filter((e) => e instanceof XmlElement).filter((element) => element.name === stdio);
155
+ if (!xmlStdio.length)
156
+ return void 0;
157
+ return xmlStdio.map((node) => node.children.filter((node2) => node2 instanceof XmlText)).flat().map((txtNode) => ({
158
+ text: txtNode.text
159
+ }));
160
+ }
161
+ async function parseAttachment(value) {
162
+ let absolutePath = path.resolve(process.cwd(), value);
163
+ if (fs2.existsSync(absolutePath)) {
164
+ const id = await sha1File(absolutePath);
165
+ return {
166
+ contentType: "image/png",
167
+ path: absolutePath,
168
+ id
169
+ };
170
+ }
171
+ return {
172
+ contentType: "text/plain",
173
+ id: sha1Buffer(value),
174
+ body: Buffer.from(value)
175
+ };
176
+ }
177
+ async function traverseJUnitReport(context, node) {
178
+ const element = node;
179
+ if (!(element instanceof XmlElement))
180
+ return;
181
+ let { currentEnv, currentEnvIndex, currentSuite, report, currentTimeMs, attachments } = context;
182
+ if (element.attributes["timestamp"])
183
+ currentTimeMs = new Date(element.attributes["timestamp"]).getTime();
184
+ if (element.name === "testsuite") {
185
+ const file = element.attributes["file"];
186
+ const line = parseInt(element.attributes["line"], 10);
187
+ const name = element.attributes["name"];
188
+ const newSuite = {
189
+ title: name ?? file,
190
+ location: file && !isNaN(line) ? {
191
+ file,
192
+ line,
193
+ column: 1
194
+ } : void 0,
195
+ type: name ? "suite" : file ? "file" : "anonymous suite",
196
+ suites: [],
197
+ tests: []
198
+ };
199
+ if (currentSuite) {
200
+ currentSuite.suites ??= [];
201
+ currentSuite.suites.push(newSuite);
202
+ } else {
203
+ report.suites.push(newSuite);
204
+ }
205
+ currentSuite = newSuite;
206
+ const userSuppliedData = getProperties(element);
207
+ if (userSuppliedData.length) {
208
+ currentEnv = structuredClone(currentEnv);
209
+ currentEnv.userSuppliedData ??= {};
210
+ for (const [key, value] of userSuppliedData)
211
+ currentEnv.userSuppliedData[key] = value;
212
+ currentEnvIndex = report.environments.push(currentEnv) - 1;
213
+ }
214
+ } else if (element.name === "testcase") {
215
+ assert(currentSuite);
216
+ const file = element.attributes["file"];
217
+ const name = element.attributes["name"];
218
+ const line = parseInt(element.attributes["line"], 10);
219
+ const timeMs = parseFloat(element.attributes["time"]) * 1e3;
220
+ const startTimestamp = currentTimeMs;
221
+ const duration = timeMs;
222
+ currentTimeMs += timeMs;
223
+ const annotations = [];
224
+ const attachments2 = [];
225
+ for (const [key, value] of getProperties(element)) {
226
+ if (key.toLowerCase().startsWith("attachment")) {
227
+ if (context.ignoreAttachments)
228
+ continue;
229
+ const attachment = await parseAttachment(value);
230
+ context.attachments.set(attachment.id, attachment);
231
+ attachments2.push({
232
+ id: attachment.id,
233
+ contentType: attachment.contentType,
234
+ //TODO: better default names for attachments?
235
+ name: attachment.path ? path.basename(attachment.path) : `attachment`
236
+ });
237
+ } else {
238
+ annotations.push({
239
+ type: key,
240
+ description: value.length ? value : void 0
241
+ });
242
+ }
243
+ }
244
+ const childElements = element.children.filter((child) => child instanceof XmlElement);
245
+ const xmlSkippedAnnotation = childElements.find((child) => child.name === "skipped");
246
+ if (xmlSkippedAnnotation)
247
+ annotations.push({ type: "skipped", description: xmlSkippedAnnotation.attributes["message"] });
248
+ const expectedStatus = xmlSkippedAnnotation ? "skipped" : "passed";
249
+ const errors = extractErrors(element);
250
+ const test = {
251
+ title: name,
252
+ location: file && !isNaN(line) ? {
253
+ file,
254
+ line,
255
+ column: 1
256
+ } : void 0,
257
+ attempts: [{
258
+ environmentIdx: currentEnvIndex,
259
+ expectedStatus,
260
+ annotations,
261
+ attachments: attachments2,
262
+ startTimestamp,
263
+ duration,
264
+ status: xmlSkippedAnnotation ? "skipped" : errors ? "failed" : "passed",
265
+ errors,
266
+ stdout: extractStdout(element, "system-out"),
267
+ stderr: extractStdout(element, "system-err")
268
+ }]
269
+ };
270
+ currentSuite.tests ??= [];
271
+ currentSuite.tests.push(test);
272
+ }
273
+ context = { ...context, currentEnv, currentEnvIndex, currentSuite, currentTimeMs };
274
+ for (const child of element.children)
275
+ await traverseJUnitReport(context, child);
276
+ }
277
+ async function parseJUnit(xmls, options) {
278
+ const report = {
279
+ category: "junit",
280
+ commitId: options.commitId,
281
+ duration: options.runDuration,
282
+ startTimestamp: options.runStartTimestamp,
283
+ url: options.runUrl,
284
+ environments: [options.defaultEnv],
285
+ suites: [],
286
+ unattributedErrors: []
287
+ };
288
+ const context = {
289
+ currentEnv: options.defaultEnv,
290
+ currentEnvIndex: 0,
291
+ currentTimeMs: 0,
292
+ report,
293
+ currentSuite: void 0,
294
+ attachments: /* @__PURE__ */ new Map(),
295
+ ignoreAttachments: !!options.ignoreAttachments
296
+ };
297
+ for (const xml of xmls) {
298
+ const doc = parseXml(xml);
299
+ for (const element of doc.children)
300
+ await traverseJUnitReport(context, element);
301
+ }
302
+ return {
303
+ report: ReportUtils2.normalizeReport(report),
304
+ attachments: Array.from(context.attachments.values())
305
+ };
306
+ }
307
+ export {
308
+ parseJUnit
309
+ };
310
+ //# sourceMappingURL=junit.js.map