Add some test and fix a rare network condition that caused a crash

I am opening this branch to fix #18. In the process, I have added some test to reproduce my bug and added some very simple tests on basic features.

This will need to be expanded but it sets the base for a test infrastructure.

This is not quite ready to be merged yet, I need to double-check that my fix works and does not have any side-effect but I am opening this pull-request to discuss it with you guys ( ping @tmeasday / @emgee3).

FYI - I am using rewire and sinon (new dependencies) to mock WebSocket.