-
-
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
Adds WebSocket support #396
Conversation
How to try this out?Building locally
API referencesSee the |
9be1a4d
to
977469f
Compare
Love the library, we need this feature for our company since we have already integrated MSW in our workflow. If there is anything I can do here to help please give me some direction. |
Hey, @ashkan-pm. Thanks for reaching out! The best thing you can do at the moment is to give this branch a test in your project. Share the feedback and bugs you spot here. See the instructions above. I may have other things that need help in the future. |
977469f
to
92fb93b
Compare
92fb93b
to
962eea3
Compare
I love using msw for different projects, I will give a shot on new version of my game https://github.com/keremciu/house-of-decks/blob/ws-implement/client/src/utils/server-mock.js I use |
962eea3
to
9d42451
Compare
import { captureConsole } from '../../support/captureConsole' | ||
import { runBrowserWith } from '../../support/runBrowserWith' | ||
|
||
test('sends server event to all active clients', async () => { |
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.
this test is great! I'd like to try it out in my tests, thanks for all this hard work here ✨
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.
Thanks, @keremciu. So far it behaves as expected in regards to multi-client handling. Please let me know once you try this out.
e2a659c
to
d232a94
Compare
d232a94
to
bde1291
Compare
bde1291
to
69e9b17
Compare
Hi is there will be suppirt also for socket.io ? |
Hey, @johnico. We are planning on socket.io support as it's one of the most used WebSocket libraries. I'm not sure if there're any usage examples with it yet, but I'd be glad to work on them when the time comes. |
@kettanaito thanks |
69e9b17
to
2cce30c
Compare
@johnico the easiest way is just to try that out. WebSocket events are not captured by Service Workers, so there should be no issue with having MSW for mocking REST API and provisioning a separate mock WebSocket server by yourself to deal with WebSockets. The only issues there can be are in NodeJS, because request interception works differently there. |
2cce30c
to
a1029ed
Compare
a1029ed
to
a7ef532
Compare
@kettanaito - Is there any idea on when this feature will be released? |
@josh-biddick, there's no release date planned for it yet. It needs to have a proof of concept in Node.js to see if WebSocket support is even possible in that environment. There are quite a lot of other tasks on the roadmap, with some taking precedence over this. While I see WebSocket support as a great addition to the library, there are features that much more developers would benefit from, objectively. The team behind the project is small, so there are not enough hands to get to some stuff. If you wish to get this done sooner, consider contributing to the project, either by helping with the open issues or supporting the work on WebSockets on Open Collective. With enough funds, we can pay contributors to dedicate time to this feature exclusively. |
a7ef532
to
9cb4736
Compare
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.
the build is probably failing because the code is trying to load webSocketStorage
from WebSocketStorage.ts
but the file is webSocketStorage.ts
.
I'm not sure which is more idiomatic for the project, but I went with changing the code to look for the right file, rather than change the case of the filename.
953b937
to
57e8e14
Compare
@kettanaito, Can you please fix the above mentioned typo please? File webSocketStorage.ts should be WebSocketStorage.ts. |
Hi @kettanaito, need any help pushing this to the finish line? I have some spare time to help on it if needed :) |
Hey @kettanaito curious about the state of things with this, wonder if it might be coming to official support soon-ish |
thought this article might be helpful for anyone interested in adding node.js support: https://dustinpfister.github.io/2019/11/20/nodejs-websocket/ |
Hey, folks. Thank you everybody for contributing with feedback. I am planning on getting to WebSocket support this spring. We've just released a massive Node.js request interception rewrite and I need some time to address any related issues. We are also migrating all our dependencies to Node.js v16 to stay up-to-date and prevent unexpected behaviors when using newer versions of Node.js. My plan remains the same:
@MatanBobi, thanks for volunteering! I will certainly count you in once I reach the state of these changes where contributions would be easier. Right now it's a rough PoC and collaborating on it will not be efficient just yet. As I'm getting overwhelmed with the issues, I feel this is a good time to remind everybody that you can sponsor Mock Service Worker on GitHub to, hopefully, accumulate the budget to have at least one part/full-time contributor. Until then happens, I will prioritize tasks and work on them as my time allows. Thank you for understanding. |
@kettanaito Thank you for hard work. I started sponsoring you :) |
548fbd0
to
fed3b21
Compare
Thank you, @SerkanSipahi! I appreciate it more than you know it! I'm nearing the end of the "polishing" phase as most of the critical issues should be addressed by now. There are a few releases ahead for the things other contributors have worked on, it's time to publish them. And after that, unless we got a large number of issues again, I'm planning on switching to WebSocket support. |
@kettanaito I am used to reading the tests first and then looking at the documentation if necessary. Your tests (https://github.com/mswjs/msw/pull/396/files) are wonderfully written and very understandable. Thank you for that. |
Update: I've spent some time outlining the architecture that the
I'm curious if the current implementation of the I will start with the study on how WebSocket is usually implemented in Node.js, and will turn that study into a Node.js interceptor for WebSocket events. Excited to get these changes going! |
@kettanaito should probably make sure msw has support for both binary and text request/responses as that's a big reason why a lot of devs will move to a web socket. with binary protocols you can create channels via some extra bits in binary data. You can see an overview of how something like that might work here: https://www.youtube.com/watch?v=-OjYRDVlGZQ |
A great point, @lifeiscontent. Thanks for sharing the link as well. Let me get the browser/Node.js interception working for WebSocket and then we can iterate on top of it to ensure binary support. |
@kettanaito what is the current state of websocket support in msw? :) |
Hey, @SerkanSipahi. The current status is that the WebSocket support is in development. I've done some ground work in the interceptors repository so interceptors are now event-based. This will also open up the possibility to handle non-HTTP interactions in interceptors. The WebSocket support will be implemented in a form of a new interceptors (see mswjs/interceptors#236). You can also find the progress map in the referenced pull request. This pull request (396) is likely to be abandoned. How can I help make WebSockets happen faster?
|
To prevent confusion, I'm closing this pull request in favor of mswjs/interceptors#236. There will be additional work required on the MSW's side once the interceptor is merged, such as developing the If you wish to contribute, mswjs/interceptors#236 is the correct place to do so. |
@kettanaito I am already supporting msw for 2 month :) ... but I can help in reviewing the code, too. |
@SerkanSipahi, my bad 😅 I'm thankful for your support. That's the reason I was able to kick off the interceptors refactoring and have already prepared in-browser support for SocketIO and native |
GitHub
Goal
Provide a designated API that would allow the mocking of a WebSocket server. Keep the API as close to the actual server's API as possible, to minimize the library-specific knowledge needed to operate with this API.
Changes
Roadmap
WebSocketStorage
class as a singleton to store all server references.Event
in Node.js.BroadcastChannel
in Node.js (not needed, we can use singletons in Node.js).error
event.close
event.connections
list of the server).