Skip to content

Commit

Permalink
fix: use fetch and Headers fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Oct 2, 2020
1 parent a8f96bf commit 19fccc6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/http/fetch.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-env browser */

const { TimeoutError, AbortError } = require('./error')
const Response = require('./response')
const { Request, Response, Headers, fetch } = require('./fetch.polyfill')

/**
* @typedef {RequestInit & ExtraFetchOptions} FetchOptions
Expand Down
22 changes: 22 additions & 0 deletions src/http/fetch.polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

/* eslint-env browser */

// JSDOM has `XMLHttpRequest` but it does not have a `fetch` or `Response` so
// we workaround by pulling in node-fetch.
// See: https://github.com/jsdom/jsdom/issues/1724
exports.fetch = typeof fetch === 'function'
? fetch
: require('node-fetch')

exports.Response = typeof Response === 'function'
? Response
: require('node-fetch').Response

exports.Request = typeof Request === 'function'
? Request
: require('node-fetch').Response

exports.Headers = typeof Headers === 'function'
? Headers
: require('node-fetch').Headers
11 changes: 0 additions & 11 deletions src/http/response.js

This file was deleted.

0 comments on commit 19fccc6

Please sign in to comment.