Skip to content

Commit 787bda6

Browse files
committed
fix(test): polyfill web streams for undici v6 compatibility in jsdom
jest-environment-jsdom strips ReadableStream from globals, but undici v6 requires it at module load time. Add a shared polyfill that runs via setupFiles before @inrupt/jest-jsdom-polyfills imports undici.
1 parent 1ac710f commit 787bda6

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

test/api/jest.api.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const customJestConfig = {
1111
displayName: 'api',
1212
rootDir: '../../',
1313
// Add more setup options before each test is run
14+
setupFiles: ['<rootDir>/test/jest.polyfills.js'],
1415
setupFilesAfterEnv: ['<rootDir>/test/api/jest.api.setup.ts'],
1516
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
1617
moduleDirectories: ['node_modules', '<rootDir>/'],

test/component/jest.component.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const customJestConfig = {
1111
displayName: 'component',
1212
rootDir: '../../',
1313
// Add more setup options before each test is run
14+
setupFiles: ['<rootDir>/test/jest.polyfills.js'],
1415
setupFilesAfterEnv: ['<rootDir>/test/component/jest.component.setup.ts'],
1516
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
1617
moduleDirectories: ['node_modules', '<rootDir>/'],

test/gateway/jest.gateway.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const customJestConfig = {
1111
displayName: 'gateway',
1212
rootDir: '../../',
1313
// Add more setup options before each test is run
14+
setupFiles: ['<rootDir>/test/jest.polyfills.js'],
1415
setupFilesAfterEnv: ['<rootDir>/test/gateway/jest.gateway.setup.ts'],
1516
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
1617
moduleDirectories: ['node_modules', '<rootDir>/'],

test/hook/jest.hook.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const customJestConfig = {
1111
displayName: 'hook',
1212
rootDir: '../../',
1313
// Add more setup options before each test is run
14+
setupFiles: ['<rootDir>/test/jest.polyfills.js'],
1415
setupFilesAfterEnv: ['<rootDir>/test/hook/jest.hook.setup.ts'],
1516
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
1617
moduleDirectories: ['node_modules', '<rootDir>/'],

test/jest.polyfills.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Polyfill ReadableStream for jest-environment-jsdom + undici v6 compatibility.
2+
// jest-environment-jsdom strips web stream globals, but undici v6 requires
3+
// ReadableStream at module load time. This must run via `setupFiles` (before
4+
// setupFilesAfterEnv) so it executes before @inrupt/jest-jsdom-polyfills
5+
// imports undici.
6+
const { ReadableStream, TransformStream, WritableStream } = require('web-streams-polyfill');
7+
8+
if (typeof globalThis.ReadableStream === 'undefined') {
9+
globalThis.ReadableStream = ReadableStream;
10+
}
11+
if (typeof globalThis.TransformStream === 'undefined') {
12+
globalThis.TransformStream = TransformStream;
13+
}
14+
if (typeof globalThis.WritableStream === 'undefined') {
15+
globalThis.WritableStream = WritableStream;
16+
}

test/sdk/jest.sdk.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const customJestConfig = {
1111
displayName: 'sdk',
1212
rootDir: '../../',
1313
// Add more setup options before each test is run
14+
setupFiles: ['<rootDir>/test/jest.polyfills.js'],
1415
setupFilesAfterEnv: ['<rootDir>/test/sdk/jest.sdk.setup.ts'],
1516
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
1617
moduleDirectories: ['node_modules', '<rootDir>/'],

0 commit comments

Comments
 (0)