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 Oct 5, 2021
1 parent d5aaafd commit 64997cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ module.exports = {
],
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/clients/client-.*"],
coveragePathIgnorePatterns: ["/node_modules/", "<rootDir>/clients/client-.*", "/__fixtures__/"],
setupFiles: ["<rootDir>/scripts/jest/setupGlobalThis.js"],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build:all": "yarn build:crypto-dependencies && lerna run build",
"build-documentation": "yarn remove-documentation && typedoc",
"pretest:all": "yarn build:all",
"test:all": "jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}'",
"test:all": "node --expose-gc ./node_modules/.bin/jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}'",
"test:functional": "jest --config tests/functional/jest.config.js --passWithNoTests",
"test:integration-legacy": "cucumber-js --fail-fast",
"test:integration": "jest --config jest.config.integ.js --passWithNoTests",
Expand Down
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 64997cd

Please sign in to comment.