diff --git a/src/index.js b/src/index.js index a1b21b0..761cd9a 100644 --- a/src/index.js +++ b/src/index.js @@ -38,19 +38,12 @@ export function polyfill(options) { const fetch = require('fetch-cookie')(require('isomorphic-fetch'), cookieJar); global.fetch = fetch; global.cookieJar = cookieJar; - global.fetchMock = undefined; - const { Response, Headers, Request } = require('whatwg-fetch'); - global.Response = Response; - global.Headers = Headers; - global.Request = Request; + require('whatwg-fetch'); } - if (opts.fetch) { - const { Response, Headers, Request } = require('whatwg-fetch'); + if (opts.fetch && !opts.isomorphicFetch) { + require('whatwg-fetch'); global.fetchMock = require('fetch-mock'); - global.Response = Response; - global.Headers = Headers; - global.Request = Request; } if (opts.localStorage && !global.localStorage) { diff --git a/src/tests/index.test.js b/src/tests/index.test.js index 69fc322..b945e97 100644 --- a/src/tests/index.test.js +++ b/src/tests/index.test.js @@ -24,6 +24,7 @@ describe('polyfill', () => { expect(global.Response).not.toBeDefined(); polyfill({ media: false, + isomorphicFetch: false, fetch: true, localStorage: false, }); @@ -38,7 +39,10 @@ describe('polyfill', () => { it('should polyfill fetch', (done) => { polyfill({ + media: false, isomorphicFetch: true, + fetch: false, + localStorage: false, }); expect(global.Headers).toBeDefined(); expect(global.Request).toBeDefined(); @@ -51,6 +55,9 @@ describe('polyfill', () => { it('should not polyfill localStorage', () => { polyfill({ + media: false, + isomorphicFetch: false, + fetch: false, localStorage: false, }); expect(global.localStorage).toBeDefined();