-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
feat: send mocked response body as ReadableStream to the worker #1288
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 65752d0:
|
src/utils/handleRequest.ts
Outdated
resolve(transformedResponse as ResponseType) | ||
}, response.delay ?? 0) | ||
}) | ||
emitter.emit('request:end', request) |
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.
Delay is performed in the worker in order to affect the response timings.
} | ||
|
||
await sleep(mockResponse.delay) | ||
return resolve(new Response(stream, mockResponse)) |
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.
Gotcha
A really important nuance here is to respond with a stream response straight away. This way the client will receive the response immediately and will be able to read the stream as the operation channel keeps pushing the chunks from the response resolver.
src/node/createSetupServer.ts
Outdated
|
||
if (response) { | ||
await new Promise<void>((resolve) => { | ||
if (!response.delay) { |
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.
Since I've removed a hard-coded setTimeout
around responses in handleRequest
, the Node part now needs to delay mocked responses manually. The worker has been always delaying the responses in the worker thread so that the mocked delay counts for server computing time.
No
|
For Node, we can convert mocked response bodies to |
37192e5
to
ee327b4
Compare
a6900f5
to
65752d0
Compare
Released: v0.43.0 🎉This has been released in v0.43.0! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
jest.useFakeTimers()
with axios and msw #966 (does not wrap all responses insetTimeout
anymore). For Node, awaits timeout conditionally only ifresponse.delay
is set.Changes
ReadableStream
between the client and the worker. This way we support both text and non-text data likeUint8Array
to be used as a mocked response body.Roadmap
ctx.delay()
in Node. RemovingsetTimeout
inhandleRequest
breaks response delays for Node but no tests catch that.