Comments (2)
I have a proof of concept functional at kettanaito/tug-o-war@00bdfa6! It reuses my GameServer
PartyServer instance in a test to rely on the same behaviors I do in production. I believe this is the way to go regarding testing. Also touches on what we've discussed over our call, @threepointone, regarding how to emulate behaviors in tests.
If we can provide a better experience around the Room and Storage APIs that'd be incredible. Currently, I mock the Room
object and it's not nice 😬:
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 storage
, broadcast
can cover most of the test cases (and the Room
class can manage connections
, getConnection()
, getConnections(
, etc. internally; I get a feeling that's what it does anyway now). The important bit is that an interceptor can forward client events (and server events from the actual PartyServer) to the tested code.
from partykit.
Updates
Okay, 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 pull
event 10 times from the client and on the 10th time the server sends a finish
event. This sounds like a logic crucial to have in a test. But in reality, it's not. It doesn't belong in the test.
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 pull
must result in finish
is server's logic, not the client's. Thus, to efficiently test the client in this scenario, what you should do is this:
- Test that doing an action results in the
pull
event being sent. - Test that once the server sends a
finish
event, your client transitions into the correct state.
In the end, those are precisely the logic that the client defines and controls, and thus, also only logic that must be tested.
Now, you'd still test the actual 10 pulls -> complete in an end-to-end test with the actual/test WebSocket server running. My comments relate purely to integration-level testing.
With this conclusion, I don't think it's strictly necessary for PartyKit to expose primitives like Room
for testing. I have achieved a decent integration test coverage without those primitives and without relying on PartyKit at all. Take a look at the example test suite here:
from partykit.
Related Issues (20)
- `usePartySocket`/`useYProvider` should default to `host: window.location.host` HOT 1
- `socket.updateProperties()` overrides `party` HOT 1
- Feature request: Add rawProtocol param for y-partykit HOT 6
- Bun not working HOT 3
- bug: deploy - windows compatibility issue for wasm files HOT 2
- use npm: specifiers in partykit.json for main/parties
- Fine-grained Permissions possible? HOT 1
- Y.js V2 Update Format HOT 4
- PartySocket.fetch -- docs and host param
- This expression is not constructable HOT 1
- PartyKit Quickstart fails to open on macOS HOT 5
- Memory leak in "partykit dev" (runBuild) HOT 5
- Cannot use @jupyterlab/services: setImmediate is not defined
- Updating `Y.Doc` server-side HOT 5
- Very high number of Internal errors
- Load environment variables from alternate .env files
- CLI dev --tunnel flag to auto create Cloudflare Tunnel HOT 1
- [idea] Use Content Defined Chunking For Storing Yjs
- (might be a y-prosemirror issue) Unable to update a yjs doc via YPartykitProvider from outside of prosemirror
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from partykit.