@dvl-software/eip-cypress 0.0.0-stage → 0.1.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 +19 -0
- package/LICENSE +8 -0
- package/README.md +129 -2
- package/dist/chunk-YFM4D27K.js +237 -0
- package/dist/cli.js +226 -0
- package/dist/index.cjs +899 -0
- package/dist/index.d.cts +60 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +646 -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 +66 -5
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
interface BrowserAttempt {
|
|
2
|
+
titlePath: string[];
|
|
3
|
+
retry: number;
|
|
4
|
+
state: string;
|
|
5
|
+
wallClockStartedAt?: string;
|
|
6
|
+
durationMs?: number;
|
|
7
|
+
timings?: AttemptTimings;
|
|
8
|
+
error?: {
|
|
9
|
+
name?: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
stack?: string;
|
|
12
|
+
};
|
|
13
|
+
steps: Step[];
|
|
14
|
+
requests: RecordedRequest[];
|
|
15
|
+
console: ConsoleLine[];
|
|
16
|
+
}
|
|
17
|
+
interface AttemptTimings {
|
|
18
|
+
before_all?: HookTiming[];
|
|
19
|
+
before_each?: HookTiming[];
|
|
20
|
+
body?: number;
|
|
21
|
+
after_each?: HookTiming[];
|
|
22
|
+
after_all?: HookTiming[];
|
|
23
|
+
}
|
|
24
|
+
interface HookTiming {
|
|
25
|
+
title?: string;
|
|
26
|
+
ms: number;
|
|
27
|
+
}
|
|
28
|
+
interface Step {
|
|
29
|
+
/** ms since the attempt started */
|
|
30
|
+
t: number;
|
|
31
|
+
name: string;
|
|
32
|
+
message?: string;
|
|
33
|
+
state?: string;
|
|
34
|
+
duration_ms?: number;
|
|
35
|
+
kind?: string;
|
|
36
|
+
/** index into the attempt's requests */
|
|
37
|
+
net_ref?: number;
|
|
38
|
+
}
|
|
39
|
+
interface RecordedRequest {
|
|
40
|
+
id: number;
|
|
41
|
+
t: number;
|
|
42
|
+
source: "app" | "cy.request";
|
|
43
|
+
method: string;
|
|
44
|
+
url: string;
|
|
45
|
+
status?: number;
|
|
46
|
+
duration_ms?: number;
|
|
47
|
+
request: RecordedMessage;
|
|
48
|
+
response: RecordedMessage;
|
|
49
|
+
}
|
|
50
|
+
interface RecordedMessage {
|
|
51
|
+
headers?: Record<string, unknown>;
|
|
52
|
+
body?: unknown;
|
|
53
|
+
body_truncated?: boolean;
|
|
54
|
+
body_omitted?: string;
|
|
55
|
+
size?: number;
|
|
56
|
+
}
|
|
57
|
+
interface ConsoleLine {
|
|
58
|
+
t: number;
|
|
59
|
+
level: string;
|
|
60
|
+
message: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One request or response body; larger ones are left out ("too_large"). */
|
|
64
|
+
declare const MAX_BODY_CHARS: number;
|
|
65
|
+
/** All bodies of one spec together; later ones are left out ("budget"). */
|
|
66
|
+
declare const SPEC_BODY_BUDGET: number;
|
|
67
|
+
/** One cy.task call carries at most about this much; a spec's data goes in several calls. */
|
|
68
|
+
declare const TASK_CHUNK_CHARS: number;
|
|
69
|
+
declare function installRerunFilter(g?: Record<string, unknown>, raw?: string | undefined): void;
|
|
70
|
+
/** Splits attempts into groups of about `max` serialized characters (an attempt larger than that goes alone). */
|
|
71
|
+
declare function chunks(attempts: BrowserAttempt[], max: number): BrowserAttempt[][];
|
|
72
|
+
/** A password input, or an input whose name, id or autocomplete is a secret field name (password, pin, iban …). */
|
|
73
|
+
declare function isSecretInput($el: unknown): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* A body as recorded: binary ones and those over {@link MAX_BODY_CHARS} or beyond the spec's budget are left out
|
|
76
|
+
* with their size — never cut, so the Node side always sees whole JSON with its field names.
|
|
77
|
+
*/
|
|
78
|
+
declare function bodyOf(body: unknown, budget: {
|
|
79
|
+
left: number;
|
|
80
|
+
}): Pick<RecordedMessage, "body" | "body_omitted" | "body_truncated" | "size">;
|
|
81
|
+
/** Cypress hands a Date (or a date string); the backend wants ISO 8601. */
|
|
82
|
+
declare function isoDate(value: unknown): string | undefined;
|
|
83
|
+
|
|
84
|
+
export { MAX_BODY_CHARS, SPEC_BODY_BUDGET, TASK_CHUNK_CHARS, bodyOf, chunks, installRerunFilter, isSecretInput, isoDate };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
interface BrowserAttempt {
|
|
2
|
+
titlePath: string[];
|
|
3
|
+
retry: number;
|
|
4
|
+
state: string;
|
|
5
|
+
wallClockStartedAt?: string;
|
|
6
|
+
durationMs?: number;
|
|
7
|
+
timings?: AttemptTimings;
|
|
8
|
+
error?: {
|
|
9
|
+
name?: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
stack?: string;
|
|
12
|
+
};
|
|
13
|
+
steps: Step[];
|
|
14
|
+
requests: RecordedRequest[];
|
|
15
|
+
console: ConsoleLine[];
|
|
16
|
+
}
|
|
17
|
+
interface AttemptTimings {
|
|
18
|
+
before_all?: HookTiming[];
|
|
19
|
+
before_each?: HookTiming[];
|
|
20
|
+
body?: number;
|
|
21
|
+
after_each?: HookTiming[];
|
|
22
|
+
after_all?: HookTiming[];
|
|
23
|
+
}
|
|
24
|
+
interface HookTiming {
|
|
25
|
+
title?: string;
|
|
26
|
+
ms: number;
|
|
27
|
+
}
|
|
28
|
+
interface Step {
|
|
29
|
+
/** ms since the attempt started */
|
|
30
|
+
t: number;
|
|
31
|
+
name: string;
|
|
32
|
+
message?: string;
|
|
33
|
+
state?: string;
|
|
34
|
+
duration_ms?: number;
|
|
35
|
+
kind?: string;
|
|
36
|
+
/** index into the attempt's requests */
|
|
37
|
+
net_ref?: number;
|
|
38
|
+
}
|
|
39
|
+
interface RecordedRequest {
|
|
40
|
+
id: number;
|
|
41
|
+
t: number;
|
|
42
|
+
source: "app" | "cy.request";
|
|
43
|
+
method: string;
|
|
44
|
+
url: string;
|
|
45
|
+
status?: number;
|
|
46
|
+
duration_ms?: number;
|
|
47
|
+
request: RecordedMessage;
|
|
48
|
+
response: RecordedMessage;
|
|
49
|
+
}
|
|
50
|
+
interface RecordedMessage {
|
|
51
|
+
headers?: Record<string, unknown>;
|
|
52
|
+
body?: unknown;
|
|
53
|
+
body_truncated?: boolean;
|
|
54
|
+
body_omitted?: string;
|
|
55
|
+
size?: number;
|
|
56
|
+
}
|
|
57
|
+
interface ConsoleLine {
|
|
58
|
+
t: number;
|
|
59
|
+
level: string;
|
|
60
|
+
message: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One request or response body; larger ones are left out ("too_large"). */
|
|
64
|
+
declare const MAX_BODY_CHARS: number;
|
|
65
|
+
/** All bodies of one spec together; later ones are left out ("budget"). */
|
|
66
|
+
declare const SPEC_BODY_BUDGET: number;
|
|
67
|
+
/** One cy.task call carries at most about this much; a spec's data goes in several calls. */
|
|
68
|
+
declare const TASK_CHUNK_CHARS: number;
|
|
69
|
+
declare function installRerunFilter(g?: Record<string, unknown>, raw?: string | undefined): void;
|
|
70
|
+
/** Splits attempts into groups of about `max` serialized characters (an attempt larger than that goes alone). */
|
|
71
|
+
declare function chunks(attempts: BrowserAttempt[], max: number): BrowserAttempt[][];
|
|
72
|
+
/** A password input, or an input whose name, id or autocomplete is a secret field name (password, pin, iban …). */
|
|
73
|
+
declare function isSecretInput($el: unknown): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* A body as recorded: binary ones and those over {@link MAX_BODY_CHARS} or beyond the spec's budget are left out
|
|
76
|
+
* with their size — never cut, so the Node side always sees whole JSON with its field names.
|
|
77
|
+
*/
|
|
78
|
+
declare function bodyOf(body: unknown, budget: {
|
|
79
|
+
left: number;
|
|
80
|
+
}): Pick<RecordedMessage, "body" | "body_omitted" | "body_truncated" | "size">;
|
|
81
|
+
/** Cypress hands a Date (or a date string); the backend wants ISO 8601. */
|
|
82
|
+
declare function isoDate(value: unknown): string | undefined;
|
|
83
|
+
|
|
84
|
+
export { MAX_BODY_CHARS, SPEC_BODY_BUDGET, TASK_CHUNK_CHARS, bodyOf, chunks, installRerunFilter, isSecretInput, isoDate };
|
package/dist/support.js
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import {
|
|
2
|
+
REDACTED,
|
|
3
|
+
Redaction
|
|
4
|
+
} from "./chunk-YFM4D27K.js";
|
|
5
|
+
|
|
6
|
+
// src/support/index.ts
|
|
7
|
+
var EIP_HOOKS = /* @__PURE__ */ new Set(["eipCapture", "eipFlush"]);
|
|
8
|
+
var MAX_REQUESTS = 300;
|
|
9
|
+
var MAX_CONSOLE = 500;
|
|
10
|
+
var MAX_STEPS = 500;
|
|
11
|
+
var MAX_BODY_CHARS = 256 * 1024;
|
|
12
|
+
var SPEC_BODY_BUDGET = 16 * 1024 * 1024;
|
|
13
|
+
var TASK_CHUNK_CHARS = 4 * 1024 * 1024;
|
|
14
|
+
var TASK_TIMEOUT_MS = 12e4;
|
|
15
|
+
var MAX_TEXT = 2e3;
|
|
16
|
+
var MAX_STEP_MESSAGE = 4e3;
|
|
17
|
+
function exposed(name) {
|
|
18
|
+
const c = Cypress;
|
|
19
|
+
try {
|
|
20
|
+
const v = typeof c.expose === "function" ? c.expose(name) : c.env(name);
|
|
21
|
+
if (v !== void 0 && v !== null && v !== "") return String(v);
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
installRerunFilter();
|
|
27
|
+
installCapture();
|
|
28
|
+
var CHAIN = new Proxy(function chain() {
|
|
29
|
+
}, {
|
|
30
|
+
get: (_t, p) => p === "then" ? void 0 : () => CHAIN
|
|
31
|
+
});
|
|
32
|
+
function installRerunFilter(g = globalThis, raw = exposed("EIP_RERUN_TITLES")) {
|
|
33
|
+
if (!raw) return;
|
|
34
|
+
let titles;
|
|
35
|
+
try {
|
|
36
|
+
titles = JSON.parse(raw);
|
|
37
|
+
} catch {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!Array.isArray(titles)) return;
|
|
41
|
+
const allowed = new Set(titles.map((p) => p.join("")));
|
|
42
|
+
const stack = [];
|
|
43
|
+
const wrapSuite = (orig) => {
|
|
44
|
+
const wrapped = function(...all) {
|
|
45
|
+
const title = String(all[0]);
|
|
46
|
+
const rest = all.slice(1);
|
|
47
|
+
const fn = rest[rest.length - 1];
|
|
48
|
+
if (typeof fn !== "function") return orig.call(this, ...all);
|
|
49
|
+
const body = function(...args) {
|
|
50
|
+
stack.push(title);
|
|
51
|
+
try {
|
|
52
|
+
return fn.apply(this, args);
|
|
53
|
+
} finally {
|
|
54
|
+
stack.pop();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return orig.call(this, title, ...rest.slice(0, -1), body);
|
|
58
|
+
};
|
|
59
|
+
return wrapped;
|
|
60
|
+
};
|
|
61
|
+
const wrapTest = (orig) => function(...args) {
|
|
62
|
+
const title = String(args[0]);
|
|
63
|
+
if (!allowed.has([...stack, title].join(""))) return CHAIN;
|
|
64
|
+
return orig.apply(this, args);
|
|
65
|
+
};
|
|
66
|
+
const replace = (name, wrap) => {
|
|
67
|
+
const orig = g[name];
|
|
68
|
+
if (typeof orig !== "function") return;
|
|
69
|
+
const wrapped = Object.assign(wrap(orig), orig);
|
|
70
|
+
if (typeof orig.only === "function") wrapped.only = wrap(orig.only);
|
|
71
|
+
if (typeof orig.skip === "function") wrapped.skip = wrap(orig.skip);
|
|
72
|
+
g[name] = wrapped;
|
|
73
|
+
};
|
|
74
|
+
for (const name of ["describe", "context", "xdescribe", "xcontext"]) replace(name, wrapSuite);
|
|
75
|
+
for (const name of ["it", "specify", "xit", "xspecify"]) replace(name, wrapTest);
|
|
76
|
+
}
|
|
77
|
+
function installCapture() {
|
|
78
|
+
if (!exposed("EIP_PLUGIN")) return;
|
|
79
|
+
const attempts = [];
|
|
80
|
+
const hookTitles = /* @__PURE__ */ new Map();
|
|
81
|
+
const budget = { left: SPEC_BODY_BUDGET };
|
|
82
|
+
let exclude;
|
|
83
|
+
try {
|
|
84
|
+
const pattern = exposed("EIP_CAPTURE_EXCLUDE");
|
|
85
|
+
exclude = pattern ? new RegExp(pattern) : void 0;
|
|
86
|
+
} catch {
|
|
87
|
+
exclude = void 0;
|
|
88
|
+
}
|
|
89
|
+
let current;
|
|
90
|
+
let preTest = fresh();
|
|
91
|
+
let inEipHook = false;
|
|
92
|
+
let requestSeq = 0;
|
|
93
|
+
function fresh() {
|
|
94
|
+
return { started: performance.now(), steps: [], requests: [], console: [], stepById: /* @__PURE__ */ new Map() };
|
|
95
|
+
}
|
|
96
|
+
const target = () => current ?? preTest;
|
|
97
|
+
const since = () => Math.round(performance.now() - target().started);
|
|
98
|
+
function toAttempt(a, attrs, runnable) {
|
|
99
|
+
const err = attrs.err;
|
|
100
|
+
const retry = typeof attrs.currentRetry === "number" ? attrs.currentRetry : runnable?._currentRetry ?? attrs._currentRetry ?? 0;
|
|
101
|
+
return {
|
|
102
|
+
titlePath: runnable?.titlePath?.() ?? (typeof attrs.titlePath === "function" ? attrs.titlePath() : [String(attrs.title ?? "")]),
|
|
103
|
+
retry: Number(retry) || 0,
|
|
104
|
+
state: String(attrs.state ?? "unknown"),
|
|
105
|
+
wallClockStartedAt: isoDate(attrs.wallClockStartedAt),
|
|
106
|
+
durationMs: typeof attrs.duration === "number" ? attrs.duration : void 0,
|
|
107
|
+
timings: convertTimings(attrs.timings, hookTitles),
|
|
108
|
+
error: err ? { name: err.name, message: clip(err.message, 2e4), stack: clip(err.stack, 2e4) } : void 0,
|
|
109
|
+
steps: a.steps.slice(0, MAX_STEPS),
|
|
110
|
+
requests: a.requests.slice(0, MAX_REQUESTS),
|
|
111
|
+
console: a.console.slice(0, MAX_CONSOLE)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const runner = Cypress.mocha.getRunner();
|
|
115
|
+
runner.on("hook", (hook) => {
|
|
116
|
+
const title = hookTitle(hook);
|
|
117
|
+
inEipHook = EIP_HOOKS.has(title);
|
|
118
|
+
if (hook.hookId) hookTitles.set(hook.hookId, title);
|
|
119
|
+
});
|
|
120
|
+
runner.on("hook end", () => {
|
|
121
|
+
inEipHook = false;
|
|
122
|
+
});
|
|
123
|
+
runner.on("test", () => {
|
|
124
|
+
const carried = preTest;
|
|
125
|
+
current = fresh();
|
|
126
|
+
current.steps.push(...carried.steps.map((s) => ({ ...s, t: 0 })));
|
|
127
|
+
preTest = fresh();
|
|
128
|
+
});
|
|
129
|
+
Cypress.on("test:after:run", (attrs, runnable) => {
|
|
130
|
+
attempts.push(toAttempt(current ?? fresh(), attrs, runnable));
|
|
131
|
+
current = void 0;
|
|
132
|
+
});
|
|
133
|
+
const isProxyLog = (attrs) => attrs.name === "request" && attrs.event === true;
|
|
134
|
+
const masked = /* @__PURE__ */ new Set();
|
|
135
|
+
Cypress.on("log:added", (attrs, log) => {
|
|
136
|
+
if (inEipHook || attrs.instrument !== "command" || isProxyLog(attrs)) return;
|
|
137
|
+
const secretInput = attrs.name === "type" && isSecretInput(safeGet(log, "$el"));
|
|
138
|
+
if (secretInput && attrs.id) masked.add(String(attrs.id));
|
|
139
|
+
const step = {
|
|
140
|
+
t: since(),
|
|
141
|
+
name: String(attrs.name ?? ""),
|
|
142
|
+
message: secretInput ? REDACTED : clip(plain(attrs.message), MAX_STEP_MESSAGE),
|
|
143
|
+
state: attrs.state ? String(attrs.state) : void 0,
|
|
144
|
+
kind: attrs.type ? String(attrs.type) : void 0
|
|
145
|
+
};
|
|
146
|
+
const a = target();
|
|
147
|
+
if (a.steps.length < MAX_STEPS) {
|
|
148
|
+
a.steps.push(step);
|
|
149
|
+
if (attrs.id) a.stepById.set(String(attrs.id), step);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
Cypress.on("log:changed", (attrs) => {
|
|
153
|
+
if (inEipHook || attrs.instrument !== "command" || isProxyLog(attrs)) return;
|
|
154
|
+
const a = target();
|
|
155
|
+
const step = attrs.id ? a.stepById.get(String(attrs.id)) : void 0;
|
|
156
|
+
if (!step) return;
|
|
157
|
+
if (attrs.state) step.state = String(attrs.state);
|
|
158
|
+
if (attrs.state === "passed" || attrs.state === "failed") {
|
|
159
|
+
step.duration_ms = Math.max(0, since() - step.t);
|
|
160
|
+
if (!masked.has(String(attrs.id))) step.message = clip(plain(attrs.message), MAX_STEP_MESSAGE) || step.message;
|
|
161
|
+
}
|
|
162
|
+
if (attrs.name === "request" && (attrs.state === "passed" || attrs.state === "failed") && step.net_ref === void 0) {
|
|
163
|
+
const recorded = fromCyRequest(attrs.consoleProps, step.t, step.duration_ms, budget);
|
|
164
|
+
if (recorded && a.requests.length < MAX_REQUESTS) {
|
|
165
|
+
recorded.id = ++requestSeq;
|
|
166
|
+
a.requests.push(recorded);
|
|
167
|
+
step.net_ref = a.requests.length - 1;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
Cypress.on("window:before:load", (win) => {
|
|
172
|
+
for (const level of ["log", "info", "warn", "error", "debug"]) {
|
|
173
|
+
const original = win.console[level];
|
|
174
|
+
win.console[level] = (...args) => {
|
|
175
|
+
const a = target();
|
|
176
|
+
if (a.console.length < MAX_CONSOLE) {
|
|
177
|
+
a.console.push({ t: since(), level, message: clip(args.map(formatArg).join(" "), MAX_TEXT) ?? "" });
|
|
178
|
+
}
|
|
179
|
+
return original.apply(win.console, args);
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
Cypress.on("uncaught:exception", (err) => {
|
|
184
|
+
const a = target();
|
|
185
|
+
if (a.console.length < MAX_CONSOLE) {
|
|
186
|
+
a.console.push({ t: since(), level: "error", message: clip(`Uncaught ${err.name}: ${err.message}`, MAX_TEXT) ?? "" });
|
|
187
|
+
}
|
|
188
|
+
return void 0;
|
|
189
|
+
});
|
|
190
|
+
beforeEach(function eipCapture() {
|
|
191
|
+
cy.intercept({ resourceType: /^(xhr|fetch)$/ }, (req) => {
|
|
192
|
+
const accept = String(req.headers.accept ?? "");
|
|
193
|
+
if (accept.includes("text/event-stream") || exclude && exclude.test(req.url)) return;
|
|
194
|
+
const started = performance.now();
|
|
195
|
+
const t = since();
|
|
196
|
+
const request = { headers: { ...req.headers }, ...bodyOf(req.body, budget) };
|
|
197
|
+
req.on("after:response", (res) => {
|
|
198
|
+
const a = target();
|
|
199
|
+
if (a.requests.length >= MAX_REQUESTS) return;
|
|
200
|
+
const entry = {
|
|
201
|
+
id: ++requestSeq,
|
|
202
|
+
t,
|
|
203
|
+
source: "app",
|
|
204
|
+
method: req.method,
|
|
205
|
+
url: req.url,
|
|
206
|
+
status: res.statusCode,
|
|
207
|
+
duration_ms: Math.round(performance.now() - started),
|
|
208
|
+
request,
|
|
209
|
+
response: { headers: { ...res.headers }, ...bodyOf(res.body, budget) }
|
|
210
|
+
};
|
|
211
|
+
a.requests.push(entry);
|
|
212
|
+
if (a.steps.length < MAX_STEPS) {
|
|
213
|
+
a.steps.push({
|
|
214
|
+
t,
|
|
215
|
+
name: req.resourceType === "fetch" ? "fetch" : "xhr",
|
|
216
|
+
message: `${req.method} ${pathOf(req.url)} ${res.statusCode}`,
|
|
217
|
+
state: res.statusCode >= 400 ? "failed" : "passed",
|
|
218
|
+
duration_ms: entry.duration_ms,
|
|
219
|
+
net_ref: a.requests.length - 1
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
after(function eipFlush() {
|
|
226
|
+
const batch = attempts.splice(0);
|
|
227
|
+
const last = this.currentTest;
|
|
228
|
+
if (current && last) {
|
|
229
|
+
batch.push(toAttempt(current, last));
|
|
230
|
+
current = void 0;
|
|
231
|
+
}
|
|
232
|
+
for (const chunk of chunks(batch, TASK_CHUNK_CHARS)) {
|
|
233
|
+
cy.task("eip:events", { attempts: chunk }, { log: false, timeout: TASK_TIMEOUT_MS });
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function chunks(attempts, max) {
|
|
238
|
+
const out = [];
|
|
239
|
+
let group = [];
|
|
240
|
+
let size = 0;
|
|
241
|
+
for (const a of attempts) {
|
|
242
|
+
let n;
|
|
243
|
+
try {
|
|
244
|
+
n = JSON.stringify(a).length;
|
|
245
|
+
} catch {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (group.length && size + n > max) {
|
|
249
|
+
out.push(group);
|
|
250
|
+
group = [];
|
|
251
|
+
size = 0;
|
|
252
|
+
}
|
|
253
|
+
group.push(a);
|
|
254
|
+
size += n;
|
|
255
|
+
}
|
|
256
|
+
if (group.length) out.push(group);
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
function safeGet(log, key) {
|
|
260
|
+
try {
|
|
261
|
+
return log?.get?.(key);
|
|
262
|
+
} catch {
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function isSecretInput($el) {
|
|
267
|
+
const el = $el?.[0] ?? $el;
|
|
268
|
+
if (!el || typeof el !== "object") return false;
|
|
269
|
+
const input = el;
|
|
270
|
+
if (String(input.type ?? "").toLowerCase() === "password") return true;
|
|
271
|
+
const names = [input.name, input.id, input.autocomplete].filter((v) => typeof v === "string" && v !== "");
|
|
272
|
+
const pass = new Redaction();
|
|
273
|
+
return names.some((n) => pass.isSecretField(n) || /^(current|new)-password$|^one-time-code$/.test(n));
|
|
274
|
+
}
|
|
275
|
+
function convertTimings(raw, titles) {
|
|
276
|
+
if (!raw) return void 0;
|
|
277
|
+
const hooks = (key) => {
|
|
278
|
+
const list = raw[key];
|
|
279
|
+
if (!Array.isArray(list)) return void 0;
|
|
280
|
+
const out = list.map((h) => ({ title: titles.get(h.hookId ?? "") ?? void 0, ms: (h.fnDuration ?? 0) + (h.afterFnDuration ?? 0) })).filter((h) => !h.title || !EIP_HOOKS.has(h.title));
|
|
281
|
+
return out.length ? out : void 0;
|
|
282
|
+
};
|
|
283
|
+
const body = raw.test;
|
|
284
|
+
return {
|
|
285
|
+
before_all: hooks("before all"),
|
|
286
|
+
before_each: hooks("before each"),
|
|
287
|
+
body: body ? (body.fnDuration ?? 0) + (body.afterFnDuration ?? 0) : void 0,
|
|
288
|
+
after_each: hooks("after each"),
|
|
289
|
+
after_all: hooks("after all")
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function hookTitle(hook) {
|
|
293
|
+
const m = /hook: (.+)$/.exec(hook.title ?? "");
|
|
294
|
+
return m?.[1] ?? hook.hookName ?? hook.title ?? "";
|
|
295
|
+
}
|
|
296
|
+
function fromCyRequest(consoleProps, t, duration, budget) {
|
|
297
|
+
const props = consoleProps?.props ?? consoleProps;
|
|
298
|
+
const req = props?.Request ?? props?.["Requests"];
|
|
299
|
+
const r = Array.isArray(req) ? req[req.length - 1] : req;
|
|
300
|
+
if (!r) return void 0;
|
|
301
|
+
const url = String(r["Request URL"] ?? "");
|
|
302
|
+
const status = Number(r["Response Status"]);
|
|
303
|
+
return {
|
|
304
|
+
id: 0,
|
|
305
|
+
t,
|
|
306
|
+
source: "cy.request",
|
|
307
|
+
method: String(r["Request Method"] ?? methodGuess(props)),
|
|
308
|
+
url,
|
|
309
|
+
status: Number.isFinite(status) ? status : void 0,
|
|
310
|
+
duration_ms: duration,
|
|
311
|
+
request: { headers: r["Request Headers"] ?? {}, ...bodyOf(r["Request Body"], budget) },
|
|
312
|
+
response: { headers: r["Response Headers"] ?? {}, ...bodyOf(r["Response Body"], budget) }
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function methodGuess(props) {
|
|
316
|
+
const yielded = props?.Yielded;
|
|
317
|
+
return yielded?.allRequestResponses?.[0]?.["Request Method"] ?? "GET";
|
|
318
|
+
}
|
|
319
|
+
function bodyOf(body, budget) {
|
|
320
|
+
if (body === void 0 || body === null || body === "") return {};
|
|
321
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body) || typeof Blob !== "undefined" && body instanceof Blob) {
|
|
322
|
+
const size = body instanceof Blob ? body.size : body.byteLength;
|
|
323
|
+
return { body_omitted: "binary", size };
|
|
324
|
+
}
|
|
325
|
+
let text;
|
|
326
|
+
try {
|
|
327
|
+
text = typeof body === "string" ? body : JSON.stringify(body);
|
|
328
|
+
} catch {
|
|
329
|
+
return { body_omitted: "unreadable" };
|
|
330
|
+
}
|
|
331
|
+
if (text === void 0) return { body_omitted: "unreadable" };
|
|
332
|
+
if (text.length > MAX_BODY_CHARS) return { body_omitted: "too_large", size: text.length };
|
|
333
|
+
if (text.length > budget.left) return { body_omitted: "budget", size: text.length };
|
|
334
|
+
budget.left -= text.length;
|
|
335
|
+
return { body: typeof body === "string" ? body : JSON.parse(text) };
|
|
336
|
+
}
|
|
337
|
+
function formatArg(arg) {
|
|
338
|
+
if (typeof arg === "string") return arg;
|
|
339
|
+
if (arg instanceof Error) return `${arg.name}: ${arg.message}`;
|
|
340
|
+
try {
|
|
341
|
+
return JSON.stringify(arg);
|
|
342
|
+
} catch {
|
|
343
|
+
return String(arg);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function plain(message) {
|
|
347
|
+
return String(message ?? "").replace(/\*\*/g, "");
|
|
348
|
+
}
|
|
349
|
+
function pathOf(url) {
|
|
350
|
+
try {
|
|
351
|
+
const u = new URL(url);
|
|
352
|
+
return u.pathname + u.search;
|
|
353
|
+
} catch {
|
|
354
|
+
return url;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function isoDate(value) {
|
|
358
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
359
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
360
|
+
return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
361
|
+
}
|
|
362
|
+
function clip(text, max) {
|
|
363
|
+
if (text === void 0) return void 0;
|
|
364
|
+
return text.length > max ? text.slice(0, max) : text;
|
|
365
|
+
}
|
|
366
|
+
export {
|
|
367
|
+
MAX_BODY_CHARS,
|
|
368
|
+
SPEC_BODY_BUDGET,
|
|
369
|
+
TASK_CHUNK_CHARS,
|
|
370
|
+
bodyOf,
|
|
371
|
+
chunks,
|
|
372
|
+
installRerunFilter,
|
|
373
|
+
isSecretInput,
|
|
374
|
+
isoDate
|
|
375
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@dvl-software/eip-cypress",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Send Cypress runs to the DVL Engineering Insights Platform: run numbers, hook timings, retries, steps, network and console logs (cleaned of secrets and personal data), videos, and re-runs of failed and skipped tests.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=18"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"eip-cypress": "dist/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./support": {
|
|
24
|
+
"types": "./dist/support.d.ts",
|
|
25
|
+
"import": "./dist/support.js",
|
|
26
|
+
"require": "./dist/support.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"CHANGELOG.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:watch": "vitest",
|
|
39
|
+
"type-check": "tsc --noEmit",
|
|
40
|
+
"spike": "cd spike && cypress run",
|
|
41
|
+
"prepublishOnly": "bun run type-check && bun run test && bun run build"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"cypress": ">=13.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^22.10.0",
|
|
48
|
+
"cypress": "15.21.2",
|
|
49
|
+
"tsup": "^8.3.5",
|
|
50
|
+
"typescript": "^5.7.2",
|
|
51
|
+
"vitest": "^2.1.8"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"keywords": [
|
|
57
|
+
"cypress",
|
|
58
|
+
"cypress-plugin",
|
|
59
|
+
"test-results",
|
|
60
|
+
"eip",
|
|
61
|
+
"dvl-software"
|
|
62
|
+
],
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "git+https://github.com/dvl-software/dvl-eip-cypress-plugin.git"
|
|
66
|
+
}
|
|
67
|
+
}
|