Skip to content

Commit ba31304

Browse files
cursoragentjrhoads
andcommitted
fix(cypress): use Node global instead of globalThis in fetch mock
ESLint treats globalThis as undefined in this CommonJS file; use global for fetch binding and assignment. Co-authored-by: Joseph Rhoads <jrhoads@users.noreply.github.com>
1 parent e72a72e commit ba31304

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cypressFetchMock.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Node-only fetch mock for Cypress when `CYPRESS_NODE_ENV=test`.
33
*
4-
* Wraps `globalThis.fetch` so Next.js server-side requests during e2e runs are
4+
* Wraps `global.fetch` so Next.js server-side requests during e2e runs are
55
* served from `cypress/fixtures/` instead of live staging APIs. Unmatched
66
* requests delegate to the original `fetch`.
77
*
@@ -229,16 +229,16 @@ async function tryMockResponse(input, init) {
229229
}
230230

231231
/**
232-
* Patches `globalThis.fetch` for the lifetime of the Node process (dev server).
232+
* Patches `global.fetch` for the lifetime of the Node process (dev server).
233233
* Idempotent enough for instrumentation: repeated calls would stack wrappers, so
234234
* only invoke once from `instrumentation.js`.
235235
*/
236236
module.exports = function setupCypressFetchMock() {
237-
if (typeof globalThis.fetch !== 'function') return
237+
if (typeof global.fetch !== 'function') return
238238

239-
const originalFetch = globalThis.fetch.bind(globalThis)
239+
const originalFetch = global.fetch.bind(global)
240240

241-
globalThis.fetch = async (input, init) => {
241+
global.fetch = async (input, init) => {
242242
const mocked = await tryMockResponse(input, init)
243243
if (mocked) return mocked
244244
return originalFetch(input, init)

0 commit comments

Comments
 (0)