|
3 | 3 | // ── Auth: inject API token via visit callback ─────────────────────────────── |
4 | 4 | // Overrides cy.visit to inject the token into localStorage before the app |
5 | 5 | // reads it. Token is read from CYPRESS_API_TOKEN env var. |
6 | | -Cypress.Commands.overwrite("visit", (originalFn, url, options) => { |
7 | | - const token = Cypress.env("API_TOKEN"); |
8 | | - if (!token) return originalFn(url, options); |
9 | | - |
10 | | - const opts = { ...options } as Cypress.VisitObject; |
11 | | - const originalOnBeforeLoad = opts.onBeforeLoad; |
12 | | - opts.onBeforeLoad = (win) => { |
13 | | - win.localStorage.setItem("sympozium_token", token); |
14 | | - win.localStorage.setItem("sympozium_namespace", "default"); |
15 | | - if (originalOnBeforeLoad) originalOnBeforeLoad(win); |
16 | | - }; |
17 | | - return originalFn(url, opts); |
18 | | -}); |
| 6 | +Cypress.Commands.overwrite( |
| 7 | + "visit", |
| 8 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 9 | + (originalFn: any, url: string | Partial<Cypress.VisitOptions>, options?: Partial<Cypress.VisitOptions>) => { |
| 10 | + const token = Cypress.env("API_TOKEN"); |
| 11 | + if (!token) return originalFn(url, options); |
| 12 | + |
| 13 | + const opts: Partial<Cypress.VisitOptions> = { ...options }; |
| 14 | + const originalOnBeforeLoad = opts.onBeforeLoad; |
| 15 | + opts.onBeforeLoad = (win: Cypress.AUTWindow) => { |
| 16 | + win.localStorage.setItem("sympozium_token", token); |
| 17 | + win.localStorage.setItem("sympozium_namespace", "default"); |
| 18 | + if (originalOnBeforeLoad) originalOnBeforeLoad(win); |
| 19 | + }; |
| 20 | + return originalFn(url, opts); |
| 21 | + }, |
| 22 | +); |
19 | 23 |
|
20 | 24 | // ── Custom commands ───────────────────────────────────────────────────────── |
21 | 25 | declare global { |
@@ -200,24 +204,24 @@ Cypress.Commands.add( |
200 | 204 | Cypress.Commands.add("waitForDeleted", (path: string, timeoutMs = 30000) => { |
201 | 205 | const started = Date.now(); |
202 | 206 | const poll = (): Cypress.Chainable<void> => { |
203 | | - return cy |
| 207 | + return (cy |
204 | 208 | .request({ |
205 | 209 | url: path, |
206 | 210 | headers: authHeaders(), |
207 | 211 | failOnStatusCode: false, |
208 | 212 | }) |
209 | | - .then((resp) => { |
| 213 | + .then((resp): void => { |
210 | 214 | if (resp.status === 404) { |
211 | | - return cy.wrap(undefined); |
| 215 | + return; |
212 | 216 | } |
213 | 217 | if (Date.now() - started > timeoutMs) { |
214 | 218 | throw new Error( |
215 | 219 | `waitForDeleted(${path}) timed out; last status=${resp.status}`, |
216 | 220 | ); |
217 | 221 | } |
218 | 222 | cy.wait(1000, { log: false }); |
219 | | - return poll(); |
220 | | - }); |
| 223 | + poll(); |
| 224 | + }) as unknown as Cypress.Chainable<void>); |
221 | 225 | }; |
222 | 226 | return poll(); |
223 | 227 | }); |
|
0 commit comments