@flakiness/sdk 0.145.0 → 0.146.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/{flakinessConfig.js → flakinessProjectConfig.js} +10 -17
- package/lib/playwright-test.js +243 -294
- package/lib/{cli/cmd-show-report.js → showReport.js} +37 -106
- package/package.json +14 -17
- package/types/tsconfig.tsbuildinfo +1 -1
- package/lib/cli/cli.js +0 -2382
- package/lib/cli/cmd-convert.js +0 -421
- package/lib/cli/cmd-download.js +0 -42
- package/lib/cli/cmd-link.js +0 -207
- package/lib/cli/cmd-login.js +0 -223
- package/lib/cli/cmd-logout.js +0 -170
- package/lib/cli/cmd-status.js +0 -273
- package/lib/cli/cmd-unlink.js +0 -199
- package/lib/cli/cmd-upload-playwright-json.js +0 -614
- package/lib/cli/cmd-upload.js +0 -321
- package/lib/cli/cmd-whoami.js +0 -173
- package/lib/flakinessSession.js +0 -159
- package/lib/junit.js +0 -310
- package/lib/playwrightJSONReport.js +0 -430
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/showReport.ts
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import open from "open";
|
|
4
|
-
import
|
|
4
|
+
import path4 from "path";
|
|
5
5
|
|
|
6
|
-
// src/
|
|
6
|
+
// src/flakinessProjectConfig.ts
|
|
7
7
|
import fs2 from "fs";
|
|
8
8
|
import path2 from "path";
|
|
9
9
|
|
|
@@ -163,7 +163,7 @@ function normalizePath(aPath) {
|
|
|
163
163
|
return aPath;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
// src/
|
|
166
|
+
// src/flakinessProjectConfig.ts
|
|
167
167
|
function createConfigPath(dir) {
|
|
168
168
|
return path2.join(dir, ".flakiness", "config.json");
|
|
169
169
|
}
|
|
@@ -186,7 +186,7 @@ function computeConfigPath() {
|
|
|
186
186
|
return createConfigPath(process.cwd());
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
var
|
|
189
|
+
var FlakinessProjectConfig = class _FlakinessProjectConfig {
|
|
190
190
|
constructor(_configPath, _config) {
|
|
191
191
|
this._configPath = _configPath;
|
|
192
192
|
this._config = _config;
|
|
@@ -195,20 +195,10 @@ var FlakinessConfig = class _FlakinessConfig {
|
|
|
195
195
|
const configPath = ensureConfigPath();
|
|
196
196
|
const data = await fs2.promises.readFile(configPath, "utf-8").catch((e) => void 0);
|
|
197
197
|
const json = data ? JSON.parse(data) : {};
|
|
198
|
-
return new
|
|
199
|
-
}
|
|
200
|
-
static async projectOrDie(session) {
|
|
201
|
-
const config = await _FlakinessConfig.load();
|
|
202
|
-
const projectPublicId = config.projectPublicId();
|
|
203
|
-
if (!projectPublicId)
|
|
204
|
-
throw new Error(`Please link to flakiness project with 'npx flakiness link'`);
|
|
205
|
-
const project = await session.api.project.getProject.GET({ projectPublicId }).catch((e) => void 0);
|
|
206
|
-
if (!project)
|
|
207
|
-
throw new Error(`Failed to fetch linked project; please re-link with 'npx flakiness link'`);
|
|
208
|
-
return project;
|
|
198
|
+
return new _FlakinessProjectConfig(configPath, json);
|
|
209
199
|
}
|
|
210
200
|
static createEmpty() {
|
|
211
|
-
return new
|
|
201
|
+
return new _FlakinessProjectConfig(ensureConfigPath(), {});
|
|
212
202
|
}
|
|
213
203
|
path() {
|
|
214
204
|
return this._configPath;
|
|
@@ -216,6 +206,9 @@ var FlakinessConfig = class _FlakinessConfig {
|
|
|
216
206
|
projectPublicId() {
|
|
217
207
|
return this._config.projectPublicId;
|
|
218
208
|
}
|
|
209
|
+
reportViewerEndpoint() {
|
|
210
|
+
return this._config.customReportViewerEndpoint ?? "https://report.flakiness.io";
|
|
211
|
+
}
|
|
219
212
|
setProjectPublicId(projectId) {
|
|
220
213
|
this._config.projectPublicId = projectId;
|
|
221
214
|
}
|
|
@@ -225,72 +218,8 @@ var FlakinessConfig = class _FlakinessConfig {
|
|
|
225
218
|
}
|
|
226
219
|
};
|
|
227
220
|
|
|
228
|
-
// src/flakinessSession.ts
|
|
229
|
-
import fs3 from "fs/promises";
|
|
230
|
-
import os from "os";
|
|
231
|
-
import path3 from "path";
|
|
232
|
-
|
|
233
|
-
// src/serverapi.ts
|
|
234
|
-
import { TypedHTTP } from "@flakiness/shared/common/typedHttp.js";
|
|
235
|
-
function createServerAPI(endpoint, options) {
|
|
236
|
-
endpoint += "/api/";
|
|
237
|
-
const fetcher = options?.auth ? (url, init) => fetch(url, {
|
|
238
|
-
...init,
|
|
239
|
-
headers: {
|
|
240
|
-
...init.headers,
|
|
241
|
-
"Authorization": `Bearer ${options.auth}`
|
|
242
|
-
}
|
|
243
|
-
}) : fetch;
|
|
244
|
-
if (options?.retries)
|
|
245
|
-
return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
|
|
246
|
-
return TypedHTTP.createClient(endpoint, fetcher);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// src/flakinessSession.ts
|
|
250
|
-
var CONFIG_DIR = (() => {
|
|
251
|
-
const configDir = process.platform === "darwin" ? path3.join(os.homedir(), "Library", "Application Support", "flakiness") : process.platform === "win32" ? path3.join(os.homedir(), "AppData", "Roaming", "flakiness") : path3.join(os.homedir(), ".config", "flakiness");
|
|
252
|
-
return configDir;
|
|
253
|
-
})();
|
|
254
|
-
var CONFIG_PATH = path3.join(CONFIG_DIR, "config.json");
|
|
255
|
-
var FlakinessSession = class _FlakinessSession {
|
|
256
|
-
constructor(_config) {
|
|
257
|
-
this._config = _config;
|
|
258
|
-
this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
|
|
259
|
-
}
|
|
260
|
-
static async loadOrDie() {
|
|
261
|
-
const session = await _FlakinessSession.load();
|
|
262
|
-
if (!session)
|
|
263
|
-
throw new Error(`Please login first with 'npx flakiness login'`);
|
|
264
|
-
return session;
|
|
265
|
-
}
|
|
266
|
-
static async load() {
|
|
267
|
-
const data = await fs3.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
|
|
268
|
-
if (!data)
|
|
269
|
-
return void 0;
|
|
270
|
-
const json = JSON.parse(data);
|
|
271
|
-
return new _FlakinessSession(json);
|
|
272
|
-
}
|
|
273
|
-
static async remove() {
|
|
274
|
-
await fs3.unlink(CONFIG_PATH).catch((e) => void 0);
|
|
275
|
-
}
|
|
276
|
-
api;
|
|
277
|
-
endpoint() {
|
|
278
|
-
return this._config.endpoint;
|
|
279
|
-
}
|
|
280
|
-
path() {
|
|
281
|
-
return CONFIG_PATH;
|
|
282
|
-
}
|
|
283
|
-
sessionToken() {
|
|
284
|
-
return this._config.token;
|
|
285
|
-
}
|
|
286
|
-
async save() {
|
|
287
|
-
await fs3.mkdir(CONFIG_DIR, { recursive: true });
|
|
288
|
-
await fs3.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
221
|
// src/localReportServer.ts
|
|
293
|
-
import { TypedHTTP as
|
|
222
|
+
import { TypedHTTP as TypedHTTP2 } from "@flakiness/shared/common/typedHttp.js";
|
|
294
223
|
import { randomUUIDBase62 } from "@flakiness/shared/node/nodeutils.js";
|
|
295
224
|
import { createTypedHttpExpressMiddleware } from "@flakiness/shared/node/typedHttpExpress.js";
|
|
296
225
|
import bodyParser from "body-parser";
|
|
@@ -301,9 +230,9 @@ import "express-async-errors";
|
|
|
301
230
|
import http2 from "http";
|
|
302
231
|
|
|
303
232
|
// src/localReportApi.ts
|
|
304
|
-
import { TypedHTTP
|
|
305
|
-
import
|
|
306
|
-
import
|
|
233
|
+
import { TypedHTTP } from "@flakiness/shared/common/typedHttp.js";
|
|
234
|
+
import fs3 from "fs";
|
|
235
|
+
import path3 from "path";
|
|
307
236
|
import { z } from "zod/v4";
|
|
308
237
|
|
|
309
238
|
// src/localGit.ts
|
|
@@ -358,7 +287,7 @@ var ReportInfo = class {
|
|
|
358
287
|
attachmentIdToPath = /* @__PURE__ */ new Map();
|
|
359
288
|
commits = [];
|
|
360
289
|
async refresh() {
|
|
361
|
-
const report = await
|
|
290
|
+
const report = await fs3.promises.readFile(this._options.reportPath, "utf-8").then((x) => JSON.parse(x)).catch((e) => void 0);
|
|
362
291
|
if (!report) {
|
|
363
292
|
this.report = void 0;
|
|
364
293
|
this.commits = [];
|
|
@@ -368,7 +297,7 @@ var ReportInfo = class {
|
|
|
368
297
|
if (JSON.stringify(report) === JSON.stringify(this.report))
|
|
369
298
|
return;
|
|
370
299
|
this.report = report;
|
|
371
|
-
this.commits = await listLocalCommits(
|
|
300
|
+
this.commits = await listLocalCommits(path3.dirname(this._options.reportPath), report.commitId, 100);
|
|
372
301
|
const attachmentsDir = this._options.attachmentsFolder;
|
|
373
302
|
const { attachmentIdToPath, missingAttachments } = await resolveAttachmentPaths(report, attachmentsDir);
|
|
374
303
|
if (missingAttachments.length) {
|
|
@@ -381,7 +310,7 @@ var ReportInfo = class {
|
|
|
381
310
|
this.attachmentIdToPath = attachmentIdToPath;
|
|
382
311
|
}
|
|
383
312
|
};
|
|
384
|
-
var t =
|
|
313
|
+
var t = TypedHTTP.Router.create();
|
|
385
314
|
var localReportRouter = {
|
|
386
315
|
ping: t.get({
|
|
387
316
|
handler: async () => {
|
|
@@ -401,9 +330,9 @@ var localReportRouter = {
|
|
|
401
330
|
handler: async ({ ctx, input }) => {
|
|
402
331
|
const idx = ctx.reportInfo.attachmentIdToPath.get(input.attachmentId);
|
|
403
332
|
if (!idx)
|
|
404
|
-
throw
|
|
405
|
-
const buffer = await
|
|
406
|
-
return
|
|
333
|
+
throw TypedHTTP.HttpError.withCode("NOT_FOUND");
|
|
334
|
+
const buffer = await fs3.promises.readFile(idx.path);
|
|
335
|
+
return TypedHTTP.ok(buffer, idx.contentType);
|
|
407
336
|
}
|
|
408
337
|
}),
|
|
409
338
|
json: t.get({
|
|
@@ -431,7 +360,7 @@ var LocalReportServer = class _LocalReportServer {
|
|
|
431
360
|
app.use(bodyParser.json({ limit: 256 * 1024 }));
|
|
432
361
|
app.use((req, res, next) => {
|
|
433
362
|
if (!req.path.startsWith("/" + authToken))
|
|
434
|
-
throw
|
|
363
|
+
throw TypedHTTP2.HttpError.withCode("UNAUTHORIZED");
|
|
435
364
|
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
436
365
|
res.setHeader("Access-Control-Allow-Origin", options.endpoint);
|
|
437
366
|
res.setHeader("Access-Control-Allow-Methods", "*");
|
|
@@ -452,7 +381,7 @@ var LocalReportServer = class _LocalReportServer {
|
|
|
452
381
|
createRootContext: async ({ req, res, input }) => ({ reportInfo })
|
|
453
382
|
}));
|
|
454
383
|
app.use((err, req, res, next) => {
|
|
455
|
-
if (err instanceof
|
|
384
|
+
if (err instanceof TypedHTTP2.HttpError)
|
|
456
385
|
return res.status(err.status).send({ error: err.message });
|
|
457
386
|
logHTTPServer(err);
|
|
458
387
|
res.status(500).send({ error: "Internal Server Error" });
|
|
@@ -481,29 +410,31 @@ var LocalReportServer = class _LocalReportServer {
|
|
|
481
410
|
}
|
|
482
411
|
};
|
|
483
412
|
|
|
484
|
-
// src/
|
|
485
|
-
async function
|
|
486
|
-
const reportPath =
|
|
487
|
-
const
|
|
488
|
-
const config = await FlakinessConfig.load();
|
|
413
|
+
// src/showReport.ts
|
|
414
|
+
async function showReport(reportFolder) {
|
|
415
|
+
const reportPath = path4.join(reportFolder, "report.json");
|
|
416
|
+
const config = await FlakinessProjectConfig.load();
|
|
489
417
|
const projectPublicId = config.projectPublicId();
|
|
490
|
-
const
|
|
491
|
-
const endpoint = session?.endpoint() ?? "https://flakiness.io";
|
|
418
|
+
const reportViewerEndpoint = config.reportViewerEndpoint();
|
|
492
419
|
const server = await LocalReportServer.create({
|
|
493
|
-
endpoint,
|
|
420
|
+
endpoint: reportViewerEndpoint,
|
|
494
421
|
port: 9373,
|
|
495
422
|
reportPath,
|
|
496
423
|
attachmentsFolder: reportFolder
|
|
497
424
|
});
|
|
498
|
-
const
|
|
425
|
+
const url = new URL(reportViewerEndpoint);
|
|
426
|
+
url.searchParams.set("port", String(server.port()));
|
|
427
|
+
url.searchParams.set("token", server.authToken());
|
|
428
|
+
if (projectPublicId)
|
|
429
|
+
url.searchParams.set("ppid", projectPublicId);
|
|
499
430
|
console.log(chalk.cyan(`
|
|
500
|
-
Serving Flakiness report at ${
|
|
431
|
+
Serving Flakiness report at ${url.toString()}
|
|
501
432
|
Press Ctrl+C to quit.`));
|
|
502
|
-
await open(
|
|
433
|
+
await open(url.toString());
|
|
503
434
|
await new Promise(() => {
|
|
504
435
|
});
|
|
505
436
|
}
|
|
506
437
|
export {
|
|
507
|
-
|
|
438
|
+
showReport
|
|
508
439
|
};
|
|
509
|
-
//# sourceMappingURL=
|
|
440
|
+
//# sourceMappingURL=showReport.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flakiness/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.146.0",
|
|
4
4
|
"private": false,
|
|
5
|
-
"bin": {
|
|
6
|
-
"flakiness": "./lib/cli/cli.js"
|
|
7
|
-
},
|
|
8
5
|
"exports": {
|
|
9
6
|
"./localReportApi": {
|
|
10
7
|
"types": "./types/src/localReportApi.d.ts"
|
|
@@ -14,21 +11,21 @@
|
|
|
14
11
|
"import": "./lib/reportUploader.js",
|
|
15
12
|
"require": "./lib/reportUploader.js"
|
|
16
13
|
},
|
|
14
|
+
"./showReport": {
|
|
15
|
+
"types": "./types/src/showReport.d.ts",
|
|
16
|
+
"import": "./lib/showReport.js",
|
|
17
|
+
"require": "./lib/showReport.js"
|
|
18
|
+
},
|
|
19
|
+
"./flakinessProjectConfig": {
|
|
20
|
+
"types": "./types/src/flakinessProjectConfig.d.ts",
|
|
21
|
+
"import": "./lib/flakinessProjectConfig.js",
|
|
22
|
+
"require": "./lib/flakinessProjectConfig.js"
|
|
23
|
+
},
|
|
17
24
|
"./utils": {
|
|
18
25
|
"types": "./types/src/utils.d.ts",
|
|
19
26
|
"import": "./lib/utils.js",
|
|
20
27
|
"require": "./lib/utils.js"
|
|
21
28
|
},
|
|
22
|
-
"./playwright": {
|
|
23
|
-
"types": "./types/src/playwrightJSONReport.d.ts",
|
|
24
|
-
"import": "./lib/playwrightJSONReport.js",
|
|
25
|
-
"require": "./lib/playwrightJSONReport.js"
|
|
26
|
-
},
|
|
27
|
-
"./junit": {
|
|
28
|
-
"types": "./types/src/junit.d.ts",
|
|
29
|
-
"import": "./lib/junit.js",
|
|
30
|
-
"require": "./lib/junit.js"
|
|
31
|
-
},
|
|
32
29
|
"./playwright-test": {
|
|
33
30
|
"types": "./types/src/playwright-test.d.ts",
|
|
34
31
|
"import": "./lib/playwright-test.js",
|
|
@@ -50,7 +47,7 @@
|
|
|
50
47
|
"author": "Degu Labs, Inc",
|
|
51
48
|
"license": "Fair Source 100",
|
|
52
49
|
"devDependencies": {
|
|
53
|
-
"@flakiness/server": "0.
|
|
50
|
+
"@flakiness/server": "0.146.0",
|
|
54
51
|
"@playwright/test": "^1.57.0",
|
|
55
52
|
"@types/babel__code-frame": "^7.0.6",
|
|
56
53
|
"@types/compression": "^1.8.1",
|
|
@@ -58,8 +55,8 @@
|
|
|
58
55
|
},
|
|
59
56
|
"dependencies": {
|
|
60
57
|
"@babel/code-frame": "^7.26.2",
|
|
61
|
-
"@flakiness/report": "0.
|
|
62
|
-
"@flakiness/shared": "0.
|
|
58
|
+
"@flakiness/report": "0.146.0",
|
|
59
|
+
"@flakiness/shared": "0.146.0",
|
|
63
60
|
"@rgrove/parse-xml": "^4.2.0",
|
|
64
61
|
"body-parser": "^1.20.3",
|
|
65
62
|
"chalk": "^5.6.2",
|