Skip to content

Commit 4cbd229

Browse files
alessbellphryneas
andauthored
Use custom jsdom environment instead of patch package to set Response 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 <[email protected]> Co-authored-by: phryneas <[email protected]>
1 parent 91546eb commit 4cbd229

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

.size-limits.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"dist/apollo-client.min.cjs": 39573,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32845
2+
"dist/apollo-client.min.cjs": 39510,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32799
44
}

config/FixJSDOMEnvironment.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { default: JSDOMEnvironment } = require("jest-environment-jsdom");
2+
3+
// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
4+
class FixJSDOMEnvironment extends JSDOMEnvironment {
5+
constructor(...args) {
6+
super(...args);
7+
8+
// FIXME https://github.com/jsdom/jsdom/issues/1724
9+
this.global.Headers = Headers;
10+
this.global.Request = Request;
11+
this.global.Response = Response;
12+
13+
// FIXME: setting a global fetch breaks HttpLink tests
14+
// and setting AbortController breaks PersistedQueryLink tests, which may
15+
// indicate a memory leak
16+
// this.global.fetch = fetch;
17+
this.global.AbortController = AbortController;
18+
}
19+
}
20+
21+
module.exports = FixJSDOMEnvironment;

config/jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const defaults = {
22
rootDir: "src",
33
preset: "ts-jest",
4-
testEnvironment: "jsdom",
4+
testEnvironment: require.resolve("./FixJSDOMEnvironment.js"),
55
setupFilesAfterEnv: ["<rootDir>/config/jest/setup.ts"],
66
globals: {
77
__DEV__: true,

patches/jest-environment-jsdom+29.7.0.patch

-15
This file was deleted.

src/link/persisted-queries/__tests__/persisted-queries.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,11 @@ describe("failure path", () => {
573573
variables,
574574
}).subscribe({ complete })
575575
);
576-
576+
// fetch-mock holds a history of all options it has been called with
577+
// that includes the `signal` option, which (with the native `AbortController`)
578+
// has a reference to the `Request` instance, which will somehow reference our
579+
// hash object
580+
fetchMock.resetHistory();
577581
await expect(hashRefs[0]).toBeGarbageCollected();
578582
}
579583
);

0 commit comments

Comments
 (0)