diff --git a/packages/amplify-graphql-transformer-core/FixJestEnvironment.js b/packages/amplify-graphql-transformer-core/FixJestEnvironment.js new file mode 100644 index 0000000000..1e496d7bd4 --- /dev/null +++ b/packages/amplify-graphql-transformer-core/FixJestEnvironment.js @@ -0,0 +1,16 @@ +const NodeEnvironment = require('jest-environment-node'); + +class FixJestEnvironment extends NodeEnvironment { + constructor(...args) { + super(...args); + // https://github.com/jestjs/jest/issues/12628 + // sturcturedClone is missing in the jest node environment. + // Newer versions of jest have fixed this, but is not possible to upgrade at this time. + // Newer versions of jest have a performance issue when not used with Node ^20.11.0 + // https://github.com/jestjs/jest/issues/11956 + // Our minimum supported version is Node 18. + this.global.structuredClone = structuredClone; + } +} + +module.exports = FixJestEnvironment; diff --git a/packages/amplify-graphql-transformer-core/package.json b/packages/amplify-graphql-transformer-core/package.json index 203ecb79dc..44caebe40d 100644 --- a/packages/amplify-graphql-transformer-core/package.json +++ b/packages/amplify-graphql-transformer-core/package.json @@ -76,6 +76,7 @@ "coverageReporters": [ "clover", "text" - ] + ], + "testEnvironment": "./FixJestEnvironment.js" } }