@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
package/dist/support.cjs
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/support/index.ts
|
|
23
|
+
var support_exports = {};
|
|
24
|
+
__export(support_exports, {
|
|
25
|
+
MAX_BODY_CHARS: () => MAX_BODY_CHARS,
|
|
26
|
+
SPEC_BODY_BUDGET: () => SPEC_BODY_BUDGET,
|
|
27
|
+
TASK_CHUNK_CHARS: () => TASK_CHUNK_CHARS,
|
|
28
|
+
bodyOf: () => bodyOf,
|
|
29
|
+
chunks: () => chunks,
|
|
30
|
+
installRerunFilter: () => installRerunFilter,
|
|
31
|
+
isSecretInput: () => isSecretInput,
|
|
32
|
+
isoDate: () => isoDate
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(support_exports);
|
|
35
|
+
|
|
36
|
+
// src/redact.ts
|
|
37
|
+
var REDACTED = "[redacted]";
|
|
38
|
+
var EMAIL = "[email]";
|
|
39
|
+
var PHONE = "[phone]";
|
|
40
|
+
var SECRET_FIELDS = /* @__PURE__ */ new Set([
|
|
41
|
+
"password",
|
|
42
|
+
"passwd",
|
|
43
|
+
"pwd",
|
|
44
|
+
"secret",
|
|
45
|
+
"token",
|
|
46
|
+
"accesstoken",
|
|
47
|
+
"refreshtoken",
|
|
48
|
+
"idtoken",
|
|
49
|
+
"apikey",
|
|
50
|
+
"clientsecret",
|
|
51
|
+
"authorization",
|
|
52
|
+
"otp",
|
|
53
|
+
"pin",
|
|
54
|
+
"iban",
|
|
55
|
+
"cardnumber",
|
|
56
|
+
"creditcard",
|
|
57
|
+
"cvv",
|
|
58
|
+
"cvc",
|
|
59
|
+
"ssn",
|
|
60
|
+
"taxid",
|
|
61
|
+
"privatekey",
|
|
62
|
+
"sessionid",
|
|
63
|
+
"cookie",
|
|
64
|
+
"setcookie"
|
|
65
|
+
]);
|
|
66
|
+
var SECRET_FIELD_SUFFIXES = ["password", "secret", "token"];
|
|
67
|
+
var SECRET_HEADER_PARTS = ["auth", "cookie", "token", "secret", "key", "session", "password"];
|
|
68
|
+
var BEARER = /\bBearer\s+[A-Za-z0-9._~+/=-]+/gi;
|
|
69
|
+
var JWT = /(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g;
|
|
70
|
+
var EMAIL_PATTERN = /(?<![A-Za-z0-9._%+-])[A-Za-z0-9._%+-]{1,256}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,}/g;
|
|
71
|
+
var IBAN = /\b[A-Z]{2}\d{2}(?:\s?[A-Z0-9]{4}){2,7}(?:\s?[A-Z0-9]{1,3})?\b/g;
|
|
72
|
+
var CARD = /(?<!\d)\d(?:[ -]?\d){12,18}(?!\d)/g;
|
|
73
|
+
var PHONE_PATTERN = /\+\d{1,3}(?:[\s.-]?\(\d{1,4}\))?(?:[\s.-]?\d{2,8}){1,4}(?!\d)/g;
|
|
74
|
+
var FORM = /^[^=&\s]+=[^&]*(?:&[^=&\s]+=[^&]*)*$/;
|
|
75
|
+
var URL_IN_TEXT = /https?:\/\/[^\s"'<>]*[^\s"'<>.,;:!?)]|(?<![^\s"'`<>(\[{=,])\/[^\s"'`<>(\[{=,?#]{0,2048}[?#][^\s"'<>]*[^\s"'<>.,;:!?)]/g;
|
|
76
|
+
var JSON_PAIR = /"([^"\\]{1,100})"(\s*:\s*)"([^"\\]*(?:\\.[^"\\]*)*)"/g;
|
|
77
|
+
var USER_INFO = /^(https?:\/\/)[^/@\s]+@/;
|
|
78
|
+
var STARTS_WITH_URL = /^https?:\/\//;
|
|
79
|
+
var MAX_EXTRA_PATTERNS = 20;
|
|
80
|
+
var MAX_EXTRA_PATTERN_LENGTH = 200;
|
|
81
|
+
function normalize(name) {
|
|
82
|
+
return name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
83
|
+
}
|
|
84
|
+
function validIban(candidate) {
|
|
85
|
+
const iban = candidate.replace(/ /g, "");
|
|
86
|
+
if (iban.length < 15 || iban.length > 34) return false;
|
|
87
|
+
const rearranged = iban.slice(4) + iban.slice(0, 4);
|
|
88
|
+
let remainder = 0;
|
|
89
|
+
for (const c of rearranged) {
|
|
90
|
+
const digits = /[A-Z]/.test(c) ? String(c.charCodeAt(0) - 55) : c;
|
|
91
|
+
for (const d of digits) {
|
|
92
|
+
remainder = (remainder * 10 + Number(d)) % 97;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return remainder === 1;
|
|
96
|
+
}
|
|
97
|
+
function luhn(candidate) {
|
|
98
|
+
const digits = candidate.replace(/[ -]/g, "");
|
|
99
|
+
if (digits.length < 13 || digits.length > 19) return false;
|
|
100
|
+
let sum = 0;
|
|
101
|
+
let dbl = false;
|
|
102
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
103
|
+
let d = digits.charCodeAt(i) - 48;
|
|
104
|
+
if (dbl) {
|
|
105
|
+
d *= 2;
|
|
106
|
+
if (d > 9) d -= 9;
|
|
107
|
+
}
|
|
108
|
+
sum += d;
|
|
109
|
+
dbl = !dbl;
|
|
110
|
+
}
|
|
111
|
+
return sum % 10 === 0;
|
|
112
|
+
}
|
|
113
|
+
function phoneLength(candidate) {
|
|
114
|
+
const n = candidate.replace(/\D/g, "").length;
|
|
115
|
+
return n >= 8 && n <= 15;
|
|
116
|
+
}
|
|
117
|
+
function compile(patterns) {
|
|
118
|
+
const out = [];
|
|
119
|
+
for (const raw of patterns ?? []) {
|
|
120
|
+
if (!raw || raw.length > MAX_EXTRA_PATTERN_LENGTH || out.length >= MAX_EXTRA_PATTERNS) continue;
|
|
121
|
+
try {
|
|
122
|
+
out.push(new RegExp(raw, "g"));
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
var Redaction = class {
|
|
129
|
+
constructor(extraFields = [], extraPatterns = []) {
|
|
130
|
+
__publicField(this, "count", 0);
|
|
131
|
+
__publicField(this, "extraFields");
|
|
132
|
+
__publicField(this, "extraPatterns");
|
|
133
|
+
this.extraFields = new Set(extraFields.filter((f) => f && f.trim()).map(normalize));
|
|
134
|
+
this.extraPatterns = compile(extraPatterns);
|
|
135
|
+
}
|
|
136
|
+
isSecretField(name) {
|
|
137
|
+
const n = normalize(name);
|
|
138
|
+
return SECRET_FIELDS.has(n) || this.extraFields.has(n) || SECRET_FIELD_SUFFIXES.some((s) => n.endsWith(s));
|
|
139
|
+
}
|
|
140
|
+
headers(headers) {
|
|
141
|
+
if (!isObject(headers)) return headers;
|
|
142
|
+
const out = {};
|
|
143
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
144
|
+
const n = normalize(key);
|
|
145
|
+
const secret = SECRET_HEADER_PARTS.some((p) => n.includes(p)) || this.isSecretField(key);
|
|
146
|
+
if (secret && value !== null && value !== void 0) {
|
|
147
|
+
out[key] = REDACTED;
|
|
148
|
+
this.count++;
|
|
149
|
+
} else if (Array.isArray(value)) {
|
|
150
|
+
out[key] = value.map((item) => typeof item === "string" ? this.text(item) : item);
|
|
151
|
+
} else if (typeof value === "string") {
|
|
152
|
+
out[key] = STARTS_WITH_URL.test(value) ? this.url(value) : this.text(value);
|
|
153
|
+
} else {
|
|
154
|
+
out[key] = value;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
body(body) {
|
|
160
|
+
if (Array.isArray(body)) return body.map((item) => this.body(item));
|
|
161
|
+
if (isObject(body)) {
|
|
162
|
+
const out = {};
|
|
163
|
+
for (const [key, value] of Object.entries(body)) {
|
|
164
|
+
if (this.isSecretField(key) && value !== null && value !== void 0) {
|
|
165
|
+
out[key] = REDACTED;
|
|
166
|
+
this.count++;
|
|
167
|
+
} else {
|
|
168
|
+
out[key] = this.body(value);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
if (typeof body === "string") return this.stringBody(body);
|
|
174
|
+
return body;
|
|
175
|
+
}
|
|
176
|
+
stringBody(s) {
|
|
177
|
+
const trimmed = s.trim();
|
|
178
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
179
|
+
try {
|
|
180
|
+
return JSON.stringify(this.body(JSON.parse(trimmed)));
|
|
181
|
+
} catch {
|
|
182
|
+
return this.text(s);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (FORM.test(trimmed)) return this.pairs(trimmed);
|
|
186
|
+
return this.text(s);
|
|
187
|
+
}
|
|
188
|
+
pairs(query) {
|
|
189
|
+
return query.split("&").map((pair) => {
|
|
190
|
+
const eq = pair.indexOf("=");
|
|
191
|
+
if (eq < 0) return this.text(pair);
|
|
192
|
+
const key = pair.slice(0, eq);
|
|
193
|
+
const value = pair.slice(eq + 1);
|
|
194
|
+
if (this.isSecretField(decode(key)) && value !== "") {
|
|
195
|
+
this.count++;
|
|
196
|
+
return `${key}=${REDACTED}`;
|
|
197
|
+
}
|
|
198
|
+
const decoded = decode(value);
|
|
199
|
+
const cleaned = this.text(decoded);
|
|
200
|
+
return `${key}=${cleaned === decoded ? value : cleaned}`;
|
|
201
|
+
}).join("&");
|
|
202
|
+
}
|
|
203
|
+
/** User info, base through the value patterns, query and a `k=v` fragment through the pair rules. */
|
|
204
|
+
url(url) {
|
|
205
|
+
let u = url;
|
|
206
|
+
if (USER_INFO.test(u)) {
|
|
207
|
+
u = u.replace(USER_INFO, `$1${REDACTED}@`);
|
|
208
|
+
this.count++;
|
|
209
|
+
}
|
|
210
|
+
const hash = u.indexOf("#");
|
|
211
|
+
const beforeHash = hash < 0 ? u : u.slice(0, hash);
|
|
212
|
+
const fragment = hash < 0 ? void 0 : u.slice(hash + 1);
|
|
213
|
+
const q = beforeHash.indexOf("?");
|
|
214
|
+
let out = this.plain(q < 0 ? beforeHash : beforeHash.slice(0, q));
|
|
215
|
+
if (q >= 0) out += `?${this.pairs(beforeHash.slice(q + 1))}`;
|
|
216
|
+
if (fragment !== void 0) out += `#${fragment.includes("=") ? this.pairs(fragment) : this.plain(fragment)}`;
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
/** URLs in the text (through {@link url}), then `"secret": "…"` pairs, then the value patterns. */
|
|
220
|
+
text(text) {
|
|
221
|
+
if (!text) return text;
|
|
222
|
+
let out = text.replace(URL_IN_TEXT, (match) => this.url(match));
|
|
223
|
+
out = out.replace(JSON_PAIR, (match, key, sep) => {
|
|
224
|
+
if (!this.isSecretField(key)) return match;
|
|
225
|
+
this.count++;
|
|
226
|
+
return `"${key}"${sep}"${REDACTED}"`;
|
|
227
|
+
});
|
|
228
|
+
return this.plain(out);
|
|
229
|
+
}
|
|
230
|
+
/** The value patterns only: bearer, JWT, email, IBAN, card, phone, own patterns. */
|
|
231
|
+
plain(text) {
|
|
232
|
+
if (!text) return text;
|
|
233
|
+
let out = this.replace(text, BEARER, () => `Bearer ${REDACTED}`);
|
|
234
|
+
out = this.replace(out, JWT, () => REDACTED);
|
|
235
|
+
out = this.replace(out, EMAIL_PATTERN, () => EMAIL);
|
|
236
|
+
out = this.replace(out, IBAN, () => REDACTED, validIban);
|
|
237
|
+
out = this.replace(out, CARD, () => REDACTED, luhn);
|
|
238
|
+
out = this.replace(out, PHONE_PATTERN, () => PHONE, phoneLength);
|
|
239
|
+
for (const extra of this.extraPatterns) {
|
|
240
|
+
out = this.replace(out, extra, () => REDACTED);
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
replace(text, pattern, by, check) {
|
|
245
|
+
pattern.lastIndex = 0;
|
|
246
|
+
return text.replace(pattern, (match) => {
|
|
247
|
+
if (!match || check && !check(match)) return match;
|
|
248
|
+
this.count++;
|
|
249
|
+
return by();
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
function decode(value) {
|
|
254
|
+
try {
|
|
255
|
+
return decodeURIComponent(value.replace(/\+/g, " "));
|
|
256
|
+
} catch {
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function isObject(v) {
|
|
261
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/support/index.ts
|
|
265
|
+
var EIP_HOOKS = /* @__PURE__ */ new Set(["eipCapture", "eipFlush"]);
|
|
266
|
+
var MAX_REQUESTS = 300;
|
|
267
|
+
var MAX_CONSOLE = 500;
|
|
268
|
+
var MAX_STEPS = 500;
|
|
269
|
+
var MAX_BODY_CHARS = 256 * 1024;
|
|
270
|
+
var SPEC_BODY_BUDGET = 16 * 1024 * 1024;
|
|
271
|
+
var TASK_CHUNK_CHARS = 4 * 1024 * 1024;
|
|
272
|
+
var TASK_TIMEOUT_MS = 12e4;
|
|
273
|
+
var MAX_TEXT = 2e3;
|
|
274
|
+
var MAX_STEP_MESSAGE = 4e3;
|
|
275
|
+
function exposed(name) {
|
|
276
|
+
const c = Cypress;
|
|
277
|
+
try {
|
|
278
|
+
const v = typeof c.expose === "function" ? c.expose(name) : c.env(name);
|
|
279
|
+
if (v !== void 0 && v !== null && v !== "") return String(v);
|
|
280
|
+
} catch {
|
|
281
|
+
}
|
|
282
|
+
return void 0;
|
|
283
|
+
}
|
|
284
|
+
installRerunFilter();
|
|
285
|
+
installCapture();
|
|
286
|
+
var CHAIN = new Proxy(function chain() {
|
|
287
|
+
}, {
|
|
288
|
+
get: (_t, p) => p === "then" ? void 0 : () => CHAIN
|
|
289
|
+
});
|
|
290
|
+
function installRerunFilter(g = globalThis, raw = exposed("EIP_RERUN_TITLES")) {
|
|
291
|
+
if (!raw) return;
|
|
292
|
+
let titles;
|
|
293
|
+
try {
|
|
294
|
+
titles = JSON.parse(raw);
|
|
295
|
+
} catch {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (!Array.isArray(titles)) return;
|
|
299
|
+
const allowed = new Set(titles.map((p) => p.join("")));
|
|
300
|
+
const stack = [];
|
|
301
|
+
const wrapSuite = (orig) => {
|
|
302
|
+
const wrapped = function(...all) {
|
|
303
|
+
const title = String(all[0]);
|
|
304
|
+
const rest = all.slice(1);
|
|
305
|
+
const fn = rest[rest.length - 1];
|
|
306
|
+
if (typeof fn !== "function") return orig.call(this, ...all);
|
|
307
|
+
const body = function(...args) {
|
|
308
|
+
stack.push(title);
|
|
309
|
+
try {
|
|
310
|
+
return fn.apply(this, args);
|
|
311
|
+
} finally {
|
|
312
|
+
stack.pop();
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
return orig.call(this, title, ...rest.slice(0, -1), body);
|
|
316
|
+
};
|
|
317
|
+
return wrapped;
|
|
318
|
+
};
|
|
319
|
+
const wrapTest = (orig) => function(...args) {
|
|
320
|
+
const title = String(args[0]);
|
|
321
|
+
if (!allowed.has([...stack, title].join(""))) return CHAIN;
|
|
322
|
+
return orig.apply(this, args);
|
|
323
|
+
};
|
|
324
|
+
const replace = (name, wrap) => {
|
|
325
|
+
const orig = g[name];
|
|
326
|
+
if (typeof orig !== "function") return;
|
|
327
|
+
const wrapped = Object.assign(wrap(orig), orig);
|
|
328
|
+
if (typeof orig.only === "function") wrapped.only = wrap(orig.only);
|
|
329
|
+
if (typeof orig.skip === "function") wrapped.skip = wrap(orig.skip);
|
|
330
|
+
g[name] = wrapped;
|
|
331
|
+
};
|
|
332
|
+
for (const name of ["describe", "context", "xdescribe", "xcontext"]) replace(name, wrapSuite);
|
|
333
|
+
for (const name of ["it", "specify", "xit", "xspecify"]) replace(name, wrapTest);
|
|
334
|
+
}
|
|
335
|
+
function installCapture() {
|
|
336
|
+
if (!exposed("EIP_PLUGIN")) return;
|
|
337
|
+
const attempts = [];
|
|
338
|
+
const hookTitles = /* @__PURE__ */ new Map();
|
|
339
|
+
const budget = { left: SPEC_BODY_BUDGET };
|
|
340
|
+
let exclude;
|
|
341
|
+
try {
|
|
342
|
+
const pattern = exposed("EIP_CAPTURE_EXCLUDE");
|
|
343
|
+
exclude = pattern ? new RegExp(pattern) : void 0;
|
|
344
|
+
} catch {
|
|
345
|
+
exclude = void 0;
|
|
346
|
+
}
|
|
347
|
+
let current;
|
|
348
|
+
let preTest = fresh();
|
|
349
|
+
let inEipHook = false;
|
|
350
|
+
let requestSeq = 0;
|
|
351
|
+
function fresh() {
|
|
352
|
+
return { started: performance.now(), steps: [], requests: [], console: [], stepById: /* @__PURE__ */ new Map() };
|
|
353
|
+
}
|
|
354
|
+
const target = () => current ?? preTest;
|
|
355
|
+
const since = () => Math.round(performance.now() - target().started);
|
|
356
|
+
function toAttempt(a, attrs, runnable) {
|
|
357
|
+
const err = attrs.err;
|
|
358
|
+
const retry = typeof attrs.currentRetry === "number" ? attrs.currentRetry : runnable?._currentRetry ?? attrs._currentRetry ?? 0;
|
|
359
|
+
return {
|
|
360
|
+
titlePath: runnable?.titlePath?.() ?? (typeof attrs.titlePath === "function" ? attrs.titlePath() : [String(attrs.title ?? "")]),
|
|
361
|
+
retry: Number(retry) || 0,
|
|
362
|
+
state: String(attrs.state ?? "unknown"),
|
|
363
|
+
wallClockStartedAt: isoDate(attrs.wallClockStartedAt),
|
|
364
|
+
durationMs: typeof attrs.duration === "number" ? attrs.duration : void 0,
|
|
365
|
+
timings: convertTimings(attrs.timings, hookTitles),
|
|
366
|
+
error: err ? { name: err.name, message: clip(err.message, 2e4), stack: clip(err.stack, 2e4) } : void 0,
|
|
367
|
+
steps: a.steps.slice(0, MAX_STEPS),
|
|
368
|
+
requests: a.requests.slice(0, MAX_REQUESTS),
|
|
369
|
+
console: a.console.slice(0, MAX_CONSOLE)
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
const runner = Cypress.mocha.getRunner();
|
|
373
|
+
runner.on("hook", (hook) => {
|
|
374
|
+
const title = hookTitle(hook);
|
|
375
|
+
inEipHook = EIP_HOOKS.has(title);
|
|
376
|
+
if (hook.hookId) hookTitles.set(hook.hookId, title);
|
|
377
|
+
});
|
|
378
|
+
runner.on("hook end", () => {
|
|
379
|
+
inEipHook = false;
|
|
380
|
+
});
|
|
381
|
+
runner.on("test", () => {
|
|
382
|
+
const carried = preTest;
|
|
383
|
+
current = fresh();
|
|
384
|
+
current.steps.push(...carried.steps.map((s) => ({ ...s, t: 0 })));
|
|
385
|
+
preTest = fresh();
|
|
386
|
+
});
|
|
387
|
+
Cypress.on("test:after:run", (attrs, runnable) => {
|
|
388
|
+
attempts.push(toAttempt(current ?? fresh(), attrs, runnable));
|
|
389
|
+
current = void 0;
|
|
390
|
+
});
|
|
391
|
+
const isProxyLog = (attrs) => attrs.name === "request" && attrs.event === true;
|
|
392
|
+
const masked = /* @__PURE__ */ new Set();
|
|
393
|
+
Cypress.on("log:added", (attrs, log) => {
|
|
394
|
+
if (inEipHook || attrs.instrument !== "command" || isProxyLog(attrs)) return;
|
|
395
|
+
const secretInput = attrs.name === "type" && isSecretInput(safeGet(log, "$el"));
|
|
396
|
+
if (secretInput && attrs.id) masked.add(String(attrs.id));
|
|
397
|
+
const step = {
|
|
398
|
+
t: since(),
|
|
399
|
+
name: String(attrs.name ?? ""),
|
|
400
|
+
message: secretInput ? REDACTED : clip(plain(attrs.message), MAX_STEP_MESSAGE),
|
|
401
|
+
state: attrs.state ? String(attrs.state) : void 0,
|
|
402
|
+
kind: attrs.type ? String(attrs.type) : void 0
|
|
403
|
+
};
|
|
404
|
+
const a = target();
|
|
405
|
+
if (a.steps.length < MAX_STEPS) {
|
|
406
|
+
a.steps.push(step);
|
|
407
|
+
if (attrs.id) a.stepById.set(String(attrs.id), step);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
Cypress.on("log:changed", (attrs) => {
|
|
411
|
+
if (inEipHook || attrs.instrument !== "command" || isProxyLog(attrs)) return;
|
|
412
|
+
const a = target();
|
|
413
|
+
const step = attrs.id ? a.stepById.get(String(attrs.id)) : void 0;
|
|
414
|
+
if (!step) return;
|
|
415
|
+
if (attrs.state) step.state = String(attrs.state);
|
|
416
|
+
if (attrs.state === "passed" || attrs.state === "failed") {
|
|
417
|
+
step.duration_ms = Math.max(0, since() - step.t);
|
|
418
|
+
if (!masked.has(String(attrs.id))) step.message = clip(plain(attrs.message), MAX_STEP_MESSAGE) || step.message;
|
|
419
|
+
}
|
|
420
|
+
if (attrs.name === "request" && (attrs.state === "passed" || attrs.state === "failed") && step.net_ref === void 0) {
|
|
421
|
+
const recorded = fromCyRequest(attrs.consoleProps, step.t, step.duration_ms, budget);
|
|
422
|
+
if (recorded && a.requests.length < MAX_REQUESTS) {
|
|
423
|
+
recorded.id = ++requestSeq;
|
|
424
|
+
a.requests.push(recorded);
|
|
425
|
+
step.net_ref = a.requests.length - 1;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
Cypress.on("window:before:load", (win) => {
|
|
430
|
+
for (const level of ["log", "info", "warn", "error", "debug"]) {
|
|
431
|
+
const original = win.console[level];
|
|
432
|
+
win.console[level] = (...args) => {
|
|
433
|
+
const a = target();
|
|
434
|
+
if (a.console.length < MAX_CONSOLE) {
|
|
435
|
+
a.console.push({ t: since(), level, message: clip(args.map(formatArg).join(" "), MAX_TEXT) ?? "" });
|
|
436
|
+
}
|
|
437
|
+
return original.apply(win.console, args);
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
Cypress.on("uncaught:exception", (err) => {
|
|
442
|
+
const a = target();
|
|
443
|
+
if (a.console.length < MAX_CONSOLE) {
|
|
444
|
+
a.console.push({ t: since(), level: "error", message: clip(`Uncaught ${err.name}: ${err.message}`, MAX_TEXT) ?? "" });
|
|
445
|
+
}
|
|
446
|
+
return void 0;
|
|
447
|
+
});
|
|
448
|
+
beforeEach(function eipCapture() {
|
|
449
|
+
cy.intercept({ resourceType: /^(xhr|fetch)$/ }, (req) => {
|
|
450
|
+
const accept = String(req.headers.accept ?? "");
|
|
451
|
+
if (accept.includes("text/event-stream") || exclude && exclude.test(req.url)) return;
|
|
452
|
+
const started = performance.now();
|
|
453
|
+
const t = since();
|
|
454
|
+
const request = { headers: { ...req.headers }, ...bodyOf(req.body, budget) };
|
|
455
|
+
req.on("after:response", (res) => {
|
|
456
|
+
const a = target();
|
|
457
|
+
if (a.requests.length >= MAX_REQUESTS) return;
|
|
458
|
+
const entry = {
|
|
459
|
+
id: ++requestSeq,
|
|
460
|
+
t,
|
|
461
|
+
source: "app",
|
|
462
|
+
method: req.method,
|
|
463
|
+
url: req.url,
|
|
464
|
+
status: res.statusCode,
|
|
465
|
+
duration_ms: Math.round(performance.now() - started),
|
|
466
|
+
request,
|
|
467
|
+
response: { headers: { ...res.headers }, ...bodyOf(res.body, budget) }
|
|
468
|
+
};
|
|
469
|
+
a.requests.push(entry);
|
|
470
|
+
if (a.steps.length < MAX_STEPS) {
|
|
471
|
+
a.steps.push({
|
|
472
|
+
t,
|
|
473
|
+
name: req.resourceType === "fetch" ? "fetch" : "xhr",
|
|
474
|
+
message: `${req.method} ${pathOf(req.url)} ${res.statusCode}`,
|
|
475
|
+
state: res.statusCode >= 400 ? "failed" : "passed",
|
|
476
|
+
duration_ms: entry.duration_ms,
|
|
477
|
+
net_ref: a.requests.length - 1
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
after(function eipFlush() {
|
|
484
|
+
const batch = attempts.splice(0);
|
|
485
|
+
const last = this.currentTest;
|
|
486
|
+
if (current && last) {
|
|
487
|
+
batch.push(toAttempt(current, last));
|
|
488
|
+
current = void 0;
|
|
489
|
+
}
|
|
490
|
+
for (const chunk of chunks(batch, TASK_CHUNK_CHARS)) {
|
|
491
|
+
cy.task("eip:events", { attempts: chunk }, { log: false, timeout: TASK_TIMEOUT_MS });
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
function chunks(attempts, max) {
|
|
496
|
+
const out = [];
|
|
497
|
+
let group = [];
|
|
498
|
+
let size = 0;
|
|
499
|
+
for (const a of attempts) {
|
|
500
|
+
let n;
|
|
501
|
+
try {
|
|
502
|
+
n = JSON.stringify(a).length;
|
|
503
|
+
} catch {
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
if (group.length && size + n > max) {
|
|
507
|
+
out.push(group);
|
|
508
|
+
group = [];
|
|
509
|
+
size = 0;
|
|
510
|
+
}
|
|
511
|
+
group.push(a);
|
|
512
|
+
size += n;
|
|
513
|
+
}
|
|
514
|
+
if (group.length) out.push(group);
|
|
515
|
+
return out;
|
|
516
|
+
}
|
|
517
|
+
function safeGet(log, key) {
|
|
518
|
+
try {
|
|
519
|
+
return log?.get?.(key);
|
|
520
|
+
} catch {
|
|
521
|
+
return void 0;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function isSecretInput($el) {
|
|
525
|
+
const el = $el?.[0] ?? $el;
|
|
526
|
+
if (!el || typeof el !== "object") return false;
|
|
527
|
+
const input = el;
|
|
528
|
+
if (String(input.type ?? "").toLowerCase() === "password") return true;
|
|
529
|
+
const names = [input.name, input.id, input.autocomplete].filter((v) => typeof v === "string" && v !== "");
|
|
530
|
+
const pass = new Redaction();
|
|
531
|
+
return names.some((n) => pass.isSecretField(n) || /^(current|new)-password$|^one-time-code$/.test(n));
|
|
532
|
+
}
|
|
533
|
+
function convertTimings(raw, titles) {
|
|
534
|
+
if (!raw) return void 0;
|
|
535
|
+
const hooks = (key) => {
|
|
536
|
+
const list = raw[key];
|
|
537
|
+
if (!Array.isArray(list)) return void 0;
|
|
538
|
+
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));
|
|
539
|
+
return out.length ? out : void 0;
|
|
540
|
+
};
|
|
541
|
+
const body = raw.test;
|
|
542
|
+
return {
|
|
543
|
+
before_all: hooks("before all"),
|
|
544
|
+
before_each: hooks("before each"),
|
|
545
|
+
body: body ? (body.fnDuration ?? 0) + (body.afterFnDuration ?? 0) : void 0,
|
|
546
|
+
after_each: hooks("after each"),
|
|
547
|
+
after_all: hooks("after all")
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function hookTitle(hook) {
|
|
551
|
+
const m = /hook: (.+)$/.exec(hook.title ?? "");
|
|
552
|
+
return m?.[1] ?? hook.hookName ?? hook.title ?? "";
|
|
553
|
+
}
|
|
554
|
+
function fromCyRequest(consoleProps, t, duration, budget) {
|
|
555
|
+
const props = consoleProps?.props ?? consoleProps;
|
|
556
|
+
const req = props?.Request ?? props?.["Requests"];
|
|
557
|
+
const r = Array.isArray(req) ? req[req.length - 1] : req;
|
|
558
|
+
if (!r) return void 0;
|
|
559
|
+
const url = String(r["Request URL"] ?? "");
|
|
560
|
+
const status = Number(r["Response Status"]);
|
|
561
|
+
return {
|
|
562
|
+
id: 0,
|
|
563
|
+
t,
|
|
564
|
+
source: "cy.request",
|
|
565
|
+
method: String(r["Request Method"] ?? methodGuess(props)),
|
|
566
|
+
url,
|
|
567
|
+
status: Number.isFinite(status) ? status : void 0,
|
|
568
|
+
duration_ms: duration,
|
|
569
|
+
request: { headers: r["Request Headers"] ?? {}, ...bodyOf(r["Request Body"], budget) },
|
|
570
|
+
response: { headers: r["Response Headers"] ?? {}, ...bodyOf(r["Response Body"], budget) }
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
function methodGuess(props) {
|
|
574
|
+
const yielded = props?.Yielded;
|
|
575
|
+
return yielded?.allRequestResponses?.[0]?.["Request Method"] ?? "GET";
|
|
576
|
+
}
|
|
577
|
+
function bodyOf(body, budget) {
|
|
578
|
+
if (body === void 0 || body === null || body === "") return {};
|
|
579
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body) || typeof Blob !== "undefined" && body instanceof Blob) {
|
|
580
|
+
const size = body instanceof Blob ? body.size : body.byteLength;
|
|
581
|
+
return { body_omitted: "binary", size };
|
|
582
|
+
}
|
|
583
|
+
let text;
|
|
584
|
+
try {
|
|
585
|
+
text = typeof body === "string" ? body : JSON.stringify(body);
|
|
586
|
+
} catch {
|
|
587
|
+
return { body_omitted: "unreadable" };
|
|
588
|
+
}
|
|
589
|
+
if (text === void 0) return { body_omitted: "unreadable" };
|
|
590
|
+
if (text.length > MAX_BODY_CHARS) return { body_omitted: "too_large", size: text.length };
|
|
591
|
+
if (text.length > budget.left) return { body_omitted: "budget", size: text.length };
|
|
592
|
+
budget.left -= text.length;
|
|
593
|
+
return { body: typeof body === "string" ? body : JSON.parse(text) };
|
|
594
|
+
}
|
|
595
|
+
function formatArg(arg) {
|
|
596
|
+
if (typeof arg === "string") return arg;
|
|
597
|
+
if (arg instanceof Error) return `${arg.name}: ${arg.message}`;
|
|
598
|
+
try {
|
|
599
|
+
return JSON.stringify(arg);
|
|
600
|
+
} catch {
|
|
601
|
+
return String(arg);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function plain(message) {
|
|
605
|
+
return String(message ?? "").replace(/\*\*/g, "");
|
|
606
|
+
}
|
|
607
|
+
function pathOf(url) {
|
|
608
|
+
try {
|
|
609
|
+
const u = new URL(url);
|
|
610
|
+
return u.pathname + u.search;
|
|
611
|
+
} catch {
|
|
612
|
+
return url;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function isoDate(value) {
|
|
616
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
617
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
618
|
+
return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
619
|
+
}
|
|
620
|
+
function clip(text, max) {
|
|
621
|
+
if (text === void 0) return void 0;
|
|
622
|
+
return text.length > max ? text.slice(0, max) : text;
|
|
623
|
+
}
|
|
624
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
625
|
+
0 && (module.exports = {
|
|
626
|
+
MAX_BODY_CHARS,
|
|
627
|
+
SPEC_BODY_BUDGET,
|
|
628
|
+
TASK_CHUNK_CHARS,
|
|
629
|
+
bodyOf,
|
|
630
|
+
chunks,
|
|
631
|
+
installRerunFilter,
|
|
632
|
+
isSecretInput,
|
|
633
|
+
isoDate
|
|
634
|
+
});
|