Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom jsdom environment instead of patch package to set Response in the environemt #11751

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
phryneas marked this conversation as resolved.
Show resolved Hide resolved
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.