Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing fetch-polyfill (node-fetch) according to the documentation #462

Open
wants to merge 4 commits into
base: version-7.x
Choose a base branch
from
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