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
Make Party.Room constructor public #843
Comments
I have a proof of concept functional at kettanaito/tug-o-war@00bdfa6! It reuses my If we can provide a better experience around the Room and Storage APIs that'd be incredible. Currently, I mock the Now, I agree that a mock Room instance won't be a 1-1 replica of the production room. I think a certain degree of deviation is always acceptable in mocks. Providing the minimum, which is the |
UpdatesOkay, after I've given this some more thought, I have concluded that reusing the actual PartyKit server for testing may not be the best idea. If you've constructed you server to support such a use case, I suppose you can do as you wish, but from the general testing practices perspective, I believe that's not a good way to set up a test. My main motivation to rely on the actual WebSocket server was to reuse the existing behaviors of the server. Example: I send a That kind of logic doesn't belong in the test because it's not something the client knows or controls. The fact that the 10th
In the end, those are precisely the logic that the client defines and controls, and thus, also only logic that must be tested.
With this conclusion, I don't think it's strictly necessary for PartyKit to expose primitives like |
Hi! Thank you so much for building PartyKit! I'm enjoying it a lot so far.
I'm building a simple app with PartyKit and Remix, and I'm testing it with the new
ws
API from MSW. Due to the way a PartyKit Server is structured, there's actually nothing that prevents me from using that server class in my tests to keep the server behavior consistent. I think that'd be amazing.What I'm missing is a more developer-friendly way of creating a
Party.Room
instance. What I want to do is create a mock Room instance and implement its methods, likebroadcast
, with thews
API from MSW:This way when I do requests in my tests, I intercept them with the
game
event handler and forward them togameServer.onMessage()
:What I expect to happen here, is this:
gameServer
, which is an instance of my actual PartyKit server just implemented with the mock APIs. This allows me to have the same state and execute the same logic as my production server would.gameServer.onMessage()
. Since thebroadcast
method of the room is implemented using thegame.broadcast()
method, the connected client will receive an actual server response from thegameServer
using the interceptor. No actual servers involved while keeping the actual server's behavior.The expected usage API-wise would look like this:
Would this be something you'd like to do? I think it can improve the testing strategy of PartyKit a lot.
The text was updated successfully, but these errors were encountered: