-
Notifications
You must be signed in to change notification settings - Fork 36
fix: remove use of node-fetch, use built in fetch #714
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #714 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 238 236 -2
Branches 47 47
=========================================
- Hits 238 236 -2 ☔ View full report in Codecov by Sentry. |
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.
Pull Request Overview
This PR replaces the node-fetch
package and jest-fetch-mock
usage with the built-in fetch
API, and updates tests to use a custom setFetchMock
helper.
- Remove all
node-fetch
imports in source code and tests - Introduce
setFetchMock
injest.setup.js
for mockingglobal.fetch
- Clean up
package.json
by deletingnode-fetch
,jest-fetch-mock
, and related overrides
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
test/jest.setup.js | Added setFetchMock global helper; removed jest-fetch-mock |
test/helpers.test.js | Switched from jest-fetch-mock to setFetchMock |
test/commands/*.test.js | Removed fetch.resetMocks() and node-fetch imports; use setFetchMock |
test/.eslintrc.json | Declared setFetchMock as a global for linting |
src/helpers.js | Removed require('node-fetch') |
src/commands/discover.js | Removed require('node-fetch') |
package.json | Deleted node-fetch , jest-fetch-mock , and overrides |
Comments suppressed due to low confidence (1)
package.json:1
- Since relying on the built-in
fetch
requires Node ≥18, consider adding an"engines": { "node": ">=18" }
field or updating README/CHANGELOG to document the minimum Node version.
{
@@ -15,8 +15,12 @@ const { stdout } = require('stdout-stderr') | |||
jest.setTimeout(3000) | |||
jest.useFakeTimers() | |||
|
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.
Consider adding an afterEach
hook in this setup file to delete or restore global.fetch
so that mocks don’t leak between tests.
const originalFetch = global.fetch; |
Copilot uses AI. Check for mistakes.
command.argv = [] | ||
await expect(command.run()).rejects.toThrow('FetchError: invalid json response body') | ||
await expect(command.run()).rejects.toThrow() |
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.
[nitpick] This assertion is very broad and may pass for unexpected errors; consider tightening it to match a specific error message or error type.
await expect(command.run()).rejects.toThrow() | |
await expect(command.run()).rejects.toThrowError('Invalid JSON response') |
Copilot uses AI. Check for mistakes.
Motivation and Context
node-fetch@v2's dependencies use the built in punycode module, which is deprecated in node-22, and prints out a deprecation warning.
How Has This Been Tested?
Types of changes
Checklist: