@dvl-software/eip-cypress 0.0.0-stage → 0.2.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/CHANGELOG.md +28 -0
- package/LICENSE +8 -0
- package/README.md +175 -2
- package/dist/chunk-YFM4D27K.js +237 -0
- package/dist/cli.js +729 -0
- package/dist/index.cjs +1028 -0
- package/dist/index.d.cts +73 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +775 -0
- package/dist/support.cjs +634 -0
- package/dist/support.d.cts +84 -0
- package/dist/support.d.ts +84 -0
- package/dist/support.js +375 -0
- package/package.json +69 -5
package/dist/index.js
ADDED
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Redaction,
|
|
3
|
+
__publicField
|
|
4
|
+
} from "./chunk-YFM4D27K.js";
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
import { randomUUID } from "crypto";
|
|
8
|
+
import { existsSync } from "fs";
|
|
9
|
+
import { readFile } from "fs/promises";
|
|
10
|
+
import { extname, isAbsolute as isAbsolute2, join } from "path";
|
|
11
|
+
import { gzipSync } from "zlib";
|
|
12
|
+
|
|
13
|
+
// src/api.ts
|
|
14
|
+
var StorageFullError = class extends Error {
|
|
15
|
+
constructor() {
|
|
16
|
+
super("EIP storage is full");
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var ApiError = class extends Error {
|
|
20
|
+
constructor(status, message) {
|
|
21
|
+
super(message);
|
|
22
|
+
__publicField(this, "status", status);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var UnreachableError = class extends Error {
|
|
26
|
+
constructor() {
|
|
27
|
+
super("EIP is not reachable (earlier calls timed out or failed), skipped");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var RETRIES = 3;
|
|
31
|
+
var UNREACHABLE_AFTER = 2;
|
|
32
|
+
var DEFAULT_TIMEOUTS = { jsonMs: 3e4, uploadBaseMs: 6e4, uploadPerMbMs: 2e3 };
|
|
33
|
+
var EipApi = class {
|
|
34
|
+
constructor(baseUrl, apiKey, fetchImpl = fetch, timeouts = DEFAULT_TIMEOUTS, backoffMs = 500) {
|
|
35
|
+
__publicField(this, "baseUrl", baseUrl);
|
|
36
|
+
__publicField(this, "apiKey", apiKey);
|
|
37
|
+
__publicField(this, "fetchImpl", fetchImpl);
|
|
38
|
+
__publicField(this, "timeouts", timeouts);
|
|
39
|
+
__publicField(this, "backoffMs", backoffMs);
|
|
40
|
+
__publicField(this, "networkFailures", 0);
|
|
41
|
+
}
|
|
42
|
+
openRun(body) {
|
|
43
|
+
return this.json("POST", "/api/v1/auto-test-results/runs", body);
|
|
44
|
+
}
|
|
45
|
+
requestUpload(runId, body) {
|
|
46
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/uploads`, body);
|
|
47
|
+
}
|
|
48
|
+
postSpec(runId, body) {
|
|
49
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/specs`, body);
|
|
50
|
+
}
|
|
51
|
+
finish(runId, endedAt) {
|
|
52
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/finish`, { ended_at: endedAt });
|
|
53
|
+
}
|
|
54
|
+
/** Parallel runs: the machine's next specs; with `specs` it sends the run's spec list. */
|
|
55
|
+
next(runId, body) {
|
|
56
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/next`, body);
|
|
57
|
+
}
|
|
58
|
+
finishMachine(runId, machineId) {
|
|
59
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/machines/${machineId}/finish`);
|
|
60
|
+
}
|
|
61
|
+
/** Calls EIP again after it was unreachable (the parallel CLI keeps trying for a while before it gives up). */
|
|
62
|
+
resetReachability() {
|
|
63
|
+
this.networkFailures = 0;
|
|
64
|
+
}
|
|
65
|
+
rerunList(runNumber, projectId) {
|
|
66
|
+
const query = new URLSearchParams({ run_number: String(runNumber) });
|
|
67
|
+
if (projectId) query.set("project_id", projectId);
|
|
68
|
+
return this.json("GET", `/api/v1/auto-test-results/runs/rerun-list?${query}`);
|
|
69
|
+
}
|
|
70
|
+
/** PUT the file to the presigned URL (no API key: the URL carries its own signature). */
|
|
71
|
+
async upload(slot, content) {
|
|
72
|
+
const timeout = this.timeouts.uploadBaseMs + Math.ceil(content.byteLength / 1048576) * this.timeouts.uploadPerMbMs;
|
|
73
|
+
const res = await this.withRetry(
|
|
74
|
+
timeout,
|
|
75
|
+
(signal) => this.fetchImpl(slot.url, { method: slot.method || "PUT", headers: slot.headers, body: content, signal })
|
|
76
|
+
);
|
|
77
|
+
if (!res.ok) {
|
|
78
|
+
await discard(res);
|
|
79
|
+
throw new ApiError(res.status, `Upload failed with ${res.status}`);
|
|
80
|
+
}
|
|
81
|
+
await discard(res);
|
|
82
|
+
}
|
|
83
|
+
async json(method, path, body) {
|
|
84
|
+
const res = await this.withRetry(
|
|
85
|
+
this.timeouts.jsonMs,
|
|
86
|
+
(signal) => this.fetchImpl(this.baseUrl + path, {
|
|
87
|
+
method,
|
|
88
|
+
headers: { "X-API-Key": this.apiKey, "Content-Type": "application/json", Accept: "application/json" },
|
|
89
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
90
|
+
signal
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
if (res.status === 409) {
|
|
94
|
+
const text = await res.text().catch(() => "");
|
|
95
|
+
if (text.includes("STORAGE_FULL")) throw new StorageFullError();
|
|
96
|
+
throw new ApiError(res.status, messageOf(text) ?? "Conflict");
|
|
97
|
+
}
|
|
98
|
+
if (!res.ok) {
|
|
99
|
+
const text = await res.text().catch(() => "");
|
|
100
|
+
throw new ApiError(res.status, messageOf(text) ?? `EIP answered ${res.status}`);
|
|
101
|
+
}
|
|
102
|
+
return await res.json();
|
|
103
|
+
}
|
|
104
|
+
async withRetry(timeoutMs, call) {
|
|
105
|
+
if (this.networkFailures >= UNREACHABLE_AFTER) throw new UnreachableError();
|
|
106
|
+
let lastError;
|
|
107
|
+
for (let attempt = 0; attempt < RETRIES; attempt++) {
|
|
108
|
+
try {
|
|
109
|
+
const res = await call(AbortSignal.timeout(timeoutMs));
|
|
110
|
+
if (res.status < 500 || attempt === RETRIES - 1) {
|
|
111
|
+
this.networkFailures = 0;
|
|
112
|
+
return res;
|
|
113
|
+
}
|
|
114
|
+
await discard(res);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
lastError = isTimeout(e) ? new Error(`no answer within ${Math.round(timeoutMs / 1e3)} s`) : e;
|
|
117
|
+
}
|
|
118
|
+
if (attempt < RETRIES - 1) await new Promise((r) => setTimeout(r, this.backoffMs * 2 ** attempt));
|
|
119
|
+
}
|
|
120
|
+
this.networkFailures++;
|
|
121
|
+
throw lastError;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
async function discard(res) {
|
|
125
|
+
try {
|
|
126
|
+
await res.body?.cancel();
|
|
127
|
+
} catch {
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function isTimeout(e) {
|
|
131
|
+
return e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError");
|
|
132
|
+
}
|
|
133
|
+
function messageOf(text) {
|
|
134
|
+
try {
|
|
135
|
+
const parsed = JSON.parse(text);
|
|
136
|
+
return typeof parsed?.message === "string" ? parsed.message : void 0;
|
|
137
|
+
} catch {
|
|
138
|
+
return void 0;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/collect.ts
|
|
143
|
+
function inScope(scope, state, flaky) {
|
|
144
|
+
switch (scope) {
|
|
145
|
+
case "ALL":
|
|
146
|
+
return true;
|
|
147
|
+
case "FAILED":
|
|
148
|
+
return state === "failed";
|
|
149
|
+
case "FAILED_FLAKY":
|
|
150
|
+
return state === "failed" || flaky;
|
|
151
|
+
default:
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function isFlaky(test) {
|
|
156
|
+
return test.state === "passed" && (test.attempts ?? []).some((a) => a.state === "failed");
|
|
157
|
+
}
|
|
158
|
+
function posixPath(path) {
|
|
159
|
+
return path.replace(/\\/g, "/");
|
|
160
|
+
}
|
|
161
|
+
var STEP_MESSAGE_LIMIT = 300;
|
|
162
|
+
var key = (titlePath, retry) => `${titlePath.join("")}#${retry}`;
|
|
163
|
+
function planSpec(specPath, results, browser, settings) {
|
|
164
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
165
|
+
for (const a of browser?.attempts ?? []) byKey.set(key(a.titlePath, a.retry), a);
|
|
166
|
+
const specStart = results.stats.startedAt ? Date.parse(results.stats.startedAt) : void 0;
|
|
167
|
+
const tests = (results.tests ?? []).map((test) => {
|
|
168
|
+
const flaky = isFlaky(test);
|
|
169
|
+
const keepLog = inScope(settings.network_scope, test.state, flaky);
|
|
170
|
+
const attemptStates = test.attempts && test.attempts.length > 0 ? test.attempts : [{ state: test.state }];
|
|
171
|
+
const attempts = attemptStates.map((cyAttempt, retry) => {
|
|
172
|
+
const recorded = byKey.get(key(test.title, retry));
|
|
173
|
+
const started = recorded?.wallClockStartedAt ? Date.parse(recorded.wallClockStartedAt) : void 0;
|
|
174
|
+
const isLast = retry === attemptStates.length - 1;
|
|
175
|
+
const error = recorded?.error ?? (isLast && test.displayError ? splitError(test.displayError) : void 0) ?? (cyAttempt.state === "failed" && results.error ? specError(results.error) : void 0);
|
|
176
|
+
const pass = new Redaction(settings.extra_redact_fields, settings.extra_redact_patterns);
|
|
177
|
+
const planned = {
|
|
178
|
+
state: cyAttempt.state,
|
|
179
|
+
started_at: recorded?.wallClockStartedAt,
|
|
180
|
+
duration_ms: recorded?.durationMs,
|
|
181
|
+
video_offset_ms: specStart !== void 0 && started !== void 0 ? Math.max(0, started - specStart) : void 0,
|
|
182
|
+
timings: recorded?.timings,
|
|
183
|
+
error: error ? cleanError(error, pass) : void 0,
|
|
184
|
+
steps: recorded?.steps?.map((step) => step.message ? { ...step, message: pass.text(step.message).slice(0, STEP_MESSAGE_LIMIT) } : step),
|
|
185
|
+
screenshotPaths: []
|
|
186
|
+
};
|
|
187
|
+
let redacted = pass.count;
|
|
188
|
+
if (recorded && keepLog && (recorded.requests.length > 0 || recorded.console.length > 0)) {
|
|
189
|
+
const log = buildNetworkLog(recorded, settings);
|
|
190
|
+
planned.networkLog = log;
|
|
191
|
+
planned.network_entry_count = log.requests.length;
|
|
192
|
+
planned.console_entry_count = log.console.length;
|
|
193
|
+
redacted += log.redacted;
|
|
194
|
+
}
|
|
195
|
+
if (redacted > 0) planned.redacted_count = redacted;
|
|
196
|
+
return planned;
|
|
197
|
+
});
|
|
198
|
+
return {
|
|
199
|
+
title_path: test.title,
|
|
200
|
+
state: test.state,
|
|
201
|
+
duration_ms: test.duration ?? void 0,
|
|
202
|
+
attempts
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
attachScreenshots(tests, results, settings);
|
|
206
|
+
const keepVideo = results.video && (results.tests ?? []).some((t) => inScope(settings.video_scope, t.state, isFlaky(t)));
|
|
207
|
+
return {
|
|
208
|
+
spec: posixPath(specPath),
|
|
209
|
+
started_at: results.stats.startedAt,
|
|
210
|
+
ended_at: results.stats.endedAt,
|
|
211
|
+
duration_ms: results.stats.duration,
|
|
212
|
+
videoPath: keepVideo ? results.video ?? void 0 : void 0,
|
|
213
|
+
tests
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function cleanError(error, pass) {
|
|
217
|
+
return {
|
|
218
|
+
name: error.name,
|
|
219
|
+
message: error.message ? pass.text(error.message) : error.message,
|
|
220
|
+
stack: error.stack ? pass.text(error.stack) : error.stack
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function splitError(display) {
|
|
224
|
+
const firstLine = display.split("\n", 1)[0] ?? "";
|
|
225
|
+
const match = /^([A-Za-z]*Error):\s*(.*)$/.exec(firstLine);
|
|
226
|
+
return match ? { name: match[1], message: match[2], stack: display } : { message: firstLine, stack: display };
|
|
227
|
+
}
|
|
228
|
+
var ANSI = /\u001b\[[0-9;]*m/g;
|
|
229
|
+
function specError(text) {
|
|
230
|
+
const plain = text.replace(ANSI, "").trim();
|
|
231
|
+
const message = plain.split(/\n\s*\n/, 1)[0]?.replace(/\s*\n\s*/g, " ") ?? plain;
|
|
232
|
+
return { message, stack: plain };
|
|
233
|
+
}
|
|
234
|
+
function attachScreenshots(tests, results, settings) {
|
|
235
|
+
for (const shot of results.screenshots ?? []) {
|
|
236
|
+
const taken = shot.takenAt ? Date.parse(shot.takenAt) : void 0;
|
|
237
|
+
let target;
|
|
238
|
+
if (taken !== void 0) {
|
|
239
|
+
for (const test of tests) {
|
|
240
|
+
for (const attempt of test.attempts) {
|
|
241
|
+
if (!attempt.started_at) continue;
|
|
242
|
+
const start = Date.parse(attempt.started_at);
|
|
243
|
+
const end = start + (attempt.duration_ms ?? 0) + 5e3;
|
|
244
|
+
if (taken >= start && taken <= end) target = { test, attempt };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (!target) {
|
|
249
|
+
const file = shot.path.split(/[\\/]/).pop() ?? "";
|
|
250
|
+
const attemptNo = Number(/\(attempt (\d+)\)/.exec(file)?.[1] ?? "1");
|
|
251
|
+
const test = tests.find((t) => file.includes(t.title_path[t.title_path.length - 1] ?? "\0"));
|
|
252
|
+
const attempt = test?.attempts[Math.min(attemptNo, test.attempts.length) - 1];
|
|
253
|
+
if (test && attempt) target = { test, attempt };
|
|
254
|
+
}
|
|
255
|
+
if (target && inScope(settings.screenshot_scope, target.test.state, target.test.attempts.some((a) => a.state === "failed"))) {
|
|
256
|
+
target.attempt.screenshotPaths.push(shot.path);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function buildNetworkLog(attempt, settings) {
|
|
261
|
+
const pass = new Redaction(settings.extra_redact_fields, settings.extra_redact_patterns);
|
|
262
|
+
const limit = Math.max(1, settings.body_limit_kb) * 1024;
|
|
263
|
+
const requests = attempt.requests.map((r) => ({
|
|
264
|
+
...r,
|
|
265
|
+
url: pass.url(r.url),
|
|
266
|
+
request: cleanMessage(r.request, pass, settings.capture_bodies, limit),
|
|
267
|
+
response: cleanMessage(r.response, pass, settings.capture_bodies, limit)
|
|
268
|
+
}));
|
|
269
|
+
const console2 = attempt.console.map((c) => ({ ...c, message: pass.text(c.message).slice(0, 4e3) }));
|
|
270
|
+
return { version: 1, redacted: pass.count, requests, console: console2 };
|
|
271
|
+
}
|
|
272
|
+
function cleanMessage(message, pass, bodies, limit) {
|
|
273
|
+
const out = { ...message, headers: pass.headers(message.headers ?? {}) };
|
|
274
|
+
if (!bodies) {
|
|
275
|
+
if (out.body !== void 0) out.body_omitted = "off";
|
|
276
|
+
delete out.body;
|
|
277
|
+
return out;
|
|
278
|
+
}
|
|
279
|
+
if (out.body === void 0 || out.body === null || out.body_omitted) return out;
|
|
280
|
+
const cleaned = pass.body(out.body);
|
|
281
|
+
const text = typeof cleaned === "string" ? cleaned : JSON.stringify(cleaned);
|
|
282
|
+
if (text !== void 0 && text.length > limit) {
|
|
283
|
+
out.body = text.slice(0, limit);
|
|
284
|
+
out.body_truncated = true;
|
|
285
|
+
} else {
|
|
286
|
+
out.body = cleaned;
|
|
287
|
+
}
|
|
288
|
+
return out;
|
|
289
|
+
}
|
|
290
|
+
var STACK_LIMIT = 4e3;
|
|
291
|
+
var STEPS_LIMIT = 100;
|
|
292
|
+
function fitPayload(tests, maxBytes, size) {
|
|
293
|
+
const shrinks = [
|
|
294
|
+
() => forEachAttempt(tests, (a) => {
|
|
295
|
+
if (a.state === "passed") delete a.steps;
|
|
296
|
+
}),
|
|
297
|
+
() => forEachAttempt(tests, (a) => {
|
|
298
|
+
if (a.error?.stack && a.error.stack.length > STACK_LIMIT) a.error = { ...a.error, stack: a.error.stack.slice(0, STACK_LIMIT) };
|
|
299
|
+
}),
|
|
300
|
+
() => forEachAttempt(tests, (a) => {
|
|
301
|
+
if (a.steps && a.steps.length > STEPS_LIMIT) a.steps = a.steps.slice(0, STEPS_LIMIT);
|
|
302
|
+
}),
|
|
303
|
+
() => forEachAttempt(tests, (a) => {
|
|
304
|
+
delete a.steps;
|
|
305
|
+
}),
|
|
306
|
+
() => forEachAttempt(tests, (a) => {
|
|
307
|
+
if (a.error) a.error = { name: a.error.name, message: a.error.message?.slice(0, STACK_LIMIT) };
|
|
308
|
+
})
|
|
309
|
+
];
|
|
310
|
+
for (const shrink of shrinks) {
|
|
311
|
+
if (size() <= maxBytes) return true;
|
|
312
|
+
shrink();
|
|
313
|
+
}
|
|
314
|
+
return size() <= maxBytes;
|
|
315
|
+
}
|
|
316
|
+
function forEachAttempt(tests, fn) {
|
|
317
|
+
for (const t of tests) for (const a of t.attempts) fn(a);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/context.ts
|
|
321
|
+
import { execFileSync } from "child_process";
|
|
322
|
+
var TRUE = ["1", "true", "yes"];
|
|
323
|
+
function buildIdFrom(env) {
|
|
324
|
+
const own = env.EIP_CI_BUILD_ID?.trim();
|
|
325
|
+
if (own) return own;
|
|
326
|
+
if (env.GITHUB_ACTIONS === "true" && env.GITHUB_RUN_ID) return `github-${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT || "1"}`;
|
|
327
|
+
return void 0;
|
|
328
|
+
}
|
|
329
|
+
function positiveInt(value, max) {
|
|
330
|
+
const n = Number(value?.trim());
|
|
331
|
+
return Number.isInteger(n) && n >= 1 ? Math.min(n, max) : void 0;
|
|
332
|
+
}
|
|
333
|
+
function readOptions(env = process.env) {
|
|
334
|
+
const rerun = env.EIP_RERUN_OF?.trim().replace(/^#/, "");
|
|
335
|
+
return {
|
|
336
|
+
buildId: buildIdFrom(env)?.slice(0, 200),
|
|
337
|
+
group: env.EIP_GROUP?.trim().slice(0, 100) || void 0,
|
|
338
|
+
totalMachines: positiveInt(env.EIP_PARALLEL_TOTAL, 1e3),
|
|
339
|
+
batch: positiveInt(env.EIP_PARALLEL_BATCH, 100) ?? 1,
|
|
340
|
+
machineId: env.EIP_MACHINE_ID?.trim() || void 0,
|
|
341
|
+
parallelSeed: TRUE.includes((env.EIP_PARALLEL_SEED ?? "").toLowerCase()),
|
|
342
|
+
parallelStateFile: env.EIP_PARALLEL_STATE?.trim() || void 0,
|
|
343
|
+
parallelSpec: env.EIP_PARALLEL_SPEC?.trim() || void 0,
|
|
344
|
+
apiKey: env.EIP_API_KEY?.trim() || void 0,
|
|
345
|
+
apiUrl: env.EIP_API_URL?.trim().replace(/\/+$/, "") || void 0,
|
|
346
|
+
projectId: env.EIP_PROJECT_ID?.trim() || void 0,
|
|
347
|
+
rerunOf: rerun && /^\d+$/.test(rerun) ? Number(rerun) : void 0,
|
|
348
|
+
environment: env.EIP_ENVIRONMENT?.trim() || void 0,
|
|
349
|
+
runName: env.EIP_RUN_NAME?.trim() || void 0,
|
|
350
|
+
captureExclude: env.EIP_CAPTURE_EXCLUDE?.trim() || void 0,
|
|
351
|
+
allowHttp: TRUE.includes((env.EIP_ALLOW_HTTP ?? "").toLowerCase()),
|
|
352
|
+
disabled: TRUE.includes((env.EIP_DISABLED ?? "").toLowerCase())
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function insecureApiUrl(apiUrl) {
|
|
356
|
+
try {
|
|
357
|
+
const u = new URL(apiUrl);
|
|
358
|
+
if (u.protocol === "https:") return false;
|
|
359
|
+
return !["localhost", "127.0.0.1", "[::1]", "::1"].includes(u.hostname);
|
|
360
|
+
} catch {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function ciContext(env = process.env) {
|
|
365
|
+
if (env.GITHUB_ACTIONS !== "true") return void 0;
|
|
366
|
+
const attempt = Number(env.GITHUB_RUN_ATTEMPT);
|
|
367
|
+
return {
|
|
368
|
+
provider: "github",
|
|
369
|
+
run_id: env.GITHUB_RUN_ID,
|
|
370
|
+
run_attempt: Number.isFinite(attempt) && attempt > 0 ? attempt : void 0,
|
|
371
|
+
workflow_ref: env.GITHUB_WORKFLOW_REF,
|
|
372
|
+
repository: env.GITHUB_REPOSITORY,
|
|
373
|
+
server_url: env.GITHUB_SERVER_URL
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function gitContext(env = process.env, git = runGit) {
|
|
377
|
+
const branch = env.GITHUB_HEAD_REF || env.GITHUB_REF_NAME || git(["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
378
|
+
const sha = env.GITHUB_SHA || git(["rev-parse", "HEAD"]);
|
|
379
|
+
const message = git(["log", "-1", "--pretty=%s"]);
|
|
380
|
+
const author = git(["log", "-1", "--pretty=%an"]);
|
|
381
|
+
return {
|
|
382
|
+
branch: branch && branch !== "HEAD" ? branch : void 0,
|
|
383
|
+
sha: sha || void 0,
|
|
384
|
+
message: message ? new Redaction().text(message) : void 0,
|
|
385
|
+
author: author || void 0
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function runGit(args) {
|
|
389
|
+
try {
|
|
390
|
+
return execFileSync("git", args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 3e3 }).trim();
|
|
391
|
+
} catch {
|
|
392
|
+
return void 0;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/parallel.ts
|
|
397
|
+
import { realpathSync, writeFileSync } from "fs";
|
|
398
|
+
import { hostname } from "os";
|
|
399
|
+
import { isAbsolute, relative, resolve } from "path";
|
|
400
|
+
import { glob } from "tinyglobby";
|
|
401
|
+
var ALWAYS_IGNORED = ["**/node_modules/**"];
|
|
402
|
+
var UNSAFE_SPEC = /(^|\/)\.\.(\/|$)|^\/|^[A-Za-z]:|["%^&|<>,\p{Cc}]/u;
|
|
403
|
+
function isShareableSpec(path) {
|
|
404
|
+
return path.length > 0 && !UNSAFE_SPEC.test(posixPath(path));
|
|
405
|
+
}
|
|
406
|
+
function list(value) {
|
|
407
|
+
if (Array.isArray(value)) return value.filter((v) => typeof v === "string" && v.length > 0);
|
|
408
|
+
return typeof value === "string" && value.length > 0 ? [value] : [];
|
|
409
|
+
}
|
|
410
|
+
function real(path) {
|
|
411
|
+
try {
|
|
412
|
+
return realpathSync(path);
|
|
413
|
+
} catch {
|
|
414
|
+
return path;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async function findSpecs(config, userSpec, cwd = process.cwd()) {
|
|
418
|
+
const root = real(config.projectRoot ?? cwd);
|
|
419
|
+
const ignore = [...list(config.excludeSpecPattern), ...ALWAYS_IGNORED];
|
|
420
|
+
const found = userSpec ? (await glob(userSpec.split(",").map((s) => s.trim()).filter(Boolean), { cwd: real(cwd), ignore, absolute: true })).map((p) => relative(root, real(p))) : await glob(list(config.specPattern).map((p) => isAbsolute(p) ? posixPath(relative(root, real(p))) : p), { cwd: root, ignore });
|
|
421
|
+
return [...new Set(found.map(posixPath))].filter((p) => !p.startsWith("../") && !isAbsolute(p)).sort();
|
|
422
|
+
}
|
|
423
|
+
function literal(root, spec) {
|
|
424
|
+
return escapeGlob(posixPath(resolve(root, spec)));
|
|
425
|
+
}
|
|
426
|
+
function specPatternFor(root, specs) {
|
|
427
|
+
const safe = specs.filter(isShareableSpec);
|
|
428
|
+
return safe.length ? safe.map((s) => literal(root, s)) : [posixPath(resolve(root, "__eip_no_spec__"))];
|
|
429
|
+
}
|
|
430
|
+
function escapeGlob(path) {
|
|
431
|
+
return path.replace(/[*?[\]{}()!+@]/g, "\\$&");
|
|
432
|
+
}
|
|
433
|
+
var CI_MARKERS = ["CI", "GITHUB_ACTIONS", "GITLAB_CI", "BUILDKITE", "JENKINS_URL", "TF_BUILD", "CIRCLECI", "TEAMCITY_VERSION"];
|
|
434
|
+
function shareableHostName(env = process.env) {
|
|
435
|
+
const ci = CI_MARKERS.some((name) => {
|
|
436
|
+
const value = env[name]?.trim().toLowerCase();
|
|
437
|
+
return !!value && value !== "false" && value !== "0";
|
|
438
|
+
});
|
|
439
|
+
return ci ? hostname().slice(0, 255) : void 0;
|
|
440
|
+
}
|
|
441
|
+
function parallelBlock(opts, env = process.env) {
|
|
442
|
+
return {
|
|
443
|
+
build_id: opts.buildId,
|
|
444
|
+
group: opts.group,
|
|
445
|
+
machine_id: opts.machineId,
|
|
446
|
+
host_name: shareableHostName(env),
|
|
447
|
+
total_machines: opts.totalMachines
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function isParallel(opts) {
|
|
451
|
+
return !!opts.machineId && !!opts.buildId;
|
|
452
|
+
}
|
|
453
|
+
async function seedSpecs(api, runId, opts, config) {
|
|
454
|
+
const found = await findSpecs(config, opts.parallelSpec);
|
|
455
|
+
const specs = found.filter(isShareableSpec);
|
|
456
|
+
const left = found.filter((s) => !isShareableSpec(s));
|
|
457
|
+
if (left.length) {
|
|
458
|
+
console.log(`[EIP] ${left.length} spec file(s) can't be shared between machines because of a character in the path (" % ^ & | < > ,), and don't run with --parallel: ${left.slice(0, 5).join(", ")}${left.length > 5 ? ", \u2026" : ""}`);
|
|
459
|
+
}
|
|
460
|
+
const answer = await api.next(runId, { machine_id: opts.machineId, batch: opts.batch, specs });
|
|
461
|
+
const batch = answer.action === "run" ? answer.specs : [];
|
|
462
|
+
config.specPattern = specPatternFor(config.projectRoot ?? process.cwd(), batch);
|
|
463
|
+
writeState(opts, { specs: batch.filter(isShareableSpec) });
|
|
464
|
+
return batch;
|
|
465
|
+
}
|
|
466
|
+
function writeState(opts, state) {
|
|
467
|
+
if (!opts.parallelStateFile) return;
|
|
468
|
+
try {
|
|
469
|
+
writeFileSync(opts.parallelStateFile, JSON.stringify(state));
|
|
470
|
+
} catch {
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// src/index.ts
|
|
475
|
+
var LOG_PREFIX = "[EIP]";
|
|
476
|
+
var MAX_SPEC_BODY_BYTES = 7 * 1024 * 1024;
|
|
477
|
+
var DEFAULT_SETTINGS = {
|
|
478
|
+
video_scope: "FAILED_FLAKY",
|
|
479
|
+
screenshot_scope: "FAILED",
|
|
480
|
+
network_scope: "FAILED_FLAKY",
|
|
481
|
+
capture_bodies: true,
|
|
482
|
+
body_limit_kb: 64,
|
|
483
|
+
extra_redact_fields: [],
|
|
484
|
+
extra_redact_patterns: []
|
|
485
|
+
};
|
|
486
|
+
async function setupEip(on, config, options = {}) {
|
|
487
|
+
const opts = { ...readOptions(), ...stripUndefined(options) };
|
|
488
|
+
const hooks = options.hooks ?? {};
|
|
489
|
+
const state = {
|
|
490
|
+
settings: DEFAULT_SETTINGS,
|
|
491
|
+
storageFull: false,
|
|
492
|
+
specEvents: [],
|
|
493
|
+
warned: /* @__PURE__ */ new Set(),
|
|
494
|
+
rerunExpected: 0,
|
|
495
|
+
rerunFound: 0
|
|
496
|
+
};
|
|
497
|
+
on("task", {
|
|
498
|
+
"eip:events": (data) => {
|
|
499
|
+
try {
|
|
500
|
+
if (data && Array.isArray(data.attempts)) state.specEvents.push(...data.attempts);
|
|
501
|
+
} catch {
|
|
502
|
+
}
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
let enabled = !opts.disabled && !!opts.apiKey && !!opts.apiUrl;
|
|
507
|
+
if (!enabled && !opts.disabled) {
|
|
508
|
+
console.log(`${LOG_PREFIX} EIP_API_KEY or EIP_API_URL is not set \u2014 results are not sent to EIP.`);
|
|
509
|
+
}
|
|
510
|
+
if (enabled && insecureApiUrl(opts.apiUrl) && !opts.allowHttp) {
|
|
511
|
+
console.log(`${LOG_PREFIX} EIP_API_URL must use https (or set EIP_ALLOW_HTTP=1) \u2014 results are not sent to EIP.`);
|
|
512
|
+
enabled = false;
|
|
513
|
+
}
|
|
514
|
+
if (!enabled || !config.isTextTerminal) {
|
|
515
|
+
registerUserHooksOnly(on, hooks);
|
|
516
|
+
return config;
|
|
517
|
+
}
|
|
518
|
+
const api = new EipApi(opts.apiUrl, opts.apiKey);
|
|
519
|
+
const clientRunId = randomUUID();
|
|
520
|
+
setExposed(config, "EIP_PLUGIN", "1");
|
|
521
|
+
if (opts.captureExclude) setExposed(config, "EIP_CAPTURE_EXCLUDE", opts.captureExclude);
|
|
522
|
+
if (opts.rerunOf !== void 0) {
|
|
523
|
+
await applyRerun(api, opts, config, state);
|
|
524
|
+
}
|
|
525
|
+
const parallel = isParallel(opts);
|
|
526
|
+
const openBody = (details) => ({
|
|
527
|
+
client_run_id: clientRunId,
|
|
528
|
+
project_id: opts.projectId,
|
|
529
|
+
name: opts.runName,
|
|
530
|
+
framework: "cypress",
|
|
531
|
+
tool_version: details?.cypressVersion,
|
|
532
|
+
browser: details?.browser ? `${details.browser.displayName ?? details.browser.name} ${details.browser.majorVersion ?? ""}`.trim() : void 0,
|
|
533
|
+
os_name: details?.system ? `${details.system.osName} ${details.system.osVersion}` : void 0,
|
|
534
|
+
spec_count: parallel ? void 0 : details?.specs?.length,
|
|
535
|
+
started_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
536
|
+
environment: opts.environment,
|
|
537
|
+
rerun_of: opts.rerunOf,
|
|
538
|
+
ci: ciContext(),
|
|
539
|
+
git: gitContext(),
|
|
540
|
+
parallel: parallel ? parallelBlock(opts) : void 0
|
|
541
|
+
});
|
|
542
|
+
const applyOpened = (opened) => {
|
|
543
|
+
state.runId = opened.run_id;
|
|
544
|
+
state.runNumber = opened.run_number;
|
|
545
|
+
state.settings = { ...DEFAULT_SETTINGS, ...withoutNulls(opened.settings) };
|
|
546
|
+
state.storageFull = opened.storage_full;
|
|
547
|
+
};
|
|
548
|
+
if (parallel && opts.parallelSeed) {
|
|
549
|
+
try {
|
|
550
|
+
applyOpened(await api.openRun(openBody()));
|
|
551
|
+
const batch = await seedSpecs(api, state.runId, opts, config);
|
|
552
|
+
console.log(`${LOG_PREFIX} Run #${state.runNumber}: spec list sent; this machine starts with ${batch.length} spec(s).`);
|
|
553
|
+
} catch (e) {
|
|
554
|
+
writeState(opts, { specs: [], error: errorText(e) });
|
|
555
|
+
config.specPattern = [];
|
|
556
|
+
console.log(`${LOG_PREFIX} Could not send the spec list to EIP: ${errorText(e)}.`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
on("before:run", async (details) => {
|
|
560
|
+
await hooks.beforeRun?.(details);
|
|
561
|
+
try {
|
|
562
|
+
applyOpened(await api.openRun(openBody(details)));
|
|
563
|
+
if (!parallel) {
|
|
564
|
+
console.log(`${LOG_PREFIX} Run #${state.runNumber} opened${opts.rerunOf ? ` (re-run of #${opts.rerunOf})` : ""}.`);
|
|
565
|
+
}
|
|
566
|
+
if (state.storageFull) {
|
|
567
|
+
console.log(`${LOG_PREFIX} Storage is full: results are sent, videos, screenshots and request logs are not.`);
|
|
568
|
+
}
|
|
569
|
+
} catch (e) {
|
|
570
|
+
warn(state, "open", `Could not open a run in EIP: ${errorText(e)}. This run is not recorded.`);
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
on("after:spec", async (spec, results) => {
|
|
574
|
+
const events = state.specEvents;
|
|
575
|
+
state.specEvents = [];
|
|
576
|
+
await hooks.afterSpec?.(spec, results);
|
|
577
|
+
try {
|
|
578
|
+
checkRerunMatches(state, spec.relative, results);
|
|
579
|
+
if (!state.runId) return;
|
|
580
|
+
const plan = planSpec(spec.relative, results, { attempts: events }, state.settings);
|
|
581
|
+
await postSpec(api, state, plan, parallel ? opts.machineId : void 0);
|
|
582
|
+
} catch (e) {
|
|
583
|
+
warn(state, `spec:${spec.relative}`, `Could not send ${spec.relative}: ${errorText(e)}`);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
on("after:run", async (results) => {
|
|
587
|
+
try {
|
|
588
|
+
reportRerunMatches(state);
|
|
589
|
+
if (!parallel) await finishRun(api, state);
|
|
590
|
+
} catch (e) {
|
|
591
|
+
warn(state, "finish", `Could not finish the run in EIP: ${errorText(e)}`);
|
|
592
|
+
} finally {
|
|
593
|
+
await hooks.afterRun?.(results);
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
return config;
|
|
597
|
+
}
|
|
598
|
+
async function finishRun(api, state) {
|
|
599
|
+
if (!state.runId) return;
|
|
600
|
+
try {
|
|
601
|
+
const totals = await api.finish(state.runId, (/* @__PURE__ */ new Date()).toISOString());
|
|
602
|
+
const duration = totals.duration_ms !== void 0 ? ` in ${hhmmss(totals.duration_ms)}` : "";
|
|
603
|
+
const skipped = totals.skipped + totals.pending;
|
|
604
|
+
console.log(`${LOG_PREFIX} Run #${totals.run_number}: ${totals.passed} passed, ${totals.failed} failed, ${skipped} skipped${totals.flaky ? `, ${totals.flaky} flaky` : ""}${duration}. ${appLink(totals.run_path)}`);
|
|
605
|
+
} catch (e) {
|
|
606
|
+
warn(state, "finish", `Could not finish the run in EIP: ${errorText(e)}`);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function registerUserHooksOnly(on, hooks) {
|
|
610
|
+
const register = on;
|
|
611
|
+
if (hooks.beforeRun) register("before:run", hooks.beforeRun);
|
|
612
|
+
if (hooks.afterSpec) register("after:spec", hooks.afterSpec);
|
|
613
|
+
if (hooks.afterRun) register("after:run", hooks.afterRun);
|
|
614
|
+
}
|
|
615
|
+
async function applyRerun(api, opts, config, state) {
|
|
616
|
+
try {
|
|
617
|
+
const list2 = await api.rerunList(opts.rerunOf, opts.projectId);
|
|
618
|
+
if (list2.specs.length === 0) {
|
|
619
|
+
console.log(`${LOG_PREFIX} Run #${opts.rerunOf} has no failed or skipped tests \u2014 running everything.`);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const root = config.projectRoot ?? process.cwd();
|
|
623
|
+
const specs = list2.specs.map((s) => ({ ...s, spec: posixPath(s.spec) })).filter((s) => !isAbsolute2(s.spec) && existsSync(join(root, s.spec)));
|
|
624
|
+
const gone = list2.specs.length - specs.length;
|
|
625
|
+
if (specs.length === 0) {
|
|
626
|
+
console.log(`${LOG_PREFIX} None of the ${list2.specs.length} spec file(s) of run #${opts.rerunOf} exists any more \u2014 running everything.`);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
config.specPattern = specs.map((s) => escapeGlob(s.spec));
|
|
630
|
+
setExposed(config, "EIP_RERUN_TITLES", JSON.stringify(specs.flatMap((s) => s.title_paths)));
|
|
631
|
+
state.rerunTitles = new Map(specs.map((s) => [s.spec, new Set(s.title_paths.map(titleKey))]));
|
|
632
|
+
state.rerunExpected = specs.reduce((n, s) => n + s.title_paths.length, 0);
|
|
633
|
+
console.log(`${LOG_PREFIX} Re-running ${state.rerunExpected} failed / skipped test(s) of run #${opts.rerunOf} in ${specs.length} spec(s)${gone ? ` (${gone} spec file(s) no longer exist)` : ""}.`);
|
|
634
|
+
} catch (e) {
|
|
635
|
+
console.log(`${LOG_PREFIX} Could not load run #${opts.rerunOf} to re-run: ${errorText(e)}. Running everything.`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
var titleKey = (path) => path.join("");
|
|
639
|
+
function checkRerunMatches(state, specRelative, results) {
|
|
640
|
+
const expected = state.rerunTitles?.get(posixPath(specRelative));
|
|
641
|
+
if (!expected) return;
|
|
642
|
+
const found = (results.tests ?? []).filter((t) => expected.has(titleKey(t.title))).length;
|
|
643
|
+
state.rerunFound += found;
|
|
644
|
+
if (found < expected.size) {
|
|
645
|
+
console.log(`${LOG_PREFIX} Re-run: ${expected.size - found} of ${expected.size} test(s) of ${posixPath(specRelative)} were not found (renamed, removed or a title that changes between runs) and did not run.`);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function reportRerunMatches(state) {
|
|
649
|
+
if (!state.rerunTitles || state.rerunFound >= state.rerunExpected) return;
|
|
650
|
+
console.log(`${LOG_PREFIX} Re-run: only ${state.rerunFound} of ${state.rerunExpected} test(s) were found and run.`);
|
|
651
|
+
}
|
|
652
|
+
function setExposed(config, name, value) {
|
|
653
|
+
const cfg = config;
|
|
654
|
+
cfg.expose = { ...cfg.expose ?? {}, [name]: value };
|
|
655
|
+
const major = Number(String(cfg.version ?? "").split(".")[0]);
|
|
656
|
+
if (!(major >= 15)) cfg.env = { ...cfg.env ?? {}, [name]: value };
|
|
657
|
+
}
|
|
658
|
+
async function postSpec(api, state, plan, machineId) {
|
|
659
|
+
const runId = state.runId;
|
|
660
|
+
const videoId = plan.videoPath ? await uploadFile(api, state, "VIDEO", plan.videoPath) : void 0;
|
|
661
|
+
const tests = [];
|
|
662
|
+
for (const test of plan.tests) {
|
|
663
|
+
const attempts = [];
|
|
664
|
+
for (const attempt of test.attempts) {
|
|
665
|
+
const { networkLog, screenshotPaths, ...rest } = attempt;
|
|
666
|
+
const screenshotIds = [];
|
|
667
|
+
for (const path of screenshotPaths) {
|
|
668
|
+
const id = await uploadFile(api, state, "SCREENSHOT", path);
|
|
669
|
+
if (id) screenshotIds.push(id);
|
|
670
|
+
}
|
|
671
|
+
let networkId;
|
|
672
|
+
if (networkLog) {
|
|
673
|
+
networkId = await uploadBytes(
|
|
674
|
+
api,
|
|
675
|
+
state,
|
|
676
|
+
"NETWORK_LOG",
|
|
677
|
+
gzipSync(JSON.stringify(networkLog)),
|
|
678
|
+
"application/gzip",
|
|
679
|
+
"requests.json.gz"
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
attempts.push({
|
|
683
|
+
...rest,
|
|
684
|
+
network_upload_id: networkId,
|
|
685
|
+
screenshot_upload_ids: screenshotIds.length ? screenshotIds : void 0
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
tests.push({ ...test, attempts });
|
|
689
|
+
}
|
|
690
|
+
const body = {
|
|
691
|
+
spec: plan.spec,
|
|
692
|
+
started_at: plan.started_at,
|
|
693
|
+
ended_at: plan.ended_at,
|
|
694
|
+
duration_ms: plan.duration_ms,
|
|
695
|
+
video_upload_id: videoId,
|
|
696
|
+
machine_id: machineId,
|
|
697
|
+
tests
|
|
698
|
+
};
|
|
699
|
+
if (!fitPayload(tests, MAX_SPEC_BODY_BYTES, () => Buffer.byteLength(JSON.stringify(body)))) {
|
|
700
|
+
warn(state, `size:${plan.spec}`, `${plan.spec} has too many tests to send even without steps; its results are not sent.`);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
await api.postSpec(runId, body);
|
|
704
|
+
}
|
|
705
|
+
var CONTENT_TYPES = {
|
|
706
|
+
".mp4": "video/mp4",
|
|
707
|
+
".webm": "video/webm",
|
|
708
|
+
".png": "image/png",
|
|
709
|
+
".jpg": "image/jpeg",
|
|
710
|
+
".jpeg": "image/jpeg"
|
|
711
|
+
};
|
|
712
|
+
async function uploadFile(api, state, kind, path) {
|
|
713
|
+
const type = CONTENT_TYPES[extname(path).toLowerCase()];
|
|
714
|
+
if (!type || state.storageFull || !state.runId) return void 0;
|
|
715
|
+
let content;
|
|
716
|
+
try {
|
|
717
|
+
content = await readFile(path);
|
|
718
|
+
} catch (e) {
|
|
719
|
+
warn(state, `read:${kind}`, `Could not read a ${kind.toLowerCase()} (${errorText(e)}); it is not uploaded.`);
|
|
720
|
+
return void 0;
|
|
721
|
+
}
|
|
722
|
+
return uploadBytes(api, state, kind, content, type, path.split(/[\\/]/).pop());
|
|
723
|
+
}
|
|
724
|
+
async function uploadBytes(api, state, kind, content, contentType, fileName) {
|
|
725
|
+
if (state.storageFull || !state.runId) return void 0;
|
|
726
|
+
try {
|
|
727
|
+
const slot = await api.requestUpload(state.runId, {
|
|
728
|
+
kind,
|
|
729
|
+
size_bytes: content.byteLength,
|
|
730
|
+
content_type: contentType,
|
|
731
|
+
file_name: fileName
|
|
732
|
+
});
|
|
733
|
+
await api.upload(slot, content);
|
|
734
|
+
return slot.upload_id;
|
|
735
|
+
} catch (e) {
|
|
736
|
+
if (e instanceof StorageFullError) {
|
|
737
|
+
state.storageFull = true;
|
|
738
|
+
console.log(`${LOG_PREFIX} Storage is full: the remaining videos, screenshots and request logs of this run are not stored.`);
|
|
739
|
+
return void 0;
|
|
740
|
+
}
|
|
741
|
+
warn(state, `upload:${kind}`, `Could not upload a ${kind.toLowerCase().replace("_", " ")}: ${errorText(e)}`);
|
|
742
|
+
return void 0;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
function warn(state, key2, message) {
|
|
746
|
+
if (state.warned.has(key2)) return;
|
|
747
|
+
state.warned.add(key2);
|
|
748
|
+
console.log(`${LOG_PREFIX} ${message}`);
|
|
749
|
+
}
|
|
750
|
+
function appLink(path) {
|
|
751
|
+
const app = process.env.EIP_APP_URL?.trim().replace(/\/+$/, "");
|
|
752
|
+
return app ? `${app}${path}` : "";
|
|
753
|
+
}
|
|
754
|
+
function hhmmss(ms) {
|
|
755
|
+
const total = Math.round(ms / 1e3);
|
|
756
|
+
const h = Math.floor(total / 3600);
|
|
757
|
+
const m = Math.floor(total % 3600 / 60);
|
|
758
|
+
const s = total % 60;
|
|
759
|
+
return [h, m, s].map((n) => String(n).padStart(2, "0")).join(":");
|
|
760
|
+
}
|
|
761
|
+
function errorText(e) {
|
|
762
|
+
return e instanceof Error ? e.message : String(e);
|
|
763
|
+
}
|
|
764
|
+
function stripUndefined(o) {
|
|
765
|
+
return Object.fromEntries(Object.entries(o).filter(([k, v]) => v !== void 0 && k !== "hooks"));
|
|
766
|
+
}
|
|
767
|
+
function withoutNulls(o) {
|
|
768
|
+
return Object.fromEntries(Object.entries(o ?? {}).filter(([, v]) => v !== null && v !== void 0));
|
|
769
|
+
}
|
|
770
|
+
export {
|
|
771
|
+
Redaction,
|
|
772
|
+
escapeGlob,
|
|
773
|
+
hhmmss,
|
|
774
|
+
setupEip
|
|
775
|
+
};
|