-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathjest.setup.ts
More file actions
25 lines (21 loc) · 1021 Bytes
/
Copy pathjest.setup.ts
File metadata and controls
25 lines (21 loc) · 1021 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
import { TextEncoder, TextDecoder } from 'util';
Object.assign(global, { TextDecoder, TextEncoder });
const originalUint8ArrayHasInstance = Uint8Array[Symbol.hasInstance];
Object.defineProperty(Uint8Array, Symbol.hasInstance, {
value(potentialInstance: unknown) {
if (this === Uint8Array) {
return Object.prototype.toString.call(potentialInstance) === '[object Uint8Array]';
}
return typeof originalUint8ArrayHasInstance === 'function'
? originalUint8ArrayHasInstance.call(this, potentialInstance)
: potentialInstance instanceof (this as any);
},
});
if (typeof globalThis.ReadableStream !== 'function') {
const { ReadableStream } = require('node:stream/web');
Object.assign(globalThis, { ReadableStream });
}
if (typeof globalThis.fetch !== 'function') {
const { fetch, Headers, Request, Response, FormData, File, Blob } = require('undici');
Object.assign(globalThis, { fetch, Headers, Request, Response, FormData, File, Blob });
}