Skip to content

Commit d4495a0

Browse files
committed
fix(shared): polyfill test environment with Node globals for stability
Configures Jest to use a custom test environment that patches the JSDOM global scope with `fetch`, `Request`, and `Response` from Node.js. Since Node.js v18+ provides these fetch-related APIs as stable globals, we can reliably polyfill the test environment to ensure they are always available
1 parent 746dd97 commit d4495a0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import JSDOMEnvironment from 'jest-environment-jsdom';
2+
3+
export default class CustomJSDOMEnvironment extends JSDOMEnvironment {
4+
constructor(...args: ConstructorParameters<typeof JSDOMEnvironment>) {
5+
super(...args);
6+
7+
this.global.Response = Response;
8+
}
9+
}

packages/shared/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = {
66
displayName: name.replace('@clerk', ''),
77
injectGlobals: true,
88

9-
testEnvironment: 'jsdom',
9+
testEnvironment: './customJSDOMEnvironment.ts',
1010
roots: ['<rootDir>/src'],
1111
setupFiles: ['./jest.setup.ts'],
1212

0 commit comments

Comments
 (0)