-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
/
setup.ts
35 lines (31 loc) · 1.2 KB
/
setup.ts
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
31
32
33
34
35
import {
TextEncoder as NodeTextEncoder,
TextDecoder as NodeTextDecoder,
} from "util";
import { fetch, Request, Response, Headers } from "@remix-run/web-fetch";
import { AbortController as NodeAbortController } from "abort-controller";
// https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#configuring-your-testing-environment
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
if (!globalThis.fetch) {
// Built-in lib.dom.d.ts expects `fetch(Request | string, ...)` but the web
// fetch API allows a URL so @remix-run/web-fetch defines
// `fetch(string | URL | Request, ...)`
// @ts-expect-error
globalThis.fetch = fetch;
// Same as above, lib.dom.d.ts doesn't allow a URL to the Request constructor
// @ts-expect-error
globalThis.Request = Request;
// web-std/fetch Response does not currently implement Response.error()
// @ts-expect-error
globalThis.Response = Response;
globalThis.Headers = Headers;
}
if (!globalThis.AbortController) {
// @ts-expect-error
globalThis.AbortController = NodeAbortController;
}
if (!globalThis.TextEncoder || !globalThis.TextDecoder) {
globalThis.TextEncoder = NodeTextEncoder;
// @ts-expect-error
globalThis.TextDecoder = NodeTextDecoder;
}