-
Notifications
You must be signed in to change notification settings - Fork 541
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
reply
callback function argument's body
does not contain request body string, but AsyncGenerator
#1756
Comments
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that. By the looks of it there are two bugs:
|
Full code here: https://github.com/robertcepa/toucan-js/blob/undici-issue-1756/test/index.spec.ts#L23 Steps:
We are looking for the output of Context: the file is testing |
Miniflare creates a wrapper around a Dispatcher (called MiniflareDispatcher) where its Line 1932 in f91cd5e
This is an issue in Miniflare where the fix would (probably) be: diff --git a/packages/core/src/standards/http.ts b/packages/core/src/standards/http.ts
index 31d9615..8074866 100644
--- a/packages/core/src/standards/http.ts
+++ b/packages/core/src/standards/http.ts
@@ -736,6 +736,11 @@ class MiniflareDispatcher extends Dispatcher {
// @ts-expect-error just want to pass through to global dispatcher here
return this.inner.destroy(...args);
}
+
+ get isMockActive () {
+ // @ts-expect-error not all dispatchers may have an isMockActive property
+ return this.inner.isMockActive
+ }
}
export async function fetch( |
Thank you for investigating @KhafraDev . I will take this up with the maintainers of miniflare. My $.02: I think it would still be worthwhile to allow |
Bug Description
According to https://undici.nodejs.org/#/docs/best-practices/mocking-request?id=reply-with-data-based-on-request, the argument provided to the callback function for
reply
should containbody
property containing the request body string. However,body
contains anAsyncGenerator
, which cannot be used to act upon, because thereply
's callback function is not awaited (code does not expect async callback).Reproducible By
Expected Behavior
opts.body
provides the request body string.Logs & Screenshots
console.log(opts)
displays:I expect it to display:
I'm able to access request body data with the following code, but can't actually use it because the
reply
's callback is notawait
ed.Environment
OS: Windows 11 Home 22000.1098, macOS Monterey 12.4
NodeJS: v16.18.0
Additional context
undici
is a dependency of https://github.com/cloudflare/miniflare that I use to test Cloudflare Workers.miniflare
providesMockAgent
fromundici
directly (see: https://github.com/cloudflare/miniflare/blob/31792ba7d98f0aba839d28e13228671c46535b97/packages/core/src/standards/http.ts#L819)The text was updated successfully, but these errors were encountered: