Socket.io integration tests with Mocha & Chai
Socket.io is an event-based framework which allows bidirectional communication, an abstraction layer on WebSockets technology, utilizing the Publish/Subscribe pattern. Clients can connect to a socket using the browser and communicate with other connected sockets on real time, without worrying about compatibility and underlying mechanisms, as they are handled gracefully by the framework.
You can build real time applications really easy, like chat applications or interactive games and won't have to worry about the device or browser and how connections are made, socket.io is the jQuery of WebSockets, it just take care of them for you.
That is all good, but no code is complete without tests. Tests are essential, every piece of code that is meant to go to production must be tested in order to ensure quality, stability and future maintenance. No software is "deploy once and forget", like all things around us evolve over time, so as software. Tests will make sure that the evolution will continue in a predictable and safe manner, else software's life is at stake.
In this article I am going to talk about integration tests on socket.io, how to author them and which considerations you should take. Because of socket.io's nature, tests are written in an asynchronous style, something little bit different from the linear execution ones that most people are used to, so I leverage Jasmine's power to support asynchronous tests in order to complete my mission. Lastly, my test runner of preference is Mocha, which does a great job on Node.js tests and my assertion library is Chai, which let's me choose my favorite style to test, either BDD (Behavioral Drive Development style) or TDD (Test Driven Development style).
For the rest of the article, please follow this link on my personal site.
If you did enjoy the read, please like, share or tweet.
Follow me on Twitter @giorgosdyrra.