flakiness 0.149.1 → 0.150.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.
@@ -1,157 +0,0 @@
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
-
97
- // src/serverapi.ts
98
- function createServerAPI(endpoint, options) {
99
- endpoint += "/api/";
100
- const fetcher = options?.auth ? (url, init) => fetch(url, {
101
- ...init,
102
- headers: {
103
- ...init.headers,
104
- "Authorization": `Bearer ${options.auth}`
105
- }
106
- }) : fetch;
107
- if (options?.retries)
108
- return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
109
- return TypedHTTP.createClient(endpoint, fetcher);
110
- }
111
-
112
- // src/flakinessSession.ts
113
- var CONFIG_DIR = (() => {
114
- 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");
115
- return configDir;
116
- })();
117
- var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
118
- var FlakinessSession = class _FlakinessSession {
119
- constructor(_config) {
120
- this._config = _config;
121
- this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
122
- }
123
- static async loadOrDie() {
124
- const session = await _FlakinessSession.load();
125
- if (!session)
126
- throw new Error(`Please login first with 'npx flakiness login'`);
127
- return session;
128
- }
129
- static async load() {
130
- const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
131
- if (!data)
132
- return void 0;
133
- const json = JSON.parse(data);
134
- return new _FlakinessSession(json);
135
- }
136
- static async remove() {
137
- await fs.unlink(CONFIG_PATH).catch((e) => void 0);
138
- }
139
- api;
140
- endpoint() {
141
- return this._config.endpoint;
142
- }
143
- path() {
144
- return CONFIG_PATH;
145
- }
146
- sessionToken() {
147
- return this._config.token;
148
- }
149
- async save() {
150
- await fs.mkdir(CONFIG_DIR, { recursive: true });
151
- await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
152
- }
153
- };
154
- export {
155
- FlakinessSession
156
- };
157
- //# sourceMappingURL=flakinessSession.js.map
package/lib/serverapi.js DELETED
@@ -1,109 +0,0 @@
1
- // src/serverapi.ts
2
- import { TypedHTTP } from "@flakiness/shared/common/typedHttp.js";
3
-
4
- // src/utils.ts
5
- import { ReportUtils } from "@flakiness/sdk";
6
- import http from "http";
7
- import https from "https";
8
- var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
9
- function errorText(error) {
10
- return FLAKINESS_DBG ? error.stack : error.message;
11
- }
12
- async function retryWithBackoff(job, backoff = []) {
13
- for (const timeout of backoff) {
14
- try {
15
- return await job();
16
- } catch (e) {
17
- if (e instanceof AggregateError)
18
- console.error(`[flakiness.io err]`, errorText(e.errors[0]));
19
- else if (e instanceof Error)
20
- console.error(`[flakiness.io err]`, errorText(e));
21
- else
22
- console.error(`[flakiness.io err]`, e);
23
- await new Promise((x) => setTimeout(x, timeout));
24
- }
25
- }
26
- return await job();
27
- }
28
- var httpUtils;
29
- ((httpUtils2) => {
30
- function createRequest({ url, method = "get", headers = {} }) {
31
- let resolve;
32
- let reject;
33
- const responseDataPromise = new Promise((a, b) => {
34
- resolve = a;
35
- reject = b;
36
- });
37
- const protocol = url.startsWith("https") ? https : http;
38
- headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
39
- const request = protocol.request(url, { method, headers }, (res) => {
40
- const chunks = [];
41
- res.on("data", (chunk) => chunks.push(chunk));
42
- res.on("end", () => {
43
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
44
- resolve(Buffer.concat(chunks));
45
- else
46
- reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
47
- });
48
- res.on("error", (error) => reject(error));
49
- });
50
- request.on("error", reject);
51
- return { request, responseDataPromise };
52
- }
53
- httpUtils2.createRequest = createRequest;
54
- async function getBuffer(url, backoff) {
55
- return await retryWithBackoff(async () => {
56
- const { request, responseDataPromise } = createRequest({ url });
57
- request.end();
58
- return await responseDataPromise;
59
- }, backoff);
60
- }
61
- httpUtils2.getBuffer = getBuffer;
62
- async function getText(url, backoff) {
63
- const buffer = await getBuffer(url, backoff);
64
- return buffer.toString("utf-8");
65
- }
66
- httpUtils2.getText = getText;
67
- async function getJSON(url) {
68
- return JSON.parse(await getText(url));
69
- }
70
- httpUtils2.getJSON = getJSON;
71
- async function postText(url, text, backoff) {
72
- const headers = {
73
- "Content-Type": "application/json",
74
- "Content-Length": Buffer.byteLength(text) + ""
75
- };
76
- return await retryWithBackoff(async () => {
77
- const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
78
- request.write(text);
79
- request.end();
80
- return await responseDataPromise;
81
- }, backoff);
82
- }
83
- httpUtils2.postText = postText;
84
- async function postJSON(url, json, backoff) {
85
- const buffer = await postText(url, JSON.stringify(json), backoff);
86
- return JSON.parse(buffer.toString("utf-8"));
87
- }
88
- httpUtils2.postJSON = postJSON;
89
- })(httpUtils || (httpUtils = {}));
90
- 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");
91
-
92
- // src/serverapi.ts
93
- function createServerAPI(endpoint, options) {
94
- endpoint += "/api/";
95
- const fetcher = options?.auth ? (url, init) => fetch(url, {
96
- ...init,
97
- headers: {
98
- ...init.headers,
99
- "Authorization": `Bearer ${options.auth}`
100
- }
101
- }) : fetch;
102
- if (options?.retries)
103
- return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
104
- return TypedHTTP.createClient(endpoint, fetcher);
105
- }
106
- export {
107
- createServerAPI
108
- };
109
- //# sourceMappingURL=serverapi.js.map
package/lib/utils.js DELETED
@@ -1,187 +0,0 @@
1
- // src/utils.ts
2
- import { ReportUtils } from "@flakiness/sdk";
3
- import { spawnSync } from "child_process";
4
- import crypto from "crypto";
5
- import fs from "fs";
6
- import http from "http";
7
- import https from "https";
8
- import path from "path";
9
- async function existsAsync(aPath) {
10
- return fs.promises.stat(aPath).then(() => true).catch((e) => false);
11
- }
12
- function extractEnvConfiguration() {
13
- const ENV_PREFIX = "FK_ENV_";
14
- return Object.fromEntries(
15
- Object.entries(process.env).filter(([key]) => key.toUpperCase().startsWith(ENV_PREFIX.toUpperCase())).map(([key, value]) => [key.substring(ENV_PREFIX.length).toLowerCase(), (value ?? "").trim().toLowerCase()])
16
- );
17
- }
18
- function sha1File(filePath) {
19
- return new Promise((resolve, reject) => {
20
- const hash = crypto.createHash("sha1");
21
- const stream = fs.createReadStream(filePath);
22
- stream.on("data", (chunk) => {
23
- hash.update(chunk);
24
- });
25
- stream.on("end", () => {
26
- resolve(hash.digest("hex"));
27
- });
28
- stream.on("error", (err) => {
29
- reject(err);
30
- });
31
- });
32
- }
33
- var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
34
- function errorText(error) {
35
- return FLAKINESS_DBG ? error.stack : error.message;
36
- }
37
- function sha1Buffer(data) {
38
- const hash = crypto.createHash("sha1");
39
- hash.update(data);
40
- return hash.digest("hex");
41
- }
42
- async function retryWithBackoff(job, backoff = []) {
43
- for (const timeout of backoff) {
44
- try {
45
- return await job();
46
- } catch (e) {
47
- if (e instanceof AggregateError)
48
- console.error(`[flakiness.io err]`, errorText(e.errors[0]));
49
- else if (e instanceof Error)
50
- console.error(`[flakiness.io err]`, errorText(e));
51
- else
52
- console.error(`[flakiness.io err]`, e);
53
- await new Promise((x) => setTimeout(x, timeout));
54
- }
55
- }
56
- return await job();
57
- }
58
- var httpUtils;
59
- ((httpUtils2) => {
60
- function createRequest({ url, method = "get", headers = {} }) {
61
- let resolve;
62
- let reject;
63
- const responseDataPromise = new Promise((a, b) => {
64
- resolve = a;
65
- reject = b;
66
- });
67
- const protocol = url.startsWith("https") ? https : http;
68
- headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
69
- const request = protocol.request(url, { method, headers }, (res) => {
70
- const chunks = [];
71
- res.on("data", (chunk) => chunks.push(chunk));
72
- res.on("end", () => {
73
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
74
- resolve(Buffer.concat(chunks));
75
- else
76
- reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
77
- });
78
- res.on("error", (error) => reject(error));
79
- });
80
- request.on("error", reject);
81
- return { request, responseDataPromise };
82
- }
83
- httpUtils2.createRequest = createRequest;
84
- async function getBuffer(url, backoff) {
85
- return await retryWithBackoff(async () => {
86
- const { request, responseDataPromise } = createRequest({ url });
87
- request.end();
88
- return await responseDataPromise;
89
- }, backoff);
90
- }
91
- httpUtils2.getBuffer = getBuffer;
92
- async function getText(url, backoff) {
93
- const buffer = await getBuffer(url, backoff);
94
- return buffer.toString("utf-8");
95
- }
96
- httpUtils2.getText = getText;
97
- async function getJSON(url) {
98
- return JSON.parse(await getText(url));
99
- }
100
- httpUtils2.getJSON = getJSON;
101
- async function postText(url, text, backoff) {
102
- const headers = {
103
- "Content-Type": "application/json",
104
- "Content-Length": Buffer.byteLength(text) + ""
105
- };
106
- return await retryWithBackoff(async () => {
107
- const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
108
- request.write(text);
109
- request.end();
110
- return await responseDataPromise;
111
- }, backoff);
112
- }
113
- httpUtils2.postText = postText;
114
- async function postJSON(url, json, backoff) {
115
- const buffer = await postText(url, JSON.stringify(json), backoff);
116
- return JSON.parse(buffer.toString("utf-8"));
117
- }
118
- httpUtils2.postJSON = postJSON;
119
- })(httpUtils || (httpUtils = {}));
120
- 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");
121
- function stripAnsi(str) {
122
- return str.replace(ansiRegex, "");
123
- }
124
- function shell(command, args, options) {
125
- try {
126
- const result = spawnSync(command, args, { encoding: "utf-8", ...options });
127
- if (result.status !== 0) {
128
- return void 0;
129
- }
130
- return result.stdout.trim();
131
- } catch (e) {
132
- console.error(e);
133
- return void 0;
134
- }
135
- }
136
- function parseStringDate(dateString) {
137
- return +new Date(dateString);
138
- }
139
- async function resolveAttachmentPaths(report, attachmentsDir) {
140
- const attachmentFiles = await listFilesRecursively(attachmentsDir);
141
- const filenameToPath = new Map(attachmentFiles.map((file) => [path.basename(file), file]));
142
- const attachmentIdToPath = /* @__PURE__ */ new Map();
143
- const missingAttachments = /* @__PURE__ */ new Set();
144
- ReportUtils.visitTests(report, (test) => {
145
- for (const attempt of test.attempts) {
146
- for (const attachment of attempt.attachments ?? []) {
147
- const attachmentPath = filenameToPath.get(attachment.id);
148
- if (!attachmentPath) {
149
- missingAttachments.add(attachment.id);
150
- } else {
151
- attachmentIdToPath.set(attachment.id, {
152
- contentType: attachment.contentType,
153
- id: attachment.id,
154
- path: attachmentPath,
155
- type: "file"
156
- });
157
- }
158
- }
159
- }
160
- });
161
- return { attachmentIdToPath, missingAttachments: Array.from(missingAttachments) };
162
- }
163
- async function listFilesRecursively(dir, result = []) {
164
- const entries = await fs.promises.readdir(dir, { withFileTypes: true });
165
- for (const entry of entries) {
166
- const fullPath = path.join(dir, entry.name);
167
- if (entry.isDirectory())
168
- await listFilesRecursively(fullPath, result);
169
- else
170
- result.push(fullPath);
171
- }
172
- return result;
173
- }
174
- export {
175
- errorText,
176
- existsAsync,
177
- extractEnvConfiguration,
178
- httpUtils,
179
- parseStringDate,
180
- resolveAttachmentPaths,
181
- retryWithBackoff,
182
- sha1Buffer,
183
- sha1File,
184
- shell,
185
- stripAnsi
186
- };
187
- //# sourceMappingURL=utils.js.map