Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shazron
Copy link
Member

@shazron shazron commented Jan 21, 2025

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?

  • npm test

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (74389d0) to head (6764e35).

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.
📢 Have feedback on the report? Share it here.

Copy link

@Copilot Copilot AI left a 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 in jest.setup.js for mocking global.fetch
  • Clean up package.json by deleting node-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()

Copy link
Preview

Copilot AI Jun 10, 2025

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.

Suggested change
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()
Copy link
Preview

Copilot AI Jun 10, 2025

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.

Suggested change
await expect(command.run()).rejects.toThrow()
await expect(command.run()).rejects.toThrowError('Invalid JSON response')

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant