-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathjest.polyfills.ts
More file actions
30 lines (28 loc) · 951 Bytes
/
jest.polyfills.ts
File metadata and controls
30 lines (28 loc) · 951 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
29
30
import { TextEncoder, TextDecoder } from "util";
// @ts-ignore
if (!global.TextEncoder) global.TextEncoder = TextEncoder;
// @ts-ignore
if (!global.TextDecoder) global.TextDecoder = TextDecoder;
// @ts-ignore
import {
ReadableStream,
WritableStream,
TransformStream,
} from "web-streams-polyfill/polyfill";
// @ts-ignore
if (!global.ReadableStream) global.ReadableStream = ReadableStream;
// @ts-ignore
if (!global.WritableStream) global.WritableStream = WritableStream;
// @ts-ignore
if (!global.TransformStream) global.TransformStream = TransformStream;
// Polyfill MessageChannel and MessagePort using worker_threads if available
try {
// @ts-ignore
const { MessageChannel, MessagePort } = require("worker_threads");
// @ts-ignore
if (!global.MessageChannel) global.MessageChannel = MessageChannel;
// @ts-ignore
if (!global.MessagePort) global.MessagePort = MessagePort;
} catch (e) {
// worker_threads not available, skip
}