-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Use node-fetch v3 beta and require Node.js 10.16 #19
Conversation
Tests are failing on Node.js v8, as it is not supported in the |
Thanks for the PR! I am 👍 on dropping Node 8. |
@sholladay I added information about how to deal with |
Could you double check the unit measurements? I would expect these values to be measured in multiples of bytes, not bits. |
Oh, you are right. Just changed it. Thanks for catching that! |
The default Also, if you want a test for the default test('default highWaterMark is 10MB', async t => {
const response = await ky('https://httpbin.org/json');
t.is(response.highWaterMark, 10485760);
}); |
Yes |
Everything done 😄 |
I updated the node-fetch version so that we can now use the spread syntax. However, it will not work the way you wanted to: // Changes the default 16384 bytes but does not allow users to specify the `highWaterMark`
fetch(options.url, {...options, highWaterMark: TEN_MEGABYTES}); That's why I used the following approach: const DEFAULT = 16384;
fetch(options.url, {...options, highWaterMark: options.highWaterMark === DEFAULT ? TEN_MEGABYTES : options.highWaterMark}); Let me know if there is a cleaner way to do it. |
How about: fetch(options.url, {...options, ...{highWaterMark: TEN_MEGABYTES}}); ? |
I changed it to:: global.fetch = (url, options) => fetch(url, {highWaterMark: TEN_MEGABYTES, ...options}); Could you give this a try and let me know if it works? If not, I'll need to dig into it further, as the older commit with |
@sindresorhus This changes the default node-fetch's @sholladay This doesn't change the default node-fetch's Also, we can't do Here is the set of tests I use to check the behavior: test('default highWaterMark is 10MB', async t => {
const response = await ky('https://httpbin.org/json');
t.is(response.highWaterMark, 10000000);
});
test('can override the highWaterMark', async t => {
const response = await ky('https://httpbin.org/json', {highWaterMark: 1024 * 1024});
t.is(response.highWaterMark, 1048576);
}); In terms of the old solution (with I hope that makes sense. |
In conclusion, |
How is
I don't think we care about
This makes me think there might be a misunderstanding in how object spread works. Here's an example with mock fetch functions that take the same arguments and spread the options the same way, which do produce the output I would expect... const fetchA = (url, options) => {
fetchB(url, {highWaterMark: 'fetchA default', ...options});
};
const fetchB = (url, options) => {
console.log('url:', url);
console.log('options:', options);
};
fetchA();
// url: undefined
// options: { highWaterMark: "fetchA default" }
fetchA('foo');
// url: "foo"
// options: { highWaterMark: "fetchA default" }
fetchA('foo', {});
// url: "foo"
// options: { highWaterMark: "fetchA default" }
fetchA('foo', {highWaterMark: 'custom value'})
// url: "foo"
// options: { highWaterMark: "custom value" } In other words, it's fine to spread In this case, Could you point me more specifically to where you think this logic is wrong? |
Ok, it turns out I did not understand some things correctly 😆 After doing more verification, I can confirm that the correct |
Great, no worries! This is looking good to me now. 👍 My final thought on this is that, ultimately, the |
Fixes #8 (allows using the
highWaterMark
option)We have a section in the node-fetch's readme about custom
highWaterMark
. Let me know if we should link it somewhere here 😄IssueHunt Summary
Referenced issues
This pull request has been submitted to: