@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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — unreleased
|
|
4
|
+
|
|
5
|
+
- First version: run numbers, spec results with attempts and hook timings, steps, app requests,
|
|
6
|
+
`cy.request` calls and console output (cleaned of secrets and personal data before upload), videos and
|
|
7
|
+
screenshots by the company's storage settings, GitHub Actions context, re-run of failed and skipped tests
|
|
8
|
+
(`EIP_RERUN_OF`), `eip-cypress run` command.
|
|
9
|
+
- Step messages, errors and the commit message are cleaned too; URLs, `"key": "value"` pairs, URL fragments and
|
|
10
|
+
user info, URL-valued and list-valued headers are covered by the shared rules.
|
|
11
|
+
- Relative URLs such as `/login?token=…` in step messages are cleaned too; URLs in text end before trailing
|
|
12
|
+
punctuation.
|
|
13
|
+
- Timeouts on every EIP call, idempotent run opening (`client_run_id`), spec payloads kept under 8 MB, bodies over
|
|
14
|
+
256 KB left out, data handed to Node in chunks, the spec's last test keeps its steps.
|
|
15
|
+
- Re-run: POSIX spec paths, missing spec files left out, a warning for tests that were not found; chained `it()`
|
|
16
|
+
calls keep working.
|
|
17
|
+
- `eip-cypress run` starts the project's Cypress through Node (works on Windows).
|
|
18
|
+
- The email, JWT and relative-URL rules stay linear on long input: a match can't start inside a run of the
|
|
19
|
+
characters it consumes. A relative URL now starts only after whitespace, a quote, a bracket, `=` or `,`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright (c) 2026 DVL Software GmbH. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software is the confidential and proprietary information of
|
|
4
|
+
DVL Software GmbH ("Confidential Information"). You may use it only
|
|
5
|
+
together with an active subscription to the DVL Engineering Insights
|
|
6
|
+
Platform (EIP) and only in accordance with the terms of the agreement
|
|
7
|
+
you entered into with DVL Software GmbH. Any other use, copying,
|
|
8
|
+
modification or distribution is not permitted.
|
package/README.md
CHANGED
|
@@ -1,3 +1,130 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dvl-software/eip-cypress
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Send your Cypress runs to **Test Management in the DVL Engineering Insights Platform (EIP)**: run numbers,
|
|
4
|
+
results grouped by spec file, hook and test timings, retries and flaky tests, video replay, screenshots,
|
|
5
|
+
the requests and console output of every step, statistics, and "re-run failed + skipped" from GitHub Actions.
|
|
6
|
+
|
|
7
|
+
Requires an EIP subscription with Test Management. Cypress 13 or newer, Node 18 or newer.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install --save-dev @dvl-software/eip-cypress
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`cypress.config.ts`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { defineConfig } from "cypress";
|
|
19
|
+
import { setupEip } from "@dvl-software/eip-cypress";
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
e2e: {
|
|
23
|
+
video: true, // videos of failed and flaky specs can be replayed in EIP
|
|
24
|
+
retries: { runMode: 1, openMode: 0 }, // a test that passes on retry is shown as flaky
|
|
25
|
+
setupNodeEvents(on, config) {
|
|
26
|
+
return setupEip(on, config);
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Your support file (e.g. `cypress/support/e2e.ts`):
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import "@dvl-software/eip-cypress/support";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Cypress keeps only one handler per event. If you have your own `before:run`, `after:spec` or `after:run`
|
|
39
|
+
handlers, pass them to the plugin instead of registering them yourself:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
return setupEip(on, config, { hooks: { afterSpec: (spec, results) => { /* yours */ } } });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Settings (environment variables)
|
|
46
|
+
|
|
47
|
+
| Variable | |
|
|
48
|
+
|---|---|
|
|
49
|
+
| `EIP_API_KEY` | API key with the **Test results** scope (create it in EIP). Without it the plugin does nothing. |
|
|
50
|
+
| `EIP_API_URL` | Your EIP API address, e.g. `https://api.example.eip`. Must be `https` (plain `http` only to `localhost`, or with `EIP_ALLOW_HTTP=1`), because the key travels with every call. |
|
|
51
|
+
| `EIP_PROJECT_ID` | The EIP project the runs belong to (shown on the setup page). |
|
|
52
|
+
| `EIP_RERUN_OF` | Run number to re-run: only that run's failed and skipped tests run. |
|
|
53
|
+
| `EIP_ENVIRONMENT` | Optional environment name, e.g. `staging`. |
|
|
54
|
+
| `EIP_RUN_NAME` | Optional run name (default "Cypress run on <branch>"). |
|
|
55
|
+
| `EIP_APP_URL` | Optional web address of EIP, to print a link to the run at the end. |
|
|
56
|
+
| `EIP_CAPTURE_EXCLUDE` | Optional regular expression: app requests whose URL matches are not recorded (e.g. streaming endpoints). |
|
|
57
|
+
| `EIP_ALLOW_HTTP` | `1` allows a plain-http `EIP_API_URL` that isn't `localhost`. |
|
|
58
|
+
| `EIP_DISABLED` | `true` turns the plugin off. |
|
|
59
|
+
|
|
60
|
+
The plugin never changes the outcome of your Cypress run: if EIP can't be reached, the run goes on and
|
|
61
|
+
the plugin prints one line about it. Every call has a timeout; after two calls in a row get no answer, the plugin
|
|
62
|
+
stops calling EIP for the rest of the run. Results are only recorded in `cypress run` (`cypress open` sends nothing).
|
|
63
|
+
|
|
64
|
+
## GitHub Actions
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
on:
|
|
68
|
+
push:
|
|
69
|
+
workflow_dispatch:
|
|
70
|
+
inputs:
|
|
71
|
+
rerun_of:
|
|
72
|
+
description: "Re-run of (run number)"
|
|
73
|
+
required: false
|
|
74
|
+
jobs:
|
|
75
|
+
e2e:
|
|
76
|
+
runs-on: ubuntu-latest
|
|
77
|
+
steps:
|
|
78
|
+
- uses: actions/checkout@v4
|
|
79
|
+
- run: npm ci
|
|
80
|
+
- run: npx eip-cypress run
|
|
81
|
+
env:
|
|
82
|
+
EIP_API_KEY: ${{ secrets.EIP_API_KEY }}
|
|
83
|
+
EIP_API_URL: https://api.example.eip
|
|
84
|
+
EIP_PROJECT_ID: <your project id>
|
|
85
|
+
EIP_RERUN_OF: ${{ inputs.rerun_of }}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`npx eip-cypress run [options]` runs `cypress run` with the same options and keeps its exit code. With
|
|
89
|
+
`EIP_RERUN_OF` it stops early when the earlier run had nothing to re-run. In EIP, "Re-run failed + skipped"
|
|
90
|
+
shows the run number to paste into the **Re-run of** field of this workflow.
|
|
91
|
+
|
|
92
|
+
A re-run finds tests by their title path. Spec files that no longer exist are left out (with none left, everything
|
|
93
|
+
runs), and the plugin prints how many tests of the earlier run it could not find — e.g. renamed tests or titles that
|
|
94
|
+
change between runs (`it(\`… ${Date.now()}\`)`).
|
|
95
|
+
|
|
96
|
+
## What is recorded
|
|
97
|
+
|
|
98
|
+
Per test attempt: before all / before each / test body / after each / after all timings, the commands
|
|
99
|
+
(steps), the app's XHR and fetch requests, `cy.request` calls, console output and uncaught errors.
|
|
100
|
+
Your EIP storage settings decide what is uploaded: by default videos and request logs only for failed and
|
|
101
|
+
flaky tests, screenshots only for failed tests. A request or response body over 256 KB, and bodies beyond 16 MB per
|
|
102
|
+
spec file, are left out (marked as too large). Server-sent event streams are not recorded. Steps of passed tests are
|
|
103
|
+
dropped first when a spec file's results get very large.
|
|
104
|
+
|
|
105
|
+
### Secrets and personal data
|
|
106
|
+
|
|
107
|
+
Before anything leaves the CI machine, the plugin removes from request logs, console output, step messages (e.g.
|
|
108
|
+
typed text, visited URLs), error messages and stacks, and the commit message:
|
|
109
|
+
|
|
110
|
+
- headers such as `Authorization`, `Cookie`, `Set-Cookie`, `X-API-Key` and any header whose name contains
|
|
111
|
+
token, secret, key, session or password;
|
|
112
|
+
- fields named like password, secret, token, api key, IBAN, card number, CVV, PIN, tax id (in JSON, forms
|
|
113
|
+
and query strings, any letter case);
|
|
114
|
+
- the same fields as `"name": "value"` pairs inside text, query strings and `k=v` URL fragments, and the user
|
|
115
|
+
info of URLs (`https://user:password@…`);
|
|
116
|
+
- relative URLs such as `/login?token=…` in step messages;
|
|
117
|
+
- values that look like JWTs, bearer tokens, card numbers (checksum), IBANs (checksum), email addresses and
|
|
118
|
+
international phone numbers.
|
|
119
|
+
|
|
120
|
+
The commit author's name is sent as it is (EIP shows it next to the run).
|
|
121
|
+
|
|
122
|
+
You can add your own field names and patterns in EIP's storage settings (patterns use the syntax both
|
|
123
|
+
JavaScript and Java understand: no inline flags like `(?i)`, atomic groups or possessive quantifiers — EIP refuses
|
|
124
|
+
those). EIP runs the same rules again when
|
|
125
|
+
the log arrives. Names and street addresses can't be recognised by pattern: if your tests use real people's
|
|
126
|
+
data, add your own field names or switch request bodies off in the storage settings.
|
|
127
|
+
|
|
128
|
+
## Licence
|
|
129
|
+
|
|
130
|
+
Proprietary. Use only together with an EIP subscription. See `LICENSE`.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/redact.ts
|
|
6
|
+
var REDACTED = "[redacted]";
|
|
7
|
+
var EMAIL = "[email]";
|
|
8
|
+
var PHONE = "[phone]";
|
|
9
|
+
var SECRET_FIELDS = /* @__PURE__ */ new Set([
|
|
10
|
+
"password",
|
|
11
|
+
"passwd",
|
|
12
|
+
"pwd",
|
|
13
|
+
"secret",
|
|
14
|
+
"token",
|
|
15
|
+
"accesstoken",
|
|
16
|
+
"refreshtoken",
|
|
17
|
+
"idtoken",
|
|
18
|
+
"apikey",
|
|
19
|
+
"clientsecret",
|
|
20
|
+
"authorization",
|
|
21
|
+
"otp",
|
|
22
|
+
"pin",
|
|
23
|
+
"iban",
|
|
24
|
+
"cardnumber",
|
|
25
|
+
"creditcard",
|
|
26
|
+
"cvv",
|
|
27
|
+
"cvc",
|
|
28
|
+
"ssn",
|
|
29
|
+
"taxid",
|
|
30
|
+
"privatekey",
|
|
31
|
+
"sessionid",
|
|
32
|
+
"cookie",
|
|
33
|
+
"setcookie"
|
|
34
|
+
]);
|
|
35
|
+
var SECRET_FIELD_SUFFIXES = ["password", "secret", "token"];
|
|
36
|
+
var SECRET_HEADER_PARTS = ["auth", "cookie", "token", "secret", "key", "session", "password"];
|
|
37
|
+
var BEARER = /\bBearer\s+[A-Za-z0-9._~+/=-]+/gi;
|
|
38
|
+
var JWT = /(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g;
|
|
39
|
+
var EMAIL_PATTERN = /(?<![A-Za-z0-9._%+-])[A-Za-z0-9._%+-]{1,256}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,}/g;
|
|
40
|
+
var IBAN = /\b[A-Z]{2}\d{2}(?:\s?[A-Z0-9]{4}){2,7}(?:\s?[A-Z0-9]{1,3})?\b/g;
|
|
41
|
+
var CARD = /(?<!\d)\d(?:[ -]?\d){12,18}(?!\d)/g;
|
|
42
|
+
var PHONE_PATTERN = /\+\d{1,3}(?:[\s.-]?\(\d{1,4}\))?(?:[\s.-]?\d{2,8}){1,4}(?!\d)/g;
|
|
43
|
+
var FORM = /^[^=&\s]+=[^&]*(?:&[^=&\s]+=[^&]*)*$/;
|
|
44
|
+
var URL_IN_TEXT = /https?:\/\/[^\s"'<>]*[^\s"'<>.,;:!?)]|(?<![^\s"'`<>(\[{=,])\/[^\s"'`<>(\[{=,?#]{0,2048}[?#][^\s"'<>]*[^\s"'<>.,;:!?)]/g;
|
|
45
|
+
var JSON_PAIR = /"([^"\\]{1,100})"(\s*:\s*)"([^"\\]*(?:\\.[^"\\]*)*)"/g;
|
|
46
|
+
var USER_INFO = /^(https?:\/\/)[^/@\s]+@/;
|
|
47
|
+
var STARTS_WITH_URL = /^https?:\/\//;
|
|
48
|
+
var MAX_EXTRA_PATTERNS = 20;
|
|
49
|
+
var MAX_EXTRA_PATTERN_LENGTH = 200;
|
|
50
|
+
function normalize(name) {
|
|
51
|
+
return name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
52
|
+
}
|
|
53
|
+
function validIban(candidate) {
|
|
54
|
+
const iban = candidate.replace(/ /g, "");
|
|
55
|
+
if (iban.length < 15 || iban.length > 34) return false;
|
|
56
|
+
const rearranged = iban.slice(4) + iban.slice(0, 4);
|
|
57
|
+
let remainder = 0;
|
|
58
|
+
for (const c of rearranged) {
|
|
59
|
+
const digits = /[A-Z]/.test(c) ? String(c.charCodeAt(0) - 55) : c;
|
|
60
|
+
for (const d of digits) {
|
|
61
|
+
remainder = (remainder * 10 + Number(d)) % 97;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return remainder === 1;
|
|
65
|
+
}
|
|
66
|
+
function luhn(candidate) {
|
|
67
|
+
const digits = candidate.replace(/[ -]/g, "");
|
|
68
|
+
if (digits.length < 13 || digits.length > 19) return false;
|
|
69
|
+
let sum = 0;
|
|
70
|
+
let dbl = false;
|
|
71
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
72
|
+
let d = digits.charCodeAt(i) - 48;
|
|
73
|
+
if (dbl) {
|
|
74
|
+
d *= 2;
|
|
75
|
+
if (d > 9) d -= 9;
|
|
76
|
+
}
|
|
77
|
+
sum += d;
|
|
78
|
+
dbl = !dbl;
|
|
79
|
+
}
|
|
80
|
+
return sum % 10 === 0;
|
|
81
|
+
}
|
|
82
|
+
function phoneLength(candidate) {
|
|
83
|
+
const n = candidate.replace(/\D/g, "").length;
|
|
84
|
+
return n >= 8 && n <= 15;
|
|
85
|
+
}
|
|
86
|
+
function compile(patterns) {
|
|
87
|
+
const out = [];
|
|
88
|
+
for (const raw of patterns ?? []) {
|
|
89
|
+
if (!raw || raw.length > MAX_EXTRA_PATTERN_LENGTH || out.length >= MAX_EXTRA_PATTERNS) continue;
|
|
90
|
+
try {
|
|
91
|
+
out.push(new RegExp(raw, "g"));
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
var Redaction = class {
|
|
98
|
+
constructor(extraFields = [], extraPatterns = []) {
|
|
99
|
+
__publicField(this, "count", 0);
|
|
100
|
+
__publicField(this, "extraFields");
|
|
101
|
+
__publicField(this, "extraPatterns");
|
|
102
|
+
this.extraFields = new Set(extraFields.filter((f) => f && f.trim()).map(normalize));
|
|
103
|
+
this.extraPatterns = compile(extraPatterns);
|
|
104
|
+
}
|
|
105
|
+
isSecretField(name) {
|
|
106
|
+
const n = normalize(name);
|
|
107
|
+
return SECRET_FIELDS.has(n) || this.extraFields.has(n) || SECRET_FIELD_SUFFIXES.some((s) => n.endsWith(s));
|
|
108
|
+
}
|
|
109
|
+
headers(headers) {
|
|
110
|
+
if (!isObject(headers)) return headers;
|
|
111
|
+
const out = {};
|
|
112
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
113
|
+
const n = normalize(key);
|
|
114
|
+
const secret = SECRET_HEADER_PARTS.some((p) => n.includes(p)) || this.isSecretField(key);
|
|
115
|
+
if (secret && value !== null && value !== void 0) {
|
|
116
|
+
out[key] = REDACTED;
|
|
117
|
+
this.count++;
|
|
118
|
+
} else if (Array.isArray(value)) {
|
|
119
|
+
out[key] = value.map((item) => typeof item === "string" ? this.text(item) : item);
|
|
120
|
+
} else if (typeof value === "string") {
|
|
121
|
+
out[key] = STARTS_WITH_URL.test(value) ? this.url(value) : this.text(value);
|
|
122
|
+
} else {
|
|
123
|
+
out[key] = value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
body(body) {
|
|
129
|
+
if (Array.isArray(body)) return body.map((item) => this.body(item));
|
|
130
|
+
if (isObject(body)) {
|
|
131
|
+
const out = {};
|
|
132
|
+
for (const [key, value] of Object.entries(body)) {
|
|
133
|
+
if (this.isSecretField(key) && value !== null && value !== void 0) {
|
|
134
|
+
out[key] = REDACTED;
|
|
135
|
+
this.count++;
|
|
136
|
+
} else {
|
|
137
|
+
out[key] = this.body(value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
if (typeof body === "string") return this.stringBody(body);
|
|
143
|
+
return body;
|
|
144
|
+
}
|
|
145
|
+
stringBody(s) {
|
|
146
|
+
const trimmed = s.trim();
|
|
147
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
148
|
+
try {
|
|
149
|
+
return JSON.stringify(this.body(JSON.parse(trimmed)));
|
|
150
|
+
} catch {
|
|
151
|
+
return this.text(s);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (FORM.test(trimmed)) return this.pairs(trimmed);
|
|
155
|
+
return this.text(s);
|
|
156
|
+
}
|
|
157
|
+
pairs(query) {
|
|
158
|
+
return query.split("&").map((pair) => {
|
|
159
|
+
const eq = pair.indexOf("=");
|
|
160
|
+
if (eq < 0) return this.text(pair);
|
|
161
|
+
const key = pair.slice(0, eq);
|
|
162
|
+
const value = pair.slice(eq + 1);
|
|
163
|
+
if (this.isSecretField(decode(key)) && value !== "") {
|
|
164
|
+
this.count++;
|
|
165
|
+
return `${key}=${REDACTED}`;
|
|
166
|
+
}
|
|
167
|
+
const decoded = decode(value);
|
|
168
|
+
const cleaned = this.text(decoded);
|
|
169
|
+
return `${key}=${cleaned === decoded ? value : cleaned}`;
|
|
170
|
+
}).join("&");
|
|
171
|
+
}
|
|
172
|
+
/** User info, base through the value patterns, query and a `k=v` fragment through the pair rules. */
|
|
173
|
+
url(url) {
|
|
174
|
+
let u = url;
|
|
175
|
+
if (USER_INFO.test(u)) {
|
|
176
|
+
u = u.replace(USER_INFO, `$1${REDACTED}@`);
|
|
177
|
+
this.count++;
|
|
178
|
+
}
|
|
179
|
+
const hash = u.indexOf("#");
|
|
180
|
+
const beforeHash = hash < 0 ? u : u.slice(0, hash);
|
|
181
|
+
const fragment = hash < 0 ? void 0 : u.slice(hash + 1);
|
|
182
|
+
const q = beforeHash.indexOf("?");
|
|
183
|
+
let out = this.plain(q < 0 ? beforeHash : beforeHash.slice(0, q));
|
|
184
|
+
if (q >= 0) out += `?${this.pairs(beforeHash.slice(q + 1))}`;
|
|
185
|
+
if (fragment !== void 0) out += `#${fragment.includes("=") ? this.pairs(fragment) : this.plain(fragment)}`;
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
/** URLs in the text (through {@link url}), then `"secret": "…"` pairs, then the value patterns. */
|
|
189
|
+
text(text) {
|
|
190
|
+
if (!text) return text;
|
|
191
|
+
let out = text.replace(URL_IN_TEXT, (match) => this.url(match));
|
|
192
|
+
out = out.replace(JSON_PAIR, (match, key, sep) => {
|
|
193
|
+
if (!this.isSecretField(key)) return match;
|
|
194
|
+
this.count++;
|
|
195
|
+
return `"${key}"${sep}"${REDACTED}"`;
|
|
196
|
+
});
|
|
197
|
+
return this.plain(out);
|
|
198
|
+
}
|
|
199
|
+
/** The value patterns only: bearer, JWT, email, IBAN, card, phone, own patterns. */
|
|
200
|
+
plain(text) {
|
|
201
|
+
if (!text) return text;
|
|
202
|
+
let out = this.replace(text, BEARER, () => `Bearer ${REDACTED}`);
|
|
203
|
+
out = this.replace(out, JWT, () => REDACTED);
|
|
204
|
+
out = this.replace(out, EMAIL_PATTERN, () => EMAIL);
|
|
205
|
+
out = this.replace(out, IBAN, () => REDACTED, validIban);
|
|
206
|
+
out = this.replace(out, CARD, () => REDACTED, luhn);
|
|
207
|
+
out = this.replace(out, PHONE_PATTERN, () => PHONE, phoneLength);
|
|
208
|
+
for (const extra of this.extraPatterns) {
|
|
209
|
+
out = this.replace(out, extra, () => REDACTED);
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
replace(text, pattern, by, check) {
|
|
214
|
+
pattern.lastIndex = 0;
|
|
215
|
+
return text.replace(pattern, (match) => {
|
|
216
|
+
if (!match || check && !check(match)) return match;
|
|
217
|
+
this.count++;
|
|
218
|
+
return by();
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
function decode(value) {
|
|
223
|
+
try {
|
|
224
|
+
return decodeURIComponent(value.replace(/\+/g, " "));
|
|
225
|
+
} catch {
|
|
226
|
+
return value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function isObject(v) {
|
|
230
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export {
|
|
234
|
+
__publicField,
|
|
235
|
+
REDACTED,
|
|
236
|
+
Redaction
|
|
237
|
+
};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import { readFileSync } from "fs";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
import { dirname, join } from "path";
|
|
8
|
+
|
|
9
|
+
// src/api.ts
|
|
10
|
+
var StorageFullError = class extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("EIP storage is full");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var ApiError = class extends Error {
|
|
16
|
+
constructor(status, message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.status = status;
|
|
19
|
+
}
|
|
20
|
+
status;
|
|
21
|
+
};
|
|
22
|
+
var UnreachableError = class extends Error {
|
|
23
|
+
constructor() {
|
|
24
|
+
super("EIP is not reachable (earlier calls timed out or failed), skipped");
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var RETRIES = 3;
|
|
28
|
+
var UNREACHABLE_AFTER = 2;
|
|
29
|
+
var DEFAULT_TIMEOUTS = { jsonMs: 3e4, uploadBaseMs: 6e4, uploadPerMbMs: 2e3 };
|
|
30
|
+
var EipApi = class {
|
|
31
|
+
constructor(baseUrl, apiKey, fetchImpl = fetch, timeouts = DEFAULT_TIMEOUTS, backoffMs = 500) {
|
|
32
|
+
this.baseUrl = baseUrl;
|
|
33
|
+
this.apiKey = apiKey;
|
|
34
|
+
this.fetchImpl = fetchImpl;
|
|
35
|
+
this.timeouts = timeouts;
|
|
36
|
+
this.backoffMs = backoffMs;
|
|
37
|
+
}
|
|
38
|
+
baseUrl;
|
|
39
|
+
apiKey;
|
|
40
|
+
fetchImpl;
|
|
41
|
+
timeouts;
|
|
42
|
+
backoffMs;
|
|
43
|
+
networkFailures = 0;
|
|
44
|
+
openRun(body) {
|
|
45
|
+
return this.json("POST", "/api/v1/auto-test-results/runs", body);
|
|
46
|
+
}
|
|
47
|
+
requestUpload(runId, body) {
|
|
48
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/uploads`, body);
|
|
49
|
+
}
|
|
50
|
+
postSpec(runId, body) {
|
|
51
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/specs`, body);
|
|
52
|
+
}
|
|
53
|
+
finish(runId, endedAt) {
|
|
54
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/finish`, { ended_at: endedAt });
|
|
55
|
+
}
|
|
56
|
+
rerunList(runNumber, projectId) {
|
|
57
|
+
const query = new URLSearchParams({ run_number: String(runNumber) });
|
|
58
|
+
if (projectId) query.set("project_id", projectId);
|
|
59
|
+
return this.json("GET", `/api/v1/auto-test-results/runs/rerun-list?${query}`);
|
|
60
|
+
}
|
|
61
|
+
/** PUT the file to the presigned URL (no API key: the URL carries its own signature). */
|
|
62
|
+
async upload(slot, content) {
|
|
63
|
+
const timeout = this.timeouts.uploadBaseMs + Math.ceil(content.byteLength / 1048576) * this.timeouts.uploadPerMbMs;
|
|
64
|
+
const res = await this.withRetry(
|
|
65
|
+
timeout,
|
|
66
|
+
(signal) => this.fetchImpl(slot.url, { method: slot.method || "PUT", headers: slot.headers, body: content, signal })
|
|
67
|
+
);
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
await discard(res);
|
|
70
|
+
throw new ApiError(res.status, `Upload failed with ${res.status}`);
|
|
71
|
+
}
|
|
72
|
+
await discard(res);
|
|
73
|
+
}
|
|
74
|
+
async json(method, path, body) {
|
|
75
|
+
const res = await this.withRetry(
|
|
76
|
+
this.timeouts.jsonMs,
|
|
77
|
+
(signal) => this.fetchImpl(this.baseUrl + path, {
|
|
78
|
+
method,
|
|
79
|
+
headers: { "X-API-Key": this.apiKey, "Content-Type": "application/json", Accept: "application/json" },
|
|
80
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
81
|
+
signal
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
if (res.status === 409) {
|
|
85
|
+
const text = await res.text().catch(() => "");
|
|
86
|
+
if (text.includes("STORAGE_FULL")) throw new StorageFullError();
|
|
87
|
+
throw new ApiError(res.status, messageOf(text) ?? "Conflict");
|
|
88
|
+
}
|
|
89
|
+
if (!res.ok) {
|
|
90
|
+
const text = await res.text().catch(() => "");
|
|
91
|
+
throw new ApiError(res.status, messageOf(text) ?? `EIP answered ${res.status}`);
|
|
92
|
+
}
|
|
93
|
+
return await res.json();
|
|
94
|
+
}
|
|
95
|
+
async withRetry(timeoutMs, call) {
|
|
96
|
+
if (this.networkFailures >= UNREACHABLE_AFTER) throw new UnreachableError();
|
|
97
|
+
let lastError;
|
|
98
|
+
for (let attempt = 0; attempt < RETRIES; attempt++) {
|
|
99
|
+
try {
|
|
100
|
+
const res = await call(AbortSignal.timeout(timeoutMs));
|
|
101
|
+
if (res.status < 500 || attempt === RETRIES - 1) {
|
|
102
|
+
this.networkFailures = 0;
|
|
103
|
+
return res;
|
|
104
|
+
}
|
|
105
|
+
await discard(res);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
lastError = isTimeout(e) ? new Error(`no answer within ${Math.round(timeoutMs / 1e3)} s`) : e;
|
|
108
|
+
}
|
|
109
|
+
if (attempt < RETRIES - 1) await new Promise((r) => setTimeout(r, this.backoffMs * 2 ** attempt));
|
|
110
|
+
}
|
|
111
|
+
this.networkFailures++;
|
|
112
|
+
throw lastError;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
async function discard(res) {
|
|
116
|
+
try {
|
|
117
|
+
await res.body?.cancel();
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function isTimeout(e) {
|
|
122
|
+
return e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError");
|
|
123
|
+
}
|
|
124
|
+
function messageOf(text) {
|
|
125
|
+
try {
|
|
126
|
+
const parsed = JSON.parse(text);
|
|
127
|
+
return typeof parsed?.message === "string" ? parsed.message : void 0;
|
|
128
|
+
} catch {
|
|
129
|
+
return void 0;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/context.ts
|
|
134
|
+
import { execFileSync } from "child_process";
|
|
135
|
+
var TRUE = ["1", "true", "yes"];
|
|
136
|
+
function readOptions(env = process.env) {
|
|
137
|
+
const rerun = env.EIP_RERUN_OF?.trim().replace(/^#/, "");
|
|
138
|
+
return {
|
|
139
|
+
apiKey: env.EIP_API_KEY?.trim() || void 0,
|
|
140
|
+
apiUrl: env.EIP_API_URL?.trim().replace(/\/+$/, "") || void 0,
|
|
141
|
+
projectId: env.EIP_PROJECT_ID?.trim() || void 0,
|
|
142
|
+
rerunOf: rerun && /^\d+$/.test(rerun) ? Number(rerun) : void 0,
|
|
143
|
+
environment: env.EIP_ENVIRONMENT?.trim() || void 0,
|
|
144
|
+
runName: env.EIP_RUN_NAME?.trim() || void 0,
|
|
145
|
+
captureExclude: env.EIP_CAPTURE_EXCLUDE?.trim() || void 0,
|
|
146
|
+
allowHttp: TRUE.includes((env.EIP_ALLOW_HTTP ?? "").toLowerCase()),
|
|
147
|
+
disabled: TRUE.includes((env.EIP_DISABLED ?? "").toLowerCase())
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function insecureApiUrl(apiUrl) {
|
|
151
|
+
try {
|
|
152
|
+
const u = new URL(apiUrl);
|
|
153
|
+
if (u.protocol === "https:") return false;
|
|
154
|
+
return !["localhost", "127.0.0.1", "[::1]", "::1"].includes(u.hostname);
|
|
155
|
+
} catch {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/cli.ts
|
|
161
|
+
function cypressCommand(cwd, platform = process.platform) {
|
|
162
|
+
try {
|
|
163
|
+
const require2 = createRequire(join(cwd, "package.json"));
|
|
164
|
+
const pkgPath = require2.resolve("cypress/package.json");
|
|
165
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
166
|
+
const bin = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.cypress;
|
|
167
|
+
if (bin) return { command: process.execPath, args: [join(dirname(pkgPath), bin)], shell: false };
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
170
|
+
return { command: "npx", args: ["cypress"], shell: platform === "win32" };
|
|
171
|
+
}
|
|
172
|
+
function shellQuote(arg) {
|
|
173
|
+
return /^[\w./:=@,+-]+$/.test(arg) ? arg : `"${arg.replace(/"/g, '\\"')}"`;
|
|
174
|
+
}
|
|
175
|
+
async function main(argv) {
|
|
176
|
+
const [command, ...rest] = argv;
|
|
177
|
+
if (command !== "run") {
|
|
178
|
+
console.log("Usage: eip-cypress run [cypress run options]\n\nEnvironment: EIP_API_KEY, EIP_API_URL, EIP_PROJECT_ID, EIP_RERUN_OF (run number to re-run), EIP_ENVIRONMENT, EIP_RUN_NAME, EIP_APP_URL, EIP_CAPTURE_EXCLUDE, EIP_ALLOW_HTTP, EIP_DISABLED");
|
|
179
|
+
return command === void 0 || command === "--help" || command === "-h" ? 0 : 1;
|
|
180
|
+
}
|
|
181
|
+
const opts = readOptions();
|
|
182
|
+
const usable = opts.apiKey && opts.apiUrl && !opts.disabled && (opts.allowHttp || !insecureApiUrl(opts.apiUrl));
|
|
183
|
+
if (opts.rerunOf !== void 0 && usable) {
|
|
184
|
+
try {
|
|
185
|
+
const list = await new EipApi(opts.apiUrl, opts.apiKey).rerunList(opts.rerunOf, opts.projectId);
|
|
186
|
+
if (list.specs.length === 0) {
|
|
187
|
+
console.log(`[EIP] Run #${opts.rerunOf} has no failed or skipped tests. Nothing to re-run.`);
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
} catch (e) {
|
|
191
|
+
console.log(`[EIP] Could not load run #${opts.rerunOf}: ${e instanceof Error ? e.message : e}. Running everything.`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const cy = cypressCommand(process.cwd());
|
|
195
|
+
const args = [...cy.args, "run", ...rest];
|
|
196
|
+
return new Promise((resolve) => {
|
|
197
|
+
let child;
|
|
198
|
+
try {
|
|
199
|
+
child = spawn(cy.command, cy.shell ? args.map(shellQuote) : args, { stdio: "inherit", env: process.env, shell: cy.shell });
|
|
200
|
+
} catch (e) {
|
|
201
|
+
console.error(`[EIP] Could not start Cypress: ${e instanceof Error ? e.message : e}`);
|
|
202
|
+
resolve(1);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const forward = (signal) => () => child.kill(signal);
|
|
206
|
+
const onInt = forward("SIGINT");
|
|
207
|
+
const onTerm = forward("SIGTERM");
|
|
208
|
+
process.on("SIGINT", onInt);
|
|
209
|
+
process.on("SIGTERM", onTerm);
|
|
210
|
+
child.on("exit", (code, signal) => {
|
|
211
|
+
process.off("SIGINT", onInt);
|
|
212
|
+
process.off("SIGTERM", onTerm);
|
|
213
|
+
resolve(signal ? 1 : code ?? 1);
|
|
214
|
+
});
|
|
215
|
+
child.on("error", (e) => {
|
|
216
|
+
console.error(`[EIP] Could not start Cypress: ${e.message}`);
|
|
217
|
+
resolve(1);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (!process.env.VITEST) {
|
|
222
|
+
main(process.argv.slice(2)).then((code) => process.exit(code));
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
cypressCommand
|
|
226
|
+
};
|