diff --git a/.size-limits.json b/.size-limits.json index b45c4888c89..7f569cdcf1f 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39573, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32845 + "dist/apollo-client.min.cjs": 39510, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32799 } diff --git a/config/FixJSDOMEnvironment.js b/config/FixJSDOMEnvironment.js new file mode 100644 index 00000000000..dbbf9d3356f --- /dev/null +++ b/config/FixJSDOMEnvironment.js @@ -0,0 +1,21 @@ +const { default: JSDOMEnvironment } = require("jest-environment-jsdom"); + +// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string +class FixJSDOMEnvironment extends JSDOMEnvironment { + constructor(...args) { + super(...args); + + // FIXME https://github.com/jsdom/jsdom/issues/1724 + this.global.Headers = Headers; + this.global.Request = Request; + this.global.Response = Response; + + // FIXME: setting a global fetch breaks HttpLink tests + // and setting AbortController breaks PersistedQueryLink tests, which may + // indicate a memory leak + // this.global.fetch = fetch; + this.global.AbortController = AbortController; + } +} + +module.exports = FixJSDOMEnvironment; diff --git a/config/jest.config.js b/config/jest.config.js index 4c045e3fde8..0375a1a071a 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -1,7 +1,7 @@ const defaults = { rootDir: "src", preset: "ts-jest", - testEnvironment: "jsdom", + testEnvironment: require.resolve("./FixJSDOMEnvironment.js"), setupFilesAfterEnv: ["/config/jest/setup.ts"], globals: { __DEV__: true, diff --git a/patches/jest-environment-jsdom+29.7.0.patch b/patches/jest-environment-jsdom+29.7.0.patch deleted file mode 100644 index 4f97921d495..00000000000 --- a/patches/jest-environment-jsdom+29.7.0.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/node_modules/jest-environment-jsdom/build/index.js b/node_modules/jest-environment-jsdom/build/index.js -index 2e6c16c..174e7a0 100644 ---- a/node_modules/jest-environment-jsdom/build/index.js -+++ b/node_modules/jest-environment-jsdom/build/index.js -@@ -96,6 +96,10 @@ 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.Response = Response; -+ - // Report uncaught errors. - this.errorEventListener = event => { - if (userErrorListenerCount === 0 && event.error != null) { diff --git a/src/link/persisted-queries/__tests__/persisted-queries.test.ts b/src/link/persisted-queries/__tests__/persisted-queries.test.ts index 32d75fe5136..e970af26d6f 100644 --- a/src/link/persisted-queries/__tests__/persisted-queries.test.ts +++ b/src/link/persisted-queries/__tests__/persisted-queries.test.ts @@ -573,7 +573,11 @@ describe("failure path", () => { variables, }).subscribe({ complete }) ); - + // fetch-mock holds a history of all options it has been called with + // that includes the `signal` option, which (with the native `AbortController`) + // has a reference to the `Request` instance, which will somehow reference our + // hash object + fetchMock.resetHistory(); await expect(hashRefs[0]).toBeGarbageCollected(); } );