-
Notifications
You must be signed in to change notification settings - Fork 30
Replace node-fetch and form-data with built-in fetch and FormData #344
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
Conversation
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 removes the dependency on node-fetch by switching to the built-in fetch available from Node 18+, cleaning up both production and test code.
- Removed node-fetch imports from production files and tests
- Updated tests to spy on global.fetch and added afterEach hooks to restore mocks
- Removed node-fetch from package.json
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/postGithubComment-test.js | Replaced node-fetch mocks with global.fetch spy and ensured restoration of mocks after tests. |
test/loadUserConfig-test.js | Removed node-fetch and replaced with a global.fetch spy, though some fetch mocking remains inconsistent. |
test/fetchPng-test.js | Updated fetch mocking to use global.fetch consistently. |
src/postGithubComment.js | Removed node-fetch import in favor of built-in fetch. |
src/makeRequest.js | Removed node-fetch import and dependency. |
src/loadUserConfig.js | Removed node-fetch import. |
src/loadCSSFile.js | Removed node-fetch import. |
src/fetchPng.js | Removed node-fetch import in favor of built-in fetch. |
package.json | Removed the node-fetch dependency. |
Comments suppressed due to low confidence (1)
test/loadUserConfig-test.js:115
- [nitpick] After switching to using jest.spyOn(global, 'fetch'), consider replacing 'fetch.mockImplementation' with 'global.fetch.mockImplementation' for consistency with other tests.
fetch.mockImplementation(() => Promise.resolve({ ok: true, json: () => ({ secret: 'yay' }) }));
Node added fetch in v17.5, and we don't support anything older than Node 18, so we should be able to remove this dependency now without any issues. FormData is also available in Node 18, so we should be good to go on that front.
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 removes the node-fetch and form-data dependencies by replacing them with built-in fetch and FormData in Node 18+.
- Removed node-fetch and form-data imports and their related mocks in tests
- Updated tests to use global.fetch with proper mock cleanup
- Modified FormData usage in makeRequest to use Blob for form fields
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/postGithubComment-test.js | Updated fetch mocking to use global.fetch and added cleanup in afterEach |
test/loadUserConfig-test.js | Replaced node-fetch mocking with global.fetch spy; slight inconsistency in fetch reference |
test/fetchPng-test.js | Updated fetch mocking to rely on global.fetch and adjusted header assertions for consistency |
src/postGithubComment.js | Removed node-fetch dependency |
src/makeRequest.js | Removed FormData dependency and adapted to built-in FormData using Blob for values |
src/loadUserConfig.js | Removed node-fetch dependency |
src/loadCSSFile.js | Removed node-fetch dependency |
src/fetchPng.js | Replaced node-fetch with built-in fetch and updated stream conversion using Readable.fromWeb |
package.json | Removed node-fetch and form-data dependencies |
info, | ||
})); | ||
|
||
jest.spyOn(global, 'fetch').mockImplementation(() => ({ ok: true })); |
Copilot
AI
May 8, 2025
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.
The test sets up a global.fetch spy but later calls fetch.mockImplementation. For clarity and consistency, update all references to use global.fetch explicitly.
jest.spyOn(global, 'fetch').mockImplementation(() => ({ ok: true })); | |
jest.spyOn(global, 'fetch').mockImplementation(() => ({ ok: true })); | |
global.fetch.mockImplementation(() => ({ ok: true })); |
Copilot uses AI. Check for mistakes.
} else { | ||
form.append(key, value); | ||
form.append(key, new Blob([value])); |
Copilot
AI
May 8, 2025
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] Wrapping non-file values in a Blob may alter their type; verify that converting simple form values to Blob objects is the intended behavior for the built-in FormData implementation.
Copilot uses AI. Check for mistakes.
Oh rats, we are using the |
Looks like this is coming to Node's fetch soon nodejs/node#57165 |
Node added fetch in v17.5, and we don't support anything older than Node
18, so we should be able to remove this dependency now without any
issues.
FormData is also available in Node 18, so we should be good to go on
that front.