Skip to content

Commit 64997cd

Browse files
committed
fix: set up globalThis for jest tests if not defined
Issue on Jest jsdom/jsdom#2961 globalThis in Node.js nodejs/node#22835
1 parent d5aaafd commit 64997cd

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ module.exports = {
1010
],
1111
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/clients/client-.*"],
1212
coveragePathIgnorePatterns: ["/node_modules/", "<rootDir>/clients/client-.*", "/__fixtures__/"],
13+
setupFiles: ["<rootDir>/scripts/jest/setupGlobalThis.js"],
1314
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"build:all": "yarn build:crypto-dependencies && lerna run build",
2020
"build-documentation": "yarn remove-documentation && typedoc",
2121
"pretest:all": "yarn build:all",
22-
"test:all": "jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}'",
22+
"test:all": "node --expose-gc ./node_modules/.bin/jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}'",
2323
"test:functional": "jest --config tests/functional/jest.config.js --passWithNoTests",
2424
"test:integration-legacy": "cucumber-js --fail-fast",
2525
"test:integration": "jest --config jest.config.integ.js --passWithNoTests",

scripts/jest/setupGlobalThis.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Remove this hack once `globalThis` issue is resolved or we drop testing Node.js 10.x
2+
// Issue on Jest https://github.com/jsdom/jsdom/issues/2961
3+
// PR which added globalThis in Node.js https://github.com/nodejs/node/pull/22835
4+
if (!global.globalThis) {
5+
Object.defineProperty(global, "globalThis", {
6+
value: global,
7+
writable: true,
8+
enumerable: false,
9+
configurable: true,
10+
});
11+
}

0 commit comments

Comments
 (0)