@flakiness/sdk 0.149.1 → 0.150.1
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/README.md +9 -4
- package/lib/_internalUtils.js +2 -68
- package/lib/browser.js +2 -149
- package/lib/ciUtils.js +0 -1
- package/lib/createEnvironment.js +1 -105
- package/lib/createTestStepSnippets.js +1 -19
- package/lib/flakinessProjectConfig.js +6 -317
- package/lib/gitWorktree.js +8 -112
- package/lib/index.js +9 -1244
- package/lib/normalizeReport.js +2 -3
- package/lib/reportUtils.js +9 -384
- package/lib/reportUtilsBrowser.js +3 -132
- package/lib/showReport.js +3 -612
- package/lib/staticServer.js +7 -8
- package/lib/stripAnsi.js +1 -2
- package/lib/systemUtilizationSampler.js +2 -3
- package/lib/uploadReport.js +33 -148
- package/lib/visitTests.js +0 -1
- package/lib/writeReport.js +0 -1
- package/package.json +14 -5
- package/types/src/_internalUtils.d.ts +13 -0
- package/types/src/_internalUtils.d.ts.map +1 -0
- package/types/src/browser.d.ts +3 -0
- package/types/src/browser.d.ts.map +1 -0
- package/types/src/ciUtils.d.ts +33 -0
- package/types/src/ciUtils.d.ts.map +1 -0
- package/types/src/createEnvironment.d.ts +40 -0
- package/types/src/createEnvironment.d.ts.map +1 -0
- package/types/src/createTestStepSnippets.d.ts +30 -0
- package/types/src/createTestStepSnippets.d.ts.map +1 -0
- package/types/src/flakinessProjectConfig.d.ts +103 -0
- package/types/src/flakinessProjectConfig.d.ts.map +1 -0
- package/types/src/gitWorktree.d.ts +139 -0
- package/types/src/gitWorktree.d.ts.map +1 -0
- package/types/src/index.d.ts +10 -0
- package/types/src/index.d.ts.map +1 -0
- package/types/src/normalizeReport.d.ts +26 -0
- package/types/src/normalizeReport.d.ts.map +1 -0
- package/types/src/reportUtils.d.ts +8 -0
- package/types/src/reportUtils.d.ts.map +1 -0
- package/types/src/reportUtilsBrowser.d.ts +4 -0
- package/types/src/reportUtilsBrowser.d.ts.map +1 -0
- package/types/src/showReport.d.ts +18 -0
- package/types/src/showReport.d.ts.map +1 -0
- package/types/src/staticServer.d.ts +16 -0
- package/types/src/staticServer.d.ts.map +1 -0
- package/types/src/stripAnsi.d.ts +19 -0
- package/types/src/stripAnsi.d.ts.map +1 -0
- package/types/src/systemUtilizationSampler.d.ts +43 -0
- package/types/src/systemUtilizationSampler.d.ts.map +1 -0
- package/types/src/uploadReport.d.ts +196 -0
- package/types/src/uploadReport.d.ts.map +1 -0
- package/types/src/visitTests.d.ts +28 -0
- package/types/src/visitTests.d.ts.map +1 -0
- package/types/src/writeReport.d.ts +45 -0
- package/types/src/writeReport.d.ts.map +1 -0
- package/types/tsconfig.tsbuildinfo +0 -1
package/lib/showReport.js
CHANGED
|
@@ -1,617 +1,8 @@
|
|
|
1
|
-
// src/showReport.ts
|
|
2
1
|
import chalk from "chalk";
|
|
3
2
|
import open from "open";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import crypto from "crypto";
|
|
8
|
-
import http from "http";
|
|
9
|
-
import https from "https";
|
|
10
|
-
import util from "util";
|
|
11
|
-
import zlib from "zlib";
|
|
12
|
-
var asyncBrotliCompress = util.promisify(zlib.brotliCompress);
|
|
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 resolve2;
|
|
37
|
-
let reject;
|
|
38
|
-
const responseDataPromise = new Promise((a, b) => {
|
|
39
|
-
resolve2 = 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
|
-
resolve2(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
|
-
function shell(command, args, options) {
|
|
96
|
-
try {
|
|
97
|
-
const result = spawnSync(command, args, { encoding: "utf-8", ...options });
|
|
98
|
-
if (result.status !== 0) {
|
|
99
|
-
return void 0;
|
|
100
|
-
}
|
|
101
|
-
return result.stdout.trim();
|
|
102
|
-
} catch (e) {
|
|
103
|
-
console.error(e);
|
|
104
|
-
return void 0;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function randomUUIDBase62() {
|
|
108
|
-
const BASE62_CHARSET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
109
|
-
let num = BigInt("0x" + crypto.randomUUID().replace(/-/g, ""));
|
|
110
|
-
if (num === 0n)
|
|
111
|
-
return BASE62_CHARSET[0];
|
|
112
|
-
const chars = [];
|
|
113
|
-
while (num > 0n) {
|
|
114
|
-
const remainder = Number(num % 62n);
|
|
115
|
-
num /= 62n;
|
|
116
|
-
chars.push(BASE62_CHARSET[remainder]);
|
|
117
|
-
}
|
|
118
|
-
return chars.reverse().join("");
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// src/flakinessProjectConfig.ts
|
|
122
|
-
import fs from "fs";
|
|
123
|
-
import path from "path";
|
|
124
|
-
|
|
125
|
-
// src/gitWorktree.ts
|
|
126
|
-
import assert from "assert";
|
|
127
|
-
import { exec } from "child_process";
|
|
128
|
-
import debug from "debug";
|
|
129
|
-
import { posix as posixPath, win32 as win32Path } from "path";
|
|
130
|
-
import { promisify } from "util";
|
|
131
|
-
var log = debug("fk:git");
|
|
132
|
-
var execAsync = promisify(exec);
|
|
133
|
-
var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
|
|
134
|
-
var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
|
|
135
|
-
function toPosixAbsolutePath(absolutePath) {
|
|
136
|
-
if (IS_WIN32_PATH.test(absolutePath)) {
|
|
137
|
-
absolutePath = absolutePath.split(win32Path.sep).join(posixPath.sep);
|
|
138
|
-
}
|
|
139
|
-
if (IS_ALMOST_POSIX_PATH.test(absolutePath))
|
|
140
|
-
return "/" + absolutePath[0] + absolutePath.substring(2);
|
|
141
|
-
return absolutePath;
|
|
142
|
-
}
|
|
143
|
-
function toNativeAbsolutePath(posix) {
|
|
144
|
-
if (process.platform !== "win32")
|
|
145
|
-
return posix;
|
|
146
|
-
assert(posix.startsWith("/"), "The path must be absolute");
|
|
147
|
-
const m = posix.match(/^\/([a-zA-Z])(\/.*)?$/);
|
|
148
|
-
assert(m, `Invalid POSIX path: ${posix}`);
|
|
149
|
-
const drive = m[1];
|
|
150
|
-
const rest = (m[2] ?? "").split(posixPath.sep).join(win32Path.sep);
|
|
151
|
-
return drive.toUpperCase() + ":" + rest;
|
|
152
|
-
}
|
|
153
|
-
var GitWorktree = class _GitWorktree {
|
|
154
|
-
constructor(_gitRoot) {
|
|
155
|
-
this._gitRoot = _gitRoot;
|
|
156
|
-
this._posixGitRoot = toPosixAbsolutePath(this._gitRoot);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Creates a GitWorktree instance from any path inside a git repository.
|
|
160
|
-
*
|
|
161
|
-
* @param {string} somePathInsideGitRepo - Any path (file or directory) within a git repository.
|
|
162
|
-
* Can be absolute or relative. The function will locate the git root directory.
|
|
163
|
-
*
|
|
164
|
-
* @returns {GitWorktree} A new GitWorktree instance bound to the discovered git root.
|
|
165
|
-
*
|
|
166
|
-
* @throws {Error} Throws if the path is not inside a git repository or if git commands fail.
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* const worktree = GitWorktree.create('./src/my-test.ts');
|
|
171
|
-
* const gitRoot = worktree.rootPath();
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
static create(somePathInsideGitRepo) {
|
|
175
|
-
const root = shell(`git`, ["rev-parse", "--show-toplevel"], {
|
|
176
|
-
cwd: somePathInsideGitRepo,
|
|
177
|
-
encoding: "utf-8"
|
|
178
|
-
});
|
|
179
|
-
assert(root, `FAILED: git rev-parse --show-toplevel HEAD @ ${somePathInsideGitRepo}`);
|
|
180
|
-
return new _GitWorktree(root);
|
|
181
|
-
}
|
|
182
|
-
_posixGitRoot;
|
|
183
|
-
/**
|
|
184
|
-
* Returns the native absolute path of the git repository root directory.
|
|
185
|
-
*
|
|
186
|
-
* @returns {string} Native absolute path to the git root. Format matches the current platform
|
|
187
|
-
* (Windows or POSIX).
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
* const root = worktree.rootPath();
|
|
192
|
-
* // On Windows: 'D:\project'
|
|
193
|
-
* // On Unix: '/project'
|
|
194
|
-
* ```
|
|
195
|
-
*/
|
|
196
|
-
rootPath() {
|
|
197
|
-
return this._gitRoot;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Returns the commit ID (SHA-1 hash) of the current HEAD commit.
|
|
201
|
-
*
|
|
202
|
-
* @returns {FlakinessReport.CommitId} Full 40-character commit hash of the HEAD commit.
|
|
203
|
-
*
|
|
204
|
-
* @throws {Error} Throws if git command fails or repository is in an invalid state.
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* const commitId = worktree.headCommitId();
|
|
209
|
-
* // Returns: 'a1b2c3d4e5f6...' (40-character SHA-1)
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
headCommitId() {
|
|
213
|
-
const sha = shell(`git`, ["rev-parse", "HEAD"], {
|
|
214
|
-
cwd: this._gitRoot,
|
|
215
|
-
encoding: "utf-8"
|
|
216
|
-
});
|
|
217
|
-
assert(sha, `FAILED: git rev-parse HEAD @ ${this._gitRoot}`);
|
|
218
|
-
return sha.trim();
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Converts a native absolute path to a git-relative POSIX path.
|
|
222
|
-
*
|
|
223
|
-
* Takes any absolute path (Windows or POSIX format) and converts it to a POSIX path
|
|
224
|
-
* relative to the git repository root. This is essential for Flakiness reports where
|
|
225
|
-
* all file paths must be git-relative and use POSIX separators.
|
|
226
|
-
*
|
|
227
|
-
* @param {string} absolutePath - Native absolute path to convert. Can be in Windows format
|
|
228
|
-
* (e.g., `D:\project\src\test.ts`) or POSIX format (e.g., `/project/src/test.ts`).
|
|
229
|
-
*
|
|
230
|
-
* @returns {FlakinessReport.GitFilePath} POSIX path relative to git root (e.g., `src/test.ts`).
|
|
231
|
-
* Returns an empty string if the path is the git root itself.
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```typescript
|
|
235
|
-
* const gitPath = worktree.gitPath('/Users/project/src/test.ts');
|
|
236
|
-
* // Returns: 'src/test.ts'
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
gitPath(absolutePath) {
|
|
240
|
-
return posixPath.relative(this._posixGitRoot, toPosixAbsolutePath(absolutePath));
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Converts a git-relative POSIX path to a native absolute path.
|
|
244
|
-
*
|
|
245
|
-
* Takes a POSIX path relative to the git root and converts it to the native absolute path
|
|
246
|
-
* format for the current platform (Windows or POSIX). This is the inverse of `gitPath()`.
|
|
247
|
-
*
|
|
248
|
-
* @param {FlakinessReport.GitFilePath} relativePath - POSIX path relative to git root
|
|
249
|
-
* (e.g., `src/test.ts`).
|
|
250
|
-
*
|
|
251
|
-
* @returns {string} Native absolute path. On Windows, returns Windows format (e.g., `D:\project\src\test.ts`).
|
|
252
|
-
* On POSIX systems, returns POSIX format (e.g., `/project/src/test.ts`).
|
|
253
|
-
*
|
|
254
|
-
* @example
|
|
255
|
-
* ```typescript
|
|
256
|
-
* const absolutePath = worktree.absolutePath('src/test.ts');
|
|
257
|
-
* // On Windows: 'D:\project\src\test.ts'
|
|
258
|
-
* // On Unix: '/project/src/test.ts'
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
absolutePath(relativePath) {
|
|
262
|
-
return toNativeAbsolutePath(posixPath.join(this._posixGitRoot, relativePath));
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Lists recent commits from the repository.
|
|
266
|
-
*
|
|
267
|
-
* Retrieves commit information including commit ID, timestamp, author, message, and parent commits.
|
|
268
|
-
* Note: CI environments often have shallow checkouts with limited history, which may affect
|
|
269
|
-
* the number of commits returned.
|
|
270
|
-
*
|
|
271
|
-
* @param {number} count - Maximum number of commits to retrieve, starting from HEAD.
|
|
272
|
-
*
|
|
273
|
-
* @returns {Promise<GitCommit[]>} Promise that resolves to an array of commit objects, ordered
|
|
274
|
-
* from most recent to oldest. Each commit includes:
|
|
275
|
-
* - `commitId` - Full commit hash
|
|
276
|
-
* - `timestamp` - Commit timestamp in milliseconds since Unix epoch
|
|
277
|
-
* - `message` - Commit message (subject line)
|
|
278
|
-
* - `author` - Author name
|
|
279
|
-
* - `parents` - Array of parent commit IDs
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* ```typescript
|
|
283
|
-
* const commits = await worktree.listCommits(10);
|
|
284
|
-
* console.log(`Latest commit: ${commits[0].message}`);
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
async listCommits(count) {
|
|
288
|
-
return await listCommits(this._gitRoot, "HEAD", count);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
async function listCommits(gitRoot, head, count) {
|
|
292
|
-
const FIELD_SEPARATOR = "|~|";
|
|
293
|
-
const RECORD_SEPARATOR = "\0";
|
|
294
|
-
const prettyFormat = [
|
|
295
|
-
"%H",
|
|
296
|
-
// Full commit hash
|
|
297
|
-
"%ct",
|
|
298
|
-
// Commit timestamp (Unix seconds)
|
|
299
|
-
"%an",
|
|
300
|
-
// Author name
|
|
301
|
-
"%s",
|
|
302
|
-
// Subject line
|
|
303
|
-
"%P"
|
|
304
|
-
// Parent hashes (space-separated)
|
|
305
|
-
].join(FIELD_SEPARATOR);
|
|
306
|
-
const command = `git log ${head} -n ${count} --pretty=format:"${prettyFormat}" -z`;
|
|
307
|
-
try {
|
|
308
|
-
const { stdout } = await execAsync(command, { cwd: gitRoot });
|
|
309
|
-
if (!stdout) {
|
|
310
|
-
return [];
|
|
311
|
-
}
|
|
312
|
-
return stdout.trim().split(RECORD_SEPARATOR).filter((record) => record).map((record) => {
|
|
313
|
-
const [commitId, timestampStr, author, message, parentsStr] = record.split(FIELD_SEPARATOR);
|
|
314
|
-
const parents = parentsStr ? parentsStr.split(" ").filter((p) => p) : [];
|
|
315
|
-
return {
|
|
316
|
-
commitId,
|
|
317
|
-
timestamp: parseInt(timestampStr, 10) * 1e3,
|
|
318
|
-
author,
|
|
319
|
-
message,
|
|
320
|
-
parents,
|
|
321
|
-
walkIndex: 0
|
|
322
|
-
};
|
|
323
|
-
});
|
|
324
|
-
} catch (error) {
|
|
325
|
-
log(`Failed to list commits for repository at ${gitRoot}:`, error);
|
|
326
|
-
return [];
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// src/flakinessProjectConfig.ts
|
|
331
|
-
function createConfigPath(dir) {
|
|
332
|
-
return path.join(dir, ".flakiness", "config.json");
|
|
333
|
-
}
|
|
334
|
-
var gConfigPath;
|
|
335
|
-
function ensureConfigPath() {
|
|
336
|
-
if (!gConfigPath)
|
|
337
|
-
gConfigPath = computeConfigPath();
|
|
338
|
-
return gConfigPath;
|
|
339
|
-
}
|
|
340
|
-
function computeConfigPath() {
|
|
341
|
-
for (let p = process.cwd(); p !== path.resolve(p, ".."); p = path.resolve(p, "..")) {
|
|
342
|
-
const configPath = createConfigPath(p);
|
|
343
|
-
if (fs.existsSync(configPath))
|
|
344
|
-
return configPath;
|
|
345
|
-
}
|
|
346
|
-
try {
|
|
347
|
-
const worktree = GitWorktree.create(process.cwd());
|
|
348
|
-
return createConfigPath(worktree.rootPath());
|
|
349
|
-
} catch (e) {
|
|
350
|
-
return createConfigPath(process.cwd());
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
var FlakinessProjectConfig = class _FlakinessProjectConfig {
|
|
354
|
-
constructor(_configPath, _config) {
|
|
355
|
-
this._configPath = _configPath;
|
|
356
|
-
this._config = _config;
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Loads the Flakiness project configuration from disk.
|
|
360
|
-
*
|
|
361
|
-
* Searches for an existing `.flakiness/config.json` file starting from the current working
|
|
362
|
-
* directory and walking up the directory tree. If no config exists, it determines the
|
|
363
|
-
* appropriate location (git root or current directory) for future saves.
|
|
364
|
-
*
|
|
365
|
-
* @returns {Promise<FlakinessProjectConfig>} Promise that resolves to a FlakinessProjectConfig
|
|
366
|
-
* instance. If no config file exists, returns an instance with default/empty values.
|
|
367
|
-
*
|
|
368
|
-
* @example
|
|
369
|
-
* ```typescript
|
|
370
|
-
* const config = await FlakinessProjectConfig.load();
|
|
371
|
-
* const projectId = config.projectPublicId();
|
|
372
|
-
* ```
|
|
373
|
-
*/
|
|
374
|
-
static async load() {
|
|
375
|
-
const configPath = ensureConfigPath();
|
|
376
|
-
const data = await fs.promises.readFile(configPath, "utf-8").catch((e) => void 0);
|
|
377
|
-
const json = data ? JSON.parse(data) : {};
|
|
378
|
-
return new _FlakinessProjectConfig(configPath, json);
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Creates a new empty Flakiness project configuration.
|
|
382
|
-
*
|
|
383
|
-
* Creates a configuration instance with no values set. Use this when you want to build
|
|
384
|
-
* a configuration from scratch. Call `save()` to persist it to disk.
|
|
385
|
-
*
|
|
386
|
-
* @returns {FlakinessProjectConfig} A new empty configuration instance.
|
|
387
|
-
*
|
|
388
|
-
* @example
|
|
389
|
-
* ```typescript
|
|
390
|
-
* const config = FlakinessProjectConfig.createEmpty();
|
|
391
|
-
* config.setProjectPublicId('my-project-id');
|
|
392
|
-
* await config.save();
|
|
393
|
-
* ```
|
|
394
|
-
*/
|
|
395
|
-
static createEmpty() {
|
|
396
|
-
return new _FlakinessProjectConfig(ensureConfigPath(), {});
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Returns the absolute path to the configuration file.
|
|
400
|
-
*
|
|
401
|
-
* @returns {string} Absolute path to `.flakiness/config.json`.
|
|
402
|
-
*/
|
|
403
|
-
path() {
|
|
404
|
-
return this._configPath;
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Returns the project's public ID, if configured.
|
|
408
|
-
*
|
|
409
|
-
* The project public ID is used to associate reports with a specific Flakiness.io project.
|
|
410
|
-
*
|
|
411
|
-
* @returns {string | undefined} Project public ID, or `undefined` if not set.
|
|
412
|
-
*/
|
|
413
|
-
projectPublicId() {
|
|
414
|
-
return this._config.projectPublicId;
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Returns the report viewer URL, either custom or default.
|
|
418
|
-
*
|
|
419
|
-
* @returns {string} Custom report viewer URL if configured, otherwise the default
|
|
420
|
-
* `https://report.flakiness.io`.
|
|
421
|
-
*/
|
|
422
|
-
reportViewerUrl() {
|
|
423
|
-
return this._config.customReportViewerUrl ?? "https://report.flakiness.io";
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Sets or clears the custom report viewer URL.
|
|
427
|
-
*
|
|
428
|
-
* @param {string | undefined} url - Custom report viewer URL to use, or `undefined` to
|
|
429
|
-
* clear and use the default URL.
|
|
430
|
-
*/
|
|
431
|
-
setCustomReportViewerUrl(url) {
|
|
432
|
-
if (url)
|
|
433
|
-
this._config.customReportViewerUrl = url;
|
|
434
|
-
else
|
|
435
|
-
delete this._config.customReportViewerUrl;
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Sets the project's public ID.
|
|
439
|
-
*
|
|
440
|
-
* @param {string | undefined} projectId - Project public ID to set, or `undefined` to clear.
|
|
441
|
-
*/
|
|
442
|
-
setProjectPublicId(projectId) {
|
|
443
|
-
this._config.projectPublicId = projectId;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Saves the configuration to disk.
|
|
447
|
-
*
|
|
448
|
-
* Writes the current configuration values to `.flakiness/config.json`. Creates the
|
|
449
|
-
* `.flakiness` directory if it doesn't exist.
|
|
450
|
-
*
|
|
451
|
-
* @returns {Promise<void>} Promise that resolves when the file has been written.
|
|
452
|
-
*
|
|
453
|
-
* @throws {Error} Throws if unable to create directories or write the file.
|
|
454
|
-
*
|
|
455
|
-
* @example
|
|
456
|
-
* ```typescript
|
|
457
|
-
* const config = await FlakinessProjectConfig.load();
|
|
458
|
-
* config.setProjectPublicId('my-project');
|
|
459
|
-
* await config.save();
|
|
460
|
-
* ```
|
|
461
|
-
*/
|
|
462
|
-
async save() {
|
|
463
|
-
await fs.promises.mkdir(path.dirname(this._configPath), { recursive: true });
|
|
464
|
-
await fs.promises.writeFile(this._configPath, JSON.stringify(this._config, null, 2));
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
// src/staticServer.ts
|
|
469
|
-
import debug2 from "debug";
|
|
470
|
-
import * as fs2 from "fs";
|
|
471
|
-
import * as http2 from "http";
|
|
472
|
-
import * as path2 from "path";
|
|
473
|
-
var log2 = debug2("fk:static_server");
|
|
474
|
-
var StaticServer = class {
|
|
475
|
-
_server;
|
|
476
|
-
_absoluteFolderPath;
|
|
477
|
-
_pathPrefix;
|
|
478
|
-
_cors;
|
|
479
|
-
_mimeTypes = {
|
|
480
|
-
".html": "text/html",
|
|
481
|
-
".js": "text/javascript",
|
|
482
|
-
".css": "text/css",
|
|
483
|
-
".json": "application/json",
|
|
484
|
-
".png": "image/png",
|
|
485
|
-
".jpg": "image/jpeg",
|
|
486
|
-
".gif": "image/gif",
|
|
487
|
-
".svg": "image/svg+xml",
|
|
488
|
-
".ico": "image/x-icon",
|
|
489
|
-
".txt": "text/plain"
|
|
490
|
-
};
|
|
491
|
-
constructor(pathPrefix, folderPath, cors) {
|
|
492
|
-
this._pathPrefix = "/" + pathPrefix.replace(/^\//, "").replace(/\/$/, "");
|
|
493
|
-
this._absoluteFolderPath = path2.resolve(folderPath);
|
|
494
|
-
this._cors = cors;
|
|
495
|
-
this._server = http2.createServer((req, res) => this._handleRequest(req, res));
|
|
496
|
-
}
|
|
497
|
-
port() {
|
|
498
|
-
const address = this._server.address();
|
|
499
|
-
if (!address)
|
|
500
|
-
return void 0;
|
|
501
|
-
return address.port;
|
|
502
|
-
}
|
|
503
|
-
address() {
|
|
504
|
-
const address = this._server.address();
|
|
505
|
-
if (!address)
|
|
506
|
-
return void 0;
|
|
507
|
-
const displayHost = address.address.includes(":") ? `[${address.address}]` : address.address;
|
|
508
|
-
return `http://${displayHost}:${address.port}${this._pathPrefix}`;
|
|
509
|
-
}
|
|
510
|
-
async _startServer(port, host) {
|
|
511
|
-
let okListener;
|
|
512
|
-
let errListener;
|
|
513
|
-
const result = new Promise((resolve2, reject) => {
|
|
514
|
-
okListener = resolve2;
|
|
515
|
-
errListener = reject;
|
|
516
|
-
}).finally(() => {
|
|
517
|
-
this._server.removeListener("listening", okListener);
|
|
518
|
-
this._server.removeListener("error", errListener);
|
|
519
|
-
});
|
|
520
|
-
this._server.once("listening", okListener);
|
|
521
|
-
this._server.once("error", errListener);
|
|
522
|
-
this._server.listen(port, host);
|
|
523
|
-
await result;
|
|
524
|
-
log2('Serving "%s" on "%s"', this._absoluteFolderPath, this.address());
|
|
525
|
-
}
|
|
526
|
-
async start(port, host = "127.0.0.1") {
|
|
527
|
-
if (port === 0) {
|
|
528
|
-
await this._startServer(port, host);
|
|
529
|
-
return this.address();
|
|
530
|
-
}
|
|
531
|
-
for (let i = 0; i < 20; ++i) {
|
|
532
|
-
const err = await this._startServer(port, host).then(() => void 0).catch((e) => e);
|
|
533
|
-
if (!err)
|
|
534
|
-
return this.address();
|
|
535
|
-
if (err.code !== "EADDRINUSE")
|
|
536
|
-
throw err;
|
|
537
|
-
log2("Port %d is busy (EADDRINUSE). Trying next port...", port);
|
|
538
|
-
port = port + 1;
|
|
539
|
-
if (port > 65535)
|
|
540
|
-
port = 4e3;
|
|
541
|
-
}
|
|
542
|
-
log2("All sequential ports busy. Falling back to random port.");
|
|
543
|
-
await this._startServer(0, host);
|
|
544
|
-
return this.address();
|
|
545
|
-
}
|
|
546
|
-
stop() {
|
|
547
|
-
return new Promise((resolve2, reject) => {
|
|
548
|
-
this._server.close((err) => {
|
|
549
|
-
if (err) {
|
|
550
|
-
log2("Error stopping server: %o", err);
|
|
551
|
-
reject(err);
|
|
552
|
-
} else {
|
|
553
|
-
log2("Server stopped.");
|
|
554
|
-
resolve2();
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
_errorResponse(req, res, code, text) {
|
|
560
|
-
res.writeHead(code, { "Content-Type": "text/plain" });
|
|
561
|
-
res.end(text);
|
|
562
|
-
log2(`[${code}] ${req.method} ${req.url}`);
|
|
563
|
-
}
|
|
564
|
-
_handleRequest(req, res) {
|
|
565
|
-
const { url, method } = req;
|
|
566
|
-
if (this._cors) {
|
|
567
|
-
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
568
|
-
res.setHeader("Access-Control-Allow-Origin", this._cors);
|
|
569
|
-
res.setHeader("Access-Control-Allow-Methods", "*");
|
|
570
|
-
if (req.method === "OPTIONS") {
|
|
571
|
-
res.writeHead(204);
|
|
572
|
-
res.end();
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
if (method !== "GET") {
|
|
577
|
-
this._errorResponse(req, res, 405, "Method Not Allowed");
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
req.on("aborted", () => log2(`ABORTED ${req.method} ${req.url}`));
|
|
581
|
-
res.on("close", () => {
|
|
582
|
-
if (!res.headersSent) log2(`CLOSED BEFORE SEND ${req.method} ${req.url}`);
|
|
583
|
-
});
|
|
584
|
-
if (!url || !url.startsWith(this._pathPrefix)) {
|
|
585
|
-
this._errorResponse(req, res, 404, "Not Found");
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
const relativePath = url.slice(this._pathPrefix.length);
|
|
589
|
-
const safeSuffix = path2.normalize(decodeURIComponent(relativePath)).replace(/^(\.\.[\/\\])+/, "");
|
|
590
|
-
const filePath = path2.join(this._absoluteFolderPath, safeSuffix);
|
|
591
|
-
if (!filePath.startsWith(this._absoluteFolderPath)) {
|
|
592
|
-
this._errorResponse(req, res, 403, "Forbidden");
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
fs2.stat(filePath, (err, stats) => {
|
|
596
|
-
if (err || !stats.isFile()) {
|
|
597
|
-
this._errorResponse(req, res, 404, "File Not Found");
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
const ext = path2.extname(filePath).toLowerCase();
|
|
601
|
-
const contentType = this._mimeTypes[ext] || "application/octet-stream";
|
|
602
|
-
res.writeHead(200, { "Content-Type": contentType });
|
|
603
|
-
log2(`[200] ${req.method} ${req.url} -> ${filePath}`);
|
|
604
|
-
const readStream = fs2.createReadStream(filePath);
|
|
605
|
-
readStream.pipe(res);
|
|
606
|
-
readStream.on("error", (err2) => {
|
|
607
|
-
log2("Stream error: %o", err2);
|
|
608
|
-
res.end();
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
// src/showReport.ts
|
|
3
|
+
import { randomUUIDBase62 } from "./_internalUtils.js";
|
|
4
|
+
import { FlakinessProjectConfig } from "./flakinessProjectConfig.js";
|
|
5
|
+
import { StaticServer } from "./staticServer.js";
|
|
615
6
|
async function showReport(reportFolder) {
|
|
616
7
|
const config = await FlakinessProjectConfig.load();
|
|
617
8
|
const projectPublicId = config.projectPublicId();
|
package/lib/staticServer.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// src/staticServer.ts
|
|
2
1
|
import debug from "debug";
|
|
3
2
|
import * as fs from "fs";
|
|
4
3
|
import * as http from "http";
|
|
5
4
|
import * as path from "path";
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const log = debug("fk:static_server");
|
|
6
|
+
class StaticServer {
|
|
8
7
|
_server;
|
|
9
8
|
_absoluteFolderPath;
|
|
10
9
|
_pathPrefix;
|
|
@@ -43,8 +42,8 @@ var StaticServer = class {
|
|
|
43
42
|
async _startServer(port, host) {
|
|
44
43
|
let okListener;
|
|
45
44
|
let errListener;
|
|
46
|
-
const result = new Promise((
|
|
47
|
-
okListener =
|
|
45
|
+
const result = new Promise((resolve, reject) => {
|
|
46
|
+
okListener = resolve;
|
|
48
47
|
errListener = reject;
|
|
49
48
|
}).finally(() => {
|
|
50
49
|
this._server.removeListener("listening", okListener);
|
|
@@ -77,14 +76,14 @@ var StaticServer = class {
|
|
|
77
76
|
return this.address();
|
|
78
77
|
}
|
|
79
78
|
stop() {
|
|
80
|
-
return new Promise((
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
81
80
|
this._server.close((err) => {
|
|
82
81
|
if (err) {
|
|
83
82
|
log("Error stopping server: %o", err);
|
|
84
83
|
reject(err);
|
|
85
84
|
} else {
|
|
86
85
|
log("Server stopped.");
|
|
87
|
-
|
|
86
|
+
resolve();
|
|
88
87
|
}
|
|
89
88
|
});
|
|
90
89
|
});
|
|
@@ -142,7 +141,7 @@ var StaticServer = class {
|
|
|
142
141
|
});
|
|
143
142
|
});
|
|
144
143
|
}
|
|
145
|
-
}
|
|
144
|
+
}
|
|
146
145
|
export {
|
|
147
146
|
StaticServer
|
|
148
147
|
};
|
package/lib/stripAnsi.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
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");
|
|
1
|
+
const 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");
|
|
3
2
|
function stripAnsi(str) {
|
|
4
3
|
return str.replace(ansiRegex, "");
|
|
5
4
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/systemUtilizationSampler.ts
|
|
2
1
|
import { spawnSync } from "child_process";
|
|
3
2
|
import os from "os";
|
|
4
3
|
function getAvailableMemMacOS() {
|
|
@@ -43,7 +42,7 @@ function toFKUtilization(sample, previous) {
|
|
|
43
42
|
dts: sample.timestamp - previous.timestamp
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
|
-
|
|
45
|
+
class SystemUtilizationSampler {
|
|
47
46
|
/**
|
|
48
47
|
* The accumulated system utilization data.
|
|
49
48
|
*
|
|
@@ -85,7 +84,7 @@ var SystemUtilizationSampler = class {
|
|
|
85
84
|
dispose() {
|
|
86
85
|
clearTimeout(this._timer);
|
|
87
86
|
}
|
|
88
|
-
}
|
|
87
|
+
}
|
|
89
88
|
export {
|
|
90
89
|
SystemUtilizationSampler
|
|
91
90
|
};
|