From f6b90a3c2b884096ddf7b2e210d4b2a532d874ab Mon Sep 17 00:00:00 2001 From: Matt Petro Date: Tue, 19 Jul 2022 17:18:18 -0400 Subject: [PATCH] Update graphql transform for Jest 28 The upstream project is unmaintained, so instead copying one tiny file into the project. --- jest.transform-graphql.js | 13 +++++++++++++ package.json | 3 +-- yarn.lock | 5 ----- 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 jest.transform-graphql.js diff --git a/jest.transform-graphql.js b/jest.transform-graphql.js new file mode 100644 index 00000000..11489ebd --- /dev/null +++ b/jest.transform-graphql.js @@ -0,0 +1,13 @@ +// Copied from https://github.com/remind101/jest-transform-graphql +// and updated for Jest 28 compatibility +const loader = require('graphql-tag/loader'); + +module.exports = { + process(src) { + // call directly the webpack loader with a mocked context + // as graphql-tag/loader leverages `this.cacheable()` + return { + code: loader.call({ cacheable() {} }, src) + }; + }, +}; diff --git a/package.json b/package.json index 54eb30f5..ef54c395 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "/client" ], "transform": { - "\\.(gql|graphql)$": "jest-transform-graphql", + "\\.(gql|graphql)$": "./jest.transform-graphql", "^.+\\.jsx?$": "babel-jest" }, "moduleNameMapper": { @@ -118,7 +118,6 @@ "eventsource-polyfill": "^0.9.6", "jest": "^28.1.0", "jest-environment-jsdom": "^28.1.0", - "jest-transform-graphql": "^2.1.0", "react-test-renderer": "^17.0.2", "redux-mock-store": "^1.5.4", "wait-for-expect": "^3.0.2", diff --git a/yarn.lock b/yarn.lock index 61fb5406..878bab7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7154,11 +7154,6 @@ jest-snapshot@^28.1.0: pretty-format "^28.1.0" semver "^7.3.5" -jest-transform-graphql@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/jest-transform-graphql/-/jest-transform-graphql-2.1.0.tgz#903cb66bb27bc2772fd3e5dd4f7e9b57230f5829" - integrity sha1-kDy2a7J7wncv0+XdT36bVyMPWCk= - jest-util@^28.1.0: version "28.1.0" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-28.1.0.tgz#d54eb83ad77e1dd441408738c5a5043642823be5"