Skip to content

Commit

Permalink
fix for node webpack environments, solution based off qubyte#239 but …
Browse files Browse the repository at this point in the history
…with added support for tests
  • Loading branch information
camhart committed May 30, 2020
1 parent 47aa711 commit 145100a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion fetch-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

var fetch = require('node-fetch');

function wrapFetchForNode(fetch) {
function wrapFetchForNode(fetchModule) {
// Support webpack module import weirdness.
var fetch = fetchModule.default ? fetchModule.default : fetchModule;

// Support schemaless URIs on the server for parity with the browser.
// https://github.com/matthew-andrews/isomorphic-fetch/pull/10
return function (u, options) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"test:browserify": "testem ci",
"pretest:webpack": "npm run build && webpack --mode development tests/fetch-browser.spec.js -o build/browser-test-bundle.js",
"test:webpack": "testem ci",
"pretest:webpack:node": "webpack --mode development --target node tests/fetch-node.spec.js -o build/node-test-bundle.js",
"test:webpack:node": "mocha build/node-test-bundle.js",
"build": "rimraf build && mkdirp build && node build.js > build/fetch-browser.js",
"prepublishOnly": "npm run build"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/fetch-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var fetchWrapper = require('../fetch-node');
var URL = require('url').URL;
var nock = require('nock');
var assert = require('assert');
var ThenPromise = require('promise');
var ThenPromise = Promise;

var good = 'hello world. 你好世界。';
var bad = 'good bye cruel world. 再见残酷的世界。';
Expand Down

0 comments on commit 145100a

Please sign in to comment.