@flakiness/sdk 0.95.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/LICENSE +45 -0
- package/README.md +30 -0
- package/lib/cli/cli.js +1435 -0
- package/lib/cli/cmd-convert.js +413 -0
- package/lib/cli/cmd-download.js +494 -0
- package/lib/cli/cmd-link.js +463 -0
- package/lib/cli/cmd-login.js +414 -0
- package/lib/cli/cmd-logout.js +378 -0
- package/lib/cli/cmd-serve.js +7 -0
- package/lib/cli/cmd-status.js +460 -0
- package/lib/cli/cmd-unlink.js +166 -0
- package/lib/cli/cmd-upload-playwright-json.js +818 -0
- package/lib/cli/cmd-upload.js +512 -0
- package/lib/cli/cmd-whoami.js +387 -0
- package/lib/createTestStepSnippets.js +32 -0
- package/lib/flakinessLink.js +161 -0
- package/lib/flakinessSession.js +373 -0
- package/lib/junit.js +311 -0
- package/lib/playwright-test.js +933 -0
- package/lib/playwrightJSONReport.js +432 -0
- package/lib/reportUploader.js +447 -0
- package/lib/serverapi.js +331 -0
- package/lib/systemUtilizationSampler.js +71 -0
- package/lib/utils.js +323 -0
- package/package.json +58 -0
- package/types/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
// src/flakinessSession.ts
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
// ../server/lib/common/typedHttp.js
|
|
7
|
+
var TypedHTTP;
|
|
8
|
+
((TypedHTTP2) => {
|
|
9
|
+
TypedHTTP2.StatusCodes = {
|
|
10
|
+
Informational: {
|
|
11
|
+
CONTINUE: 100,
|
|
12
|
+
SWITCHING_PROTOCOLS: 101,
|
|
13
|
+
PROCESSING: 102,
|
|
14
|
+
EARLY_HINTS: 103
|
|
15
|
+
},
|
|
16
|
+
Success: {
|
|
17
|
+
OK: 200,
|
|
18
|
+
CREATED: 201,
|
|
19
|
+
ACCEPTED: 202,
|
|
20
|
+
NON_AUTHORITATIVE_INFORMATION: 203,
|
|
21
|
+
NO_CONTENT: 204,
|
|
22
|
+
RESET_CONTENT: 205,
|
|
23
|
+
PARTIAL_CONTENT: 206,
|
|
24
|
+
MULTI_STATUS: 207
|
|
25
|
+
},
|
|
26
|
+
Redirection: {
|
|
27
|
+
MULTIPLE_CHOICES: 300,
|
|
28
|
+
MOVED_PERMANENTLY: 301,
|
|
29
|
+
MOVED_TEMPORARILY: 302,
|
|
30
|
+
SEE_OTHER: 303,
|
|
31
|
+
NOT_MODIFIED: 304,
|
|
32
|
+
USE_PROXY: 305,
|
|
33
|
+
TEMPORARY_REDIRECT: 307,
|
|
34
|
+
PERMANENT_REDIRECT: 308
|
|
35
|
+
},
|
|
36
|
+
ClientErrors: {
|
|
37
|
+
BAD_REQUEST: 400,
|
|
38
|
+
UNAUTHORIZED: 401,
|
|
39
|
+
PAYMENT_REQUIRED: 402,
|
|
40
|
+
FORBIDDEN: 403,
|
|
41
|
+
NOT_FOUND: 404,
|
|
42
|
+
METHOD_NOT_ALLOWED: 405,
|
|
43
|
+
NOT_ACCEPTABLE: 406,
|
|
44
|
+
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
45
|
+
REQUEST_TIMEOUT: 408,
|
|
46
|
+
CONFLICT: 409,
|
|
47
|
+
GONE: 410,
|
|
48
|
+
LENGTH_REQUIRED: 411,
|
|
49
|
+
PRECONDITION_FAILED: 412,
|
|
50
|
+
REQUEST_TOO_LONG: 413,
|
|
51
|
+
REQUEST_URI_TOO_LONG: 414,
|
|
52
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
53
|
+
REQUESTED_RANGE_NOT_SATISFIABLE: 416,
|
|
54
|
+
EXPECTATION_FAILED: 417,
|
|
55
|
+
IM_A_TEAPOT: 418,
|
|
56
|
+
INSUFFICIENT_SPACE_ON_RESOURCE: 419,
|
|
57
|
+
METHOD_FAILURE: 420,
|
|
58
|
+
MISDIRECTED_REQUEST: 421,
|
|
59
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
60
|
+
LOCKED: 423,
|
|
61
|
+
FAILED_DEPENDENCY: 424,
|
|
62
|
+
UPGRADE_REQUIRED: 426,
|
|
63
|
+
PRECONDITION_REQUIRED: 428,
|
|
64
|
+
TOO_MANY_REQUESTS: 429,
|
|
65
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
66
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451
|
|
67
|
+
},
|
|
68
|
+
ServerErrors: {
|
|
69
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
70
|
+
NOT_IMPLEMENTED: 501,
|
|
71
|
+
BAD_GATEWAY: 502,
|
|
72
|
+
SERVICE_UNAVAILABLE: 503,
|
|
73
|
+
GATEWAY_TIMEOUT: 504,
|
|
74
|
+
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
75
|
+
INSUFFICIENT_STORAGE: 507,
|
|
76
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const AllErrorCodes = {
|
|
80
|
+
...TypedHTTP2.StatusCodes.ClientErrors,
|
|
81
|
+
...TypedHTTP2.StatusCodes.ServerErrors
|
|
82
|
+
};
|
|
83
|
+
class HttpError extends Error {
|
|
84
|
+
constructor(status, message) {
|
|
85
|
+
super(message);
|
|
86
|
+
this.status = status;
|
|
87
|
+
}
|
|
88
|
+
static withCode(code, message) {
|
|
89
|
+
const statusCode = AllErrorCodes[code];
|
|
90
|
+
const defaultMessage = code.split("_").map((word) => word.charAt(0) + word.slice(1).toLowerCase()).join(" ");
|
|
91
|
+
return new HttpError(statusCode, message ?? defaultMessage);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
TypedHTTP2.HttpError = HttpError;
|
|
95
|
+
function isInformationalResponse(response) {
|
|
96
|
+
return response.status >= 100 && response.status < 200;
|
|
97
|
+
}
|
|
98
|
+
TypedHTTP2.isInformationalResponse = isInformationalResponse;
|
|
99
|
+
function isSuccessResponse(response) {
|
|
100
|
+
return response.status >= 200 && response.status < 300;
|
|
101
|
+
}
|
|
102
|
+
TypedHTTP2.isSuccessResponse = isSuccessResponse;
|
|
103
|
+
function isRedirectResponse(response) {
|
|
104
|
+
return response.status >= 300 && response.status < 400;
|
|
105
|
+
}
|
|
106
|
+
TypedHTTP2.isRedirectResponse = isRedirectResponse;
|
|
107
|
+
function isErrorResponse(response) {
|
|
108
|
+
return response.status >= 400 && response.status < 600;
|
|
109
|
+
}
|
|
110
|
+
TypedHTTP2.isErrorResponse = isErrorResponse;
|
|
111
|
+
function info(status) {
|
|
112
|
+
return { status };
|
|
113
|
+
}
|
|
114
|
+
TypedHTTP2.info = info;
|
|
115
|
+
function ok(data, status) {
|
|
116
|
+
return {
|
|
117
|
+
status: status ?? TypedHTTP2.StatusCodes.Success.OK,
|
|
118
|
+
data
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
TypedHTTP2.ok = ok;
|
|
122
|
+
function redirect(url, status = 302) {
|
|
123
|
+
return { status, url };
|
|
124
|
+
}
|
|
125
|
+
TypedHTTP2.redirect = redirect;
|
|
126
|
+
function error(message, status = TypedHTTP2.StatusCodes.ServerErrors.INTERNAL_SERVER_ERROR) {
|
|
127
|
+
return { status, message };
|
|
128
|
+
}
|
|
129
|
+
TypedHTTP2.error = error;
|
|
130
|
+
class Router {
|
|
131
|
+
constructor(_resolveContext) {
|
|
132
|
+
this._resolveContext = _resolveContext;
|
|
133
|
+
}
|
|
134
|
+
static create() {
|
|
135
|
+
return new Router(async (e) => e.ctx);
|
|
136
|
+
}
|
|
137
|
+
rawMethod(method, route) {
|
|
138
|
+
return {
|
|
139
|
+
[method]: {
|
|
140
|
+
method,
|
|
141
|
+
input: route.input,
|
|
142
|
+
etag: route.etag,
|
|
143
|
+
resolveContext: this._resolveContext,
|
|
144
|
+
handler: route.handler
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
get(route) {
|
|
149
|
+
return this.rawMethod("GET", {
|
|
150
|
+
...route,
|
|
151
|
+
handler: (...args) => Promise.resolve(route.handler(...args)).then((result) => TypedHTTP2.ok(result))
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
post(route) {
|
|
155
|
+
return this.rawMethod("POST", {
|
|
156
|
+
...route,
|
|
157
|
+
handler: (...args) => Promise.resolve(route.handler(...args)).then((result) => TypedHTTP2.ok(result))
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
use(resolveContext) {
|
|
161
|
+
return new Router(async (options) => {
|
|
162
|
+
const m = await this._resolveContext(options);
|
|
163
|
+
return resolveContext({ ...options, ctx: m });
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
TypedHTTP2.Router = Router;
|
|
168
|
+
function createClient(base, fetchCallback) {
|
|
169
|
+
function buildUrl(path2, input, options) {
|
|
170
|
+
const method = path2.at(-1);
|
|
171
|
+
const url = new URL(path2.slice(0, path2.length - 1).join("/"), base);
|
|
172
|
+
const signal = options?.signal;
|
|
173
|
+
let body = void 0;
|
|
174
|
+
if (method === "GET" && input)
|
|
175
|
+
url.searchParams.set("input", JSON.stringify(input));
|
|
176
|
+
else if (method !== "GET" && input)
|
|
177
|
+
body = JSON.stringify(input);
|
|
178
|
+
return {
|
|
179
|
+
url,
|
|
180
|
+
method,
|
|
181
|
+
headers: body ? { "Content-Type": "application/json" } : void 0,
|
|
182
|
+
body,
|
|
183
|
+
signal
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function createProxy(path2 = []) {
|
|
187
|
+
return new Proxy(() => {
|
|
188
|
+
}, {
|
|
189
|
+
get(target, prop) {
|
|
190
|
+
if (typeof prop === "symbol")
|
|
191
|
+
return void 0;
|
|
192
|
+
if (prop === "prepare")
|
|
193
|
+
return (input, options) => buildUrl(path2, input, options);
|
|
194
|
+
const newPath = [...path2, prop];
|
|
195
|
+
return createProxy(newPath);
|
|
196
|
+
},
|
|
197
|
+
apply(target, thisArg, args) {
|
|
198
|
+
const options = buildUrl(path2, args[0], args[1]);
|
|
199
|
+
return fetchCallback(options.url, {
|
|
200
|
+
method: options.method,
|
|
201
|
+
body: options.body,
|
|
202
|
+
headers: options.headers,
|
|
203
|
+
signal: options.signal
|
|
204
|
+
}).then(async (response) => {
|
|
205
|
+
if (response.status >= 200 && response.status < 300) {
|
|
206
|
+
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
207
|
+
const text = await response.text();
|
|
208
|
+
return text.length ? JSON.parse(text) : void 0;
|
|
209
|
+
}
|
|
210
|
+
return await response.blob();
|
|
211
|
+
}
|
|
212
|
+
if (response.status >= 400 && response.status < 600) {
|
|
213
|
+
const text = await response.text();
|
|
214
|
+
if (text)
|
|
215
|
+
throw new Error(`HTTP request failed with status ${response.status}: ${text}`);
|
|
216
|
+
else
|
|
217
|
+
throw new Error(`HTTP request failed with status ${response.status}`);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return createProxy();
|
|
224
|
+
}
|
|
225
|
+
TypedHTTP2.createClient = createClient;
|
|
226
|
+
})(TypedHTTP || (TypedHTTP = {}));
|
|
227
|
+
|
|
228
|
+
// src/utils.ts
|
|
229
|
+
import http from "http";
|
|
230
|
+
import https from "https";
|
|
231
|
+
import util from "util";
|
|
232
|
+
import zlib from "zlib";
|
|
233
|
+
var gzipAsync = util.promisify(zlib.gzip);
|
|
234
|
+
var gunzipAsync = util.promisify(zlib.gunzip);
|
|
235
|
+
var gunzipSync = zlib.gunzipSync;
|
|
236
|
+
var brotliCompressAsync = util.promisify(zlib.brotliCompress);
|
|
237
|
+
var brotliCompressSync = zlib.brotliCompressSync;
|
|
238
|
+
async function retryWithBackoff(job, backoff = []) {
|
|
239
|
+
for (const timeout of backoff) {
|
|
240
|
+
try {
|
|
241
|
+
return await job();
|
|
242
|
+
} catch (e) {
|
|
243
|
+
if (e instanceof AggregateError)
|
|
244
|
+
console.error(`[flakiness.io err]`, e.errors[0].message);
|
|
245
|
+
else if (e instanceof Error)
|
|
246
|
+
console.error(`[flakiness.io err]`, e.message);
|
|
247
|
+
else
|
|
248
|
+
console.error(`[flakiness.io err]`, e);
|
|
249
|
+
await new Promise((x) => setTimeout(x, timeout));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return await job();
|
|
253
|
+
}
|
|
254
|
+
var httpUtils;
|
|
255
|
+
((httpUtils2) => {
|
|
256
|
+
function createRequest({ url, method = "get", headers = {} }) {
|
|
257
|
+
let resolve;
|
|
258
|
+
let reject;
|
|
259
|
+
const responseDataPromise = new Promise((a, b) => {
|
|
260
|
+
resolve = a;
|
|
261
|
+
reject = b;
|
|
262
|
+
});
|
|
263
|
+
const protocol = url.startsWith("https") ? https : http;
|
|
264
|
+
const request = protocol.request(url, { method, headers }, (res) => {
|
|
265
|
+
const chunks = [];
|
|
266
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
267
|
+
res.on("end", () => {
|
|
268
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
|
|
269
|
+
resolve(Buffer.concat(chunks));
|
|
270
|
+
else
|
|
271
|
+
reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
|
|
272
|
+
});
|
|
273
|
+
res.on("error", (error) => reject(error));
|
|
274
|
+
});
|
|
275
|
+
request.on("error", reject);
|
|
276
|
+
return { request, responseDataPromise };
|
|
277
|
+
}
|
|
278
|
+
httpUtils2.createRequest = createRequest;
|
|
279
|
+
async function getBuffer(url, backoff) {
|
|
280
|
+
return await retryWithBackoff(async () => {
|
|
281
|
+
const { request, responseDataPromise } = createRequest({ url });
|
|
282
|
+
request.end();
|
|
283
|
+
return await responseDataPromise;
|
|
284
|
+
}, backoff);
|
|
285
|
+
}
|
|
286
|
+
httpUtils2.getBuffer = getBuffer;
|
|
287
|
+
async function getText(url, backoff) {
|
|
288
|
+
const buffer = await getBuffer(url, backoff);
|
|
289
|
+
return buffer.toString("utf-8");
|
|
290
|
+
}
|
|
291
|
+
httpUtils2.getText = getText;
|
|
292
|
+
async function getJSON(url) {
|
|
293
|
+
return JSON.parse(await getText(url));
|
|
294
|
+
}
|
|
295
|
+
httpUtils2.getJSON = getJSON;
|
|
296
|
+
async function postText(url, text, backoff) {
|
|
297
|
+
const headers = {
|
|
298
|
+
"Content-Type": "application/json",
|
|
299
|
+
"Content-Length": Buffer.byteLength(text) + ""
|
|
300
|
+
};
|
|
301
|
+
return await retryWithBackoff(async () => {
|
|
302
|
+
const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
|
|
303
|
+
request.write(text);
|
|
304
|
+
request.end();
|
|
305
|
+
return await responseDataPromise;
|
|
306
|
+
}, backoff);
|
|
307
|
+
}
|
|
308
|
+
httpUtils2.postText = postText;
|
|
309
|
+
async function postJSON(url, json, backoff) {
|
|
310
|
+
const buffer = await postText(url, JSON.stringify(json), backoff);
|
|
311
|
+
return JSON.parse(buffer.toString("utf-8"));
|
|
312
|
+
}
|
|
313
|
+
httpUtils2.postJSON = postJSON;
|
|
314
|
+
})(httpUtils || (httpUtils = {}));
|
|
315
|
+
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");
|
|
316
|
+
var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
|
|
317
|
+
var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
|
|
318
|
+
|
|
319
|
+
// src/serverapi.ts
|
|
320
|
+
function createServerAPI(endpoint, options) {
|
|
321
|
+
endpoint += "/api/";
|
|
322
|
+
const fetcher = options?.auth ? (url, init) => fetch(url, {
|
|
323
|
+
...init,
|
|
324
|
+
headers: {
|
|
325
|
+
...init.headers,
|
|
326
|
+
"Authorization": `Bearer ${options.auth}`
|
|
327
|
+
}
|
|
328
|
+
}) : fetch;
|
|
329
|
+
if (options?.retries)
|
|
330
|
+
return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
|
|
331
|
+
return TypedHTTP.createClient(endpoint, fetcher);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/flakinessSession.ts
|
|
335
|
+
var CONFIG_DIR = (() => {
|
|
336
|
+
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");
|
|
337
|
+
return configDir;
|
|
338
|
+
})();
|
|
339
|
+
var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
340
|
+
var FlakinessSession = class _FlakinessSession {
|
|
341
|
+
constructor(_config) {
|
|
342
|
+
this._config = _config;
|
|
343
|
+
this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
|
|
344
|
+
}
|
|
345
|
+
static async load() {
|
|
346
|
+
const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
|
|
347
|
+
if (!data)
|
|
348
|
+
return void 0;
|
|
349
|
+
const json = JSON.parse(data);
|
|
350
|
+
return new _FlakinessSession(json);
|
|
351
|
+
}
|
|
352
|
+
static async remove() {
|
|
353
|
+
await fs.unlink(CONFIG_PATH).catch((e) => void 0);
|
|
354
|
+
}
|
|
355
|
+
api;
|
|
356
|
+
endpoint() {
|
|
357
|
+
return this._config.endpoint;
|
|
358
|
+
}
|
|
359
|
+
path() {
|
|
360
|
+
return CONFIG_PATH;
|
|
361
|
+
}
|
|
362
|
+
sessionToken() {
|
|
363
|
+
return this._config.token;
|
|
364
|
+
}
|
|
365
|
+
async save() {
|
|
366
|
+
await fs.mkdir(CONFIG_DIR, { recursive: true });
|
|
367
|
+
await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// src/cli/cmd-logout.ts
|
|
372
|
+
async function cmdLogout() {
|
|
373
|
+
await FlakinessSession.remove();
|
|
374
|
+
}
|
|
375
|
+
export {
|
|
376
|
+
cmdLogout
|
|
377
|
+
};
|
|
378
|
+
//# sourceMappingURL=cmd-logout.js.map
|