forked from mswjs/interceptors
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Draft: Add tests for node native fetch
interceptor (WIP)
#5
Open
milesrichardson
wants to merge
8
commits into
chore/migrate-to-node-v18
Choose a base branch
from
test/node-native-global-interceptor
base: chore/migrate-to-node-v18
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Draft: Add tests for node native fetch
interceptor (WIP)
#5
milesrichardson
wants to merge
8
commits into
chore/migrate-to-node-v18
from
test/node-native-global-interceptor
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
milesrichardson
added a commit
to splitgraph/madatdata
that referenced
this pull request
Aug 31, 2022
- Basically, `msw` can mostly work with node-native `fetch` powered by undici, but it does not currently create its lone export `createServer` with the `FetchInterceptor` that is necessary to intercept `globalFetch` - Clone the library locally, fix this issue, build it locally, and copy the build files into this Yarn patch Upstream, I've started the chain of PRs necessary to fix this: - mswjs/interceptors#283 (migrate to Node 18) - milesforks/msw-interceptors#5 (wip, add native fetch tests) - Last: one line change to msw that I made in our patch here
milesrichardson
force-pushed
the
test/node-native-global-interceptor
branch
from
September 28, 2022 23:14
aab433c
to
7f6847d
Compare
milesrichardson
changed the base branch from
chore/migrate-to-node-v18
to
main
September 28, 2022 23:19
milesrichardson
force-pushed
the
test/node-native-global-interceptor
branch
2 times, most recently
from
September 28, 2022 23:29
06f880e
to
3b74e5b
Compare
milesrichardson
changed the base branch from
main
to
chore/migrate-to-node-v18
September 28, 2022 23:29
milesrichardson
force-pushed
the
chore/migrate-to-node-v18
branch
from
September 29, 2022 00:25
09198d9
to
75c55d3
Compare
… defined Now that Node v17+ has "native fetch", it's possible to have `globalThis.fetch` but not `location`, both in our own test code and in user test code. So, if `location` is not defined, like in `node-native.fetch` integration tests, then do not try to set it as the base url of a new URL - the caller is responsible for giving a correct location.
…-native shape It seems that the `headers` object when testing `fetch` with `node-native` is nested within `headers._headers`, but is available with `headers.raw()` - so use that as the basis of the left side of the comparison when comparing a header object to the expected one.
…rception Only `http` tests pass, and this is only the one test file (still needs `.body`, `.clone` and `.request` variants). The tests are copied from the general `fetch.test.ts` file, which is similar because it also runs in a Node environment, but different because it uses `cross-fetch`, while this new file uses native `fetch` (note there is no import of a polyfill).
Add `undici` as a development dependency, because we need to import `undici.Agent` so that we can set a dispatcher that intercepts insecure https (equivalent of `httpsAgent` with previous versions of Node). Technically we could accomplish this without a dependency on Undici, but it would require re-implementing the entire `undici.Agent` class, which would be silly. Note this is a _development_ dependency. It is not a regular dependency, because we aren't adding any special undici interceptor; we're only using the `Agent` because it's the only choice we have (Node does not re-export its undici module; we must depend on it)
…hen it exists * When no mock response is defined, the interceptor calls `pureFetch`. * In undici fetch, `RequestInit` accepts an additional property `dispatcher`, which is used for non-global agent configuration, e.g. an insecure https agent for a single request. * If interceptor calls `pureFetch` (because no mock response is defined), make sure it includes the `dispatcher` if it was originally provided
…6 host * Don't assume a single `:` indicates an IPv6 address * Change heuristic for identifying IPv6 address to rely on whether `new URL()` throws an error Ideally this serialization wouldn't be necessary, but the code that constructs the host doesn't have access to the address family of the server where the address came from
milesrichardson
force-pushed
the
test/node-native-global-interceptor
branch
from
September 29, 2022 00:41
3b74e5b
to
25a8ffa
Compare
milesrichardson
added a commit
to milesforks/msw
that referenced
this pull request
Sep 29, 2022
- Point `@mswjs/interceptors` to a tarball that was built from the code in this pending PR: milesforks/msw-interceptors#5 Using commit: milesforks/msw-interceptors@25a8ffa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
depends on #3
This is a WIP and is a follow-up to mswjs#283
So far it basically copies the existing
fetch.ts
tests but without a polyfill, without https support, and without any of the body/clone/request test variants.