diff --git a/src/http/fetch-polyfill.ts b/src/http/fetch-polyfill.ts index b03f853..848866e 100644 --- a/src/http/fetch-polyfill.ts +++ b/src/http/fetch-polyfill.ts @@ -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; +} diff --git a/test/integration/fetch-api.ts b/test/integration/fetch-api.ts index 8e5273c..64fa232 100644 --- a/test/integration/fetch-api.ts +++ b/test/integration/fetch-api.ts @@ -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);