Nice way to test websocket server using mocha/chai?

This question may be stemming from general newness to the whole NodeJs ecosystem, apologies if it's not too specific to colyseus. I have a general understanding of how Mocha/Chai testing works and have run tests on another project in the past. But with the presence of a websocket server and asynchronous state patches flying around I'm not sure of a good testing paradigm for a colyseus game engine. I am working on an entirely turn-based game, so careful checks of timing is not an issue, I would just like to check that my messaging system and state updates work as expected based on the desired game logic. Any suggestions?

So far I have set up a simple MyRoom.test.js script that starts up a colyseus server and makes colyseus.js clients. I can test simple connecting / room creation using async Mocha/Chai tests. I'm a bit stuck on how to check for state updating the way I expect it to, since this is asynchonously patched.

Hi @gkanwar, the way I usually approach it is by unit testing the structures that will be inside your Room implementation. I usually do not do end-to-end testing with real WebSocket connections.

For a card game I've been working on, I manually trigger a @colyseus/command (or other patterns of your choice) to manipulate the state, and then perform some assertions on the mutated state.

Both server-side and client-side of Colyseus have been evolving, and by doing end-to-end testing it's likely that you'll need to re-do a lot in order to upgrade to a newer version. (version 0.13 is coming soon!)

Hope this helps, cheers!

Thanks @endel! Good to know that I should not rely on specifics of the server-client dynamics of Colyseus. I guess this is good encouragement to move all the random tidbits of game logic in my Room into other classes that are testable.

By the way, are there any good open source examples of card games built on top of Colyseus? It would be helpful to see some examples of good server code architecture.

Thanks!

@Zielak have been working on one for quite some time 👀 https://github.com/Zielak/cardsGame