diff --git a/patches/jest-environment-jsdom+29.7.0.patch b/patches/jest-environment-jsdom+29.7.0.patch new file mode 100644 index 00000000000..39b42ec75b6 --- /dev/null +++ b/patches/jest-environment-jsdom+29.7.0.patch @@ -0,0 +1,19 @@ +diff --git a/node_modules/jest-environment-jsdom/build/index.js b/node_modules/jest-environment-jsdom/build/index.js +index 2e6c16c..ce5c77d 100644 +--- a/node_modules/jest-environment-jsdom/build/index.js ++++ b/node_modules/jest-environment-jsdom/build/index.js +@@ -96,6 +96,14 @@ class JSDOMEnvironment { + // TODO: remove this ASAP, but it currently causes tests to run really slow + global.Buffer = Buffer; + ++ // Add mocks for schemaProxy tests that rely on `Response` and `fetch` ++ // being globally available ++ global.fetch = fetch; ++ global.Headers = Headers; ++ global.Request = Request; ++ global.Response = Response; ++ global.AbortController = AbortController; ++ + // Report uncaught errors. + this.errorEventListener = event => { + if (userErrorListenerCount === 0 && event.error != null) { diff --git a/src/testing/core/__tests__/schemaProxy.test.tsx b/src/testing/core/__tests__/schemaProxy.test.tsx index 3dd09999e25..9e798d35d3a 100644 --- a/src/testing/core/__tests__/schemaProxy.test.tsx +++ b/src/testing/core/__tests__/schemaProxy.test.tsx @@ -788,6 +788,7 @@ describe("schema proxy", () => { const { ErrorBoundary } = createTrackedErrorComponents(Profiler); + // @ts-expect-error - we're intentionally passing an invalid schema using _fetch = createMockFetch(forkedSchema); const client = new ApolloClient({ diff --git a/src/testing/core/mockFetchWithSchema.ts b/src/testing/core/mockFetchWithSchema.ts index 386dbbafc0b..c0ddde0f26e 100644 --- a/src/testing/core/mockFetchWithSchema.ts +++ b/src/testing/core/mockFetchWithSchema.ts @@ -1,11 +1,10 @@ -import { Response as NodeFetchResponse } from "node-fetch"; import { execute, validate } from "graphql"; -import type { GraphQLError } from "graphql"; +import type { GraphQLError, GraphQLSchema } from "graphql"; import { ApolloError, gql } from "../../core/index.js"; import { withCleanup } from "../internal/index.js"; const createMockFetch = ( - schema: any, + schema: GraphQLSchema, mockFetchOpts: { validate: boolean } = { validate: true } ) => { const prevFetch = window.fetch; @@ -31,9 +30,7 @@ const createMockFetch = ( if (validationErrors?.length > 0) { return resolve( - new NodeFetchResponse( - JSON.stringify({ errors: validationErrors }) - ) as unknown as Response + new Response(JSON.stringify({ errors: validationErrors })) ); } } @@ -47,7 +44,7 @@ const createMockFetch = ( const stringifiedResult = JSON.stringify(result); - resolve(new NodeFetchResponse(stringifiedResult) as unknown as Response); + resolve(new Response(stringifiedResult)); }); };