1 |
|
2 | let fetch;
|
3 | try {
|
4 |
|
5 |
|
6 |
|
7 | fetch = jest.requireActual('node-fetch');
|
8 | } catch (e) {
|
9 | fetch = require('node-fetch');
|
10 | }
|
11 | const Request = fetch.Request;
|
12 | const Response = fetch.Response;
|
13 | const Headers = fetch.Headers;
|
14 | const Stream = require('stream');
|
15 | const FetchMock = require('./lib/index');
|
16 | const http = require('http');
|
17 | const { setUrlImplementation } = require('./lib/request-utils');
|
18 | setUrlImplementation(require('whatwg-url').URL);
|
19 |
|
20 | FetchMock.global = global;
|
21 | FetchMock.statusTextMap = http.STATUS_CODES;
|
22 | FetchMock.Stream = Stream;
|
23 |
|
24 | FetchMock.config = Object.assign(FetchMock.config, {
|
25 | Promise: Promise,
|
26 | Request: Request,
|
27 | Response: Response,
|
28 | Headers: Headers
|
29 | });
|
30 |
|
31 | module.exports = FetchMock.createInstance();
|