Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/http/fetch-polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import {
Response,
} from 'node-fetch';

// Registering Fetch as a glboal polyfill
(global as any).fetch = nodeFetch;
(global as any).Request = Request;
(global as any).Headers = Headers;
(global as any).Response = Response;
const globalThis = global as any;

if (!globalThis.fetch) {
globalThis.fetch = nodeFetch;
globalThis.Request = Request;
globalThis.Headers = Headers;
globalThis.Response = Response;
}
2 changes: 1 addition & 1 deletion test/integration/fetch-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Using the fetch api', () => {

it('should also work when passing a Request object', async () => {

const request = new Request('?foo=bar');
const request = new Request('http://localhost:3000/?foo=bar');
const response = await hal2.fetch(request);
expect(response).to.have.property('status');
expect(response.status).to.eql(200);
Expand Down