-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
TypeError: Failed to fetch in a miniflare-like
environment
#1834
Comments
I have this same issue |
@monoald I think there's something here: 1 - the error you're seeing is from your attempt to log Once doing that, we do get a different error
Which looks like an issue with the way We may need to wrap reads of |
It looks like there are a few places we read properties unavailable in cloudflares Request/Response objects. here are the lines I modified (in node_modules directly to get things cleared up) first, the log lines: (this, being non-synchronous) will likely end after your test does and cause some warnings. - server.events.on("request:start", ({ request }) => {
+ server.events.on("request:start", async ({ request }) => {
console.log(
"MSW intercepted:",
request.method,
request.url,
- request.json()
+ await request.clone().json()
);
});
Once I wrap those (in msw and msw/cookies) in some try/catch logic, it seems like you're missing a return HttpResponse.json({
id: "15d42a4d-1948-4de4-ba78-b8a893feaf45",
firstName: "John",
+ scope: "",
}); I'm not familiar about whether we should wrap these, or test for them somehow, and that might need a bit of prodding, |
In the short term, I think you can use something like |
once that lands we should be able to update It is strange to me that miniflare/cloudflare error instead of ignoring these |
@mattcosta7 Thank you so much for the help! I'm about to make the changes. If the pr is accepted, for other users there is no need for them to use |
yep - we should be able to avoid |
Great! thanks a lot again. |
@Ruddickmg are you also using a worker environment like miniflare? Just want to make sure your report mirrors the one that this issue discusses |
miniflare-like
environment
@monoald I'll keep this open until we fix the underlying msw code to work by default if that's ok with you |
@mattcosta7 hello! I have also updated to 2.x following the migration guide and I'm facing a similar error but with a slightly different stacktrace:
I have Node 18.17 running. Do you think this problem is related to the problem reported by @monoald? |
@kiocosta almost definitely not related your stack trace seems to be -https://github.com/mswjs/interceptors/blob/fb8a400f50ad8eb48ece32b23d8354df7e58a16e/src/interceptors/fetch/index.ts#L61 which would look like Please open a new issue with some details about your environment and ideally a reproduction, and I can try to debug when I get a chance, but it seems as though there's some missing signal that's expected What versions of jest and test environment (jsdom?) are you using? Curious if abort signal is not defined in that environment somewhere |
I'll open the issue with more details and as soon as I can.
|
I've opened PRs in both
These 2 prs update the code which seems to cause issues in your tests, and should guard against future regressions in those dependencies, since I've added a I also opened a failing test using the Once we land the 2 linked prs from dependencies, and bump their versions, I expect the regression test that's failing in #1840 will pass |
Thanks everyone for the input on this issue. I've approved both of the pull requests Matthew mentioned, hope to get them released later today. |
Released: v2.0.4 🎉This has been released in v2.0.4! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Prerequisites
Environment check
msw
versionNode.js version
v20.1.0
Reproduction repository
https://github.com/monoald/auth-hono
Reproduction steps
Current behavior
Trying to test using Hono JS, I followed all the necessary setup for jest, but still get the error.
Expected behavior
The test should run without any error and mock fetch request.
The text was updated successfully, but these errors were encountered: