-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathjest.polyfills.ts
More file actions
28 lines (26 loc) · 988 Bytes
/
jest.polyfills.ts
File metadata and controls
28 lines (26 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Polyfills for Node.js globals required by Next.js 15
import { TextEncoder, TextDecoder } from "util";
import { ReadableStream, TransformStream } from "stream/web";
// Set up polyfills before any imports
if (typeof global.TextEncoder === "undefined") {
global.TextEncoder = TextEncoder;
}
if (typeof global.TextDecoder === "undefined") {
global.TextDecoder = TextDecoder as typeof global.TextDecoder;
}
if (typeof global.ReadableStream === "undefined") {
global.ReadableStream = ReadableStream as typeof global.ReadableStream;
}
if (typeof global.TransformStream === "undefined") {
global.TransformStream = TransformStream as typeof global.TransformStream;
}
// Mock fetch API globals for Next.js 15
if (typeof global.Request === "undefined") {
global.Request = class Request {} as any;
}
if (typeof global.Response === "undefined") {
global.Response = class Response {} as any;
}
if (typeof global.Headers === "undefined") {
global.Headers = class Headers {} as any;
}