Skip to content
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

Allow Passing Custom fetch Values to Override cross-fetch Usage #22

Closed
joealden opened this issue Sep 27, 2024 · 2 comments
Closed

Allow Passing Custom fetch Values to Override cross-fetch Usage #22

joealden opened this issue Sep 27, 2024 · 2 comments

Comments

@joealden
Copy link

I'm in the process of moving a project to ESM, and as a part of that I'm now able to move to node-fetch V3 (as it's ESM only).

V3 also brings behavioural changes to make it more spec compliant - a notable one being that body parse failures now return SyntaxError instead of FetchError. As the latest cross-fetch version still depends on node-fetch V2 (presumably for CJS compatibility - which I understand), this means that the behaviour of our tests won't match what will happen in production.

As a flexible (yet hopefully simple to implement) solution, could we add an optional 2nd argument to createFetchMocker called something like overrides, that would be an object optionally containing fetch, Response, Headers and Request (all the values that createFetchMocker uses from cross-fetch)?

This would allow someone to pass whatever fetch implementation they want, which could be node-fetch V3, or thinking to the future, the built-in fetch values that are now a part of Node and are stable in Node 22.

@dirkluijk
Copy link
Collaborator

Should be fixed by #24.

IanVS pushed a commit that referenced this issue Oct 24, 2024
All right, this PR includes:

- Moving away from `cross-fetch` by just patching the global fetch which should be present in all modern runtimes and browsers. That would close issue #22 and #23.
- It will now force Node 18, which closes issue #21 and removes the need to patch the `DOMException`. 
- The source code is now written in TypeScript and transpiled to JavaScript into the `dist` directory, including the type definitions and source maps.
@IanVS
Copy link
Owner

IanVS commented Oct 24, 2024

Closed by #24, will be released in the next version.

@IanVS IanVS closed this as completed Oct 24, 2024
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

No branches or pull requests

3 participants