Skip to content

Commit

Permalink
Use custom jsdom environment instead of patch package to set Response…
Browse files Browse the repository at this point in the history
… in the environemt (#11751)

* fix: use custom jsdom env insted of patching it via patch package

* Clean up Prettier, Size-limit, and Api-Extractor

* use native `AbortController` (#11753)

---------

Co-authored-by: Lenz Weber-Tronic <lorenz.weber-tronic@apollographql.com>
Co-authored-by: phryneas <phryneas@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 4, 2024
1 parent 91546eb commit 4cbd229
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -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
}
21 changes: 21 additions & 0 deletions config/FixJSDOMEnvironment.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const defaults = {
rootDir: "src",
preset: "ts-jest",
testEnvironment: "jsdom",
testEnvironment: require.resolve("./FixJSDOMEnvironment.js"),
setupFilesAfterEnv: ["<rootDir>/config/jest/setup.ts"],
globals: {
__DEV__: true,
Expand Down
15 changes: 0 additions & 15 deletions patches/jest-environment-jsdom+29.7.0.patch

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
);
Expand Down

0 comments on commit 4cbd229

Please sign in to comment.