Skip to content

Commit

Permalink
tests: always use node-fetch to simulate browser fetch (#437)
Browse files Browse the repository at this point in the history
Since httpRequest is only used in the browser, it doesn't matter much
if we are using node-fetch, isomorphic-fetch, undici or node's native
fetch. Said that, to avoid tests to fail on Node 18 (which includes a
native fetch implementation), we can overwrite the global fetch with
node-fetch's implementation.
  • Loading branch information
pablopalacios authored Aug 30, 2023
1 parent 8053978 commit b6ece76
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tests/unit/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ const { fetch, Request } = abortableFetch({
Request: nodeFetch.Request,
});

if (!global.fetch) {
global.AbortController = AbortController;
global.Headers = nodeFetch.Headers;
global.Request = Request;
global.Response = nodeFetch.Response;
global.fetch = fetch;
}
global.AbortController = AbortController;
global.Headers = nodeFetch.Headers;
global.Request = Request;
global.Response = nodeFetch.Response;
global.fetch = fetch;

0 comments on commit b6ece76

Please sign in to comment.