Skip to content

Commit

Permalink
fix: set up globalThis for jest tests if not defined
Browse files Browse the repository at this point in the history
Issue on Jest jsdom/jsdom#2961
globalThis in Node.js nodejs/node#22835
  • Loading branch information
trivikr committed Jan 4, 2022
1 parent 9abf92f commit db212a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ module.exports = {
],
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/clients/client-.*"],
coveragePathIgnorePatterns: ["/node_modules/", "<rootDir>/clients/client-.*", "/__fixtures__/"],
setupFiles: ["<rootDir>/scripts/jest/setupGlobalThis.js"],
};
11 changes: 11 additions & 0 deletions scripts/jest/setupGlobalThis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Remove this hack once `globalThis` issue is resolved or we drop testing Node.js 10.x
// Issue on Jest https://github.com/jsdom/jsdom/issues/2961
// PR which added globalThis in Node.js https://github.com/nodejs/node/pull/22835
if (!global.globalThis) {
Object.defineProperty(global, "globalThis", {
value: global,
writable: true,
enumerable: false,
configurable: true,
});
}

0 comments on commit db212a4

Please sign in to comment.