-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fixes #86 - Pluggable Fetch #109
base: master
Are you sure you want to change the base?
Conversation
…verifying with @adobe/fetch
🎉 Sizewatcher congratulates on the size improvement 📉:
|
Codecov Report
@@ Coverage Diff @@
## master #109 +/- ##
==========================================
+ Coverage 98.87% 98.90% +0.02%
==========================================
Files 1 1
Lines 89 91 +2
==========================================
+ Hits 88 90 +2
Misses 1 1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
You can disable all retry behavior by setting `retryOptions` to `false`. | ||
|
||
```js | ||
const {fetch: adobeFetch, AbortController} = require('@adobe/fetch'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference between adobe/fetch's abort controller and ours?
timeoutHandler = setTimeout(() => controller.abort(), retryOptions.socketTimeout); | ||
options.signal = controller.signal; | ||
} | ||
|
||
try { | ||
const response = await fetch(url, options); | ||
const fetchFn = options.fetch || fetch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this recursively invokes wrappedFetch();
so i would prefer for you to set the fetchFn
once if possible. (somehow globally maybe).
Maybe there is a way to declare on import which fetch to use?
In case the options may get wiped away between retries (maybe this is too unrealistic)
"rewire": "^5.0.0", | ||
"semantic-release": "^17.4.7" | ||
"rewire": "^6.0.0", | ||
"semantic-release": "^20.0.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typically we will update major versions of dev dependencies in follow-up PRs in case they require additional changes. For instance sometimes semantic-release updates require nodejs verion increases and we won't notice that until we actually try to release, (happened before, had to update to use nodejs 16: https://github.com/adobe/node-fetch-retry/blob/master/.github/workflows/node.js.yml#L47)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yep, nodejs18 is required for v20+: https://github.com/semantic-release/semantic-release/releases/tag/v20.0.0
@@ -852,9 +841,20 @@ describe('test fetch retry', () => { | |||
const response = await fetch(`${FAKE_BASE_URL}${FAKE_PATH}`); | |||
assert.strictEqual(response.ok, true); | |||
}); | |||
} | |||
|
|||
describe('test fetch retry', () => testFetchRetry({})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('test fetch retry', () => testFetchRetry({})); | |
describe('test fetch retry with default node-fetch', () => testFetchRetry({})); |
assert.strictEqual(response.status, 200); | ||
}); | ||
} | ||
|
||
describe('test fetch retry on http errors (throw exceptions)', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('test fetch retry on http errors (throw exceptions)', () => { | |
describe('test fetch retry on http errors (throw exceptions) with default node-fetch', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the semantic release changes won't break the CI (or just remove them), other than that LGTM
it('test fetch get works 200', async () => { | ||
nock(FAKE_BASE_URL) | ||
.get(FAKE_PATH) | ||
.reply(200, { ok: true }); | ||
const response = await fetch(`${FAKE_BASE_URL}${FAKE_PATH}`, { method: 'GET' }); | ||
const response = await fetch(`${FAKE_BASE_URL}${FAKE_PATH}`, { method: 'GET', ...options }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nitpick test case i just thought of, add a test without passing ,...options
just to make sure it works as before. (I know we default options to {}
:
Line 200 in 930a3e6
options = options || {}; |
Description
Adding support for plugging the fetch implementation and verifying with @adobe/fetch
Fixes # (issue)
Types of changes
Checklist: