-
Notifications
You must be signed in to change notification settings - Fork 204
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
Fix incorrect request body when intercepting fetch with getMiniflareFetchMock #423
Fix incorrect request body when intercepting fetch with getMiniflareFetchMock #423
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.
Hey! 👋 Thanks for the PR! Added a small comment. 👍
7024e9a
to
f044199
Compare
Well done @robertcepa this is something we have been trying to work around here. Thank you for the PR. Hey @mrbbot, we have been trying to get this working here since mid-last year and have just noticed someone has already fixed it. Do you have any idea when this will be released? Thank you. |
Hi! I'm also invested in seeing this released :) do we have a timeline? |
@mrbbot was talking about this PR today with the team. Is there a plan for a wide release? The automated testing we are trying to implement needs this. |
Can we get any updates on this one, please? We really want to be able to test our API. 😁 |
Just stumbled across this PR when trying to figure out how to unit test my worker. Do you know when this will be added to a release @mrbbot? |
Hey! Miniflare |
Hey there!
I am using
miniflare
withjest
to test a Workers library. I need to write a simple unit test that intercepts a request body and returns it in response.Example (full code here):
The issue I'm encountering is that
opts.body
doesn't contain request body string, as expected per https://undici.nodejs.org/#/docs/best-practices/mocking-request?id=reply-with-data-based-on-request , butAsyncGenerator
.I first thought that this was an issue in
undici
but after discussion with their team (nodejs/undici#1756) it seems that the solution is to exposeisMockActive
property onDispatcher
for test utilities onMockAgent
to work properly.This PR adds a new
MiniflareDispatcherMock
class that extends the baseMiniflareDispatcher
withisMockActive
getter. I decided to not add the getter directly toMiniflareDispatcher
, because it's a testing function that doesn't exist on real dispatchers.This class is used on
fetch
polyfill to instantiate dispatcher when bound withMockAgent
.