-
-
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
Grpc-web #238
Comments
Hey, @Jeffhabs. Mock Service Worker will work with any library that issues request that can be intercepted by the Service Worker's There are a few exceptions at the moment:
Regarding You can reference the Getting started tutorial to set up MSW in your app. |
I was successfully able to get the mock to register. However now I'm facing the issue with the response type. Since we are using proto messages as the response types, I'm not sure how to facilitate that. import { setupWorker, rest } from 'msw';
import { GetHuntGroupPauseCodesRes } from 'protos/api/v0alpha/p3api_pb';
const hgpRes = new GetHuntGroupPauseCodesRes();
hgpRes.setName('Pause Codes');
hgpRes.setDescription('My Pause Codes');
hgpRes.setPauseCodesList(['Lunch', 'Bathroom', 'Lazy']);
const mocks = [
rest.post(
'/GetHuntGroupPauseCodes',
(_req, res, ctx) => {
return res(ctx.body(hgpRes));
}
),
];
const worker = setupWorker(...mocks);
worker.start(); My response in the network tab just looks like Is this related to serialization issue #221? |
Thanks for trying that out! The concept looks amazing. Could you try using |
Hey, @Jeffhabs! Please, have you tried my suggestion above? I feel your feedback would be valuable, so would love to hear from you. Thanks. |
@kettanaito Yes, unfortunately I could not get it to work as our UI is expecting a serialized proto message as the response not JSON. |
@Jeffhabs, hey! Could you please try this using the version We've added a binary response type to the latest minor version, and it may have solved your unexpected serialization issue. Please let me know. |
I also have the same problem where grpc-web will encode the request using Uint8Array and base64 that will result in a none human readable string payload sent to the server. If we want to mock grpc-web, we need then to return a response with the right headers and an encoded body like:
The problem I found using this method is that the coding/decoding the body depends on the proto file structure and creating a mocked response requires to correctly encode it first before returning it using handlers. For now I unfortunately I'm not able to use this good library to mock grpc-web responses. |
We'd love to have GRPC support but don't have enough manpower to implement it. If you use MSW and would like it to handle GRPC requests, consider contributing this support. We'd be more than happy to help you along the way. |
This would also be great to have on Node ( |
I am using grpc-web and there is something problem |
So i'm assuming |
@ritchieanesco, yes. See this. |
Hi all, you can mock grpc-web requests with msw, you just have to imitate the binary format. I wrote a blog post with an example here. |
@lucaslcode, this is absolutely outstanding. I will share that on Twitter. Thank you for writing this! |
Does this work with grpc-web?
If not, would it be possible to add to the road map?
The text was updated successfully, but these errors were encountered: