adonis-websocket icon indicating copy to clipboard operation
adonis-websocket copied to clipboard

Automated websocket testing

Open CodingDive opened this issue 6 years ago • 1 comments
trafficstars

Hey there, we've started adding websockets into our project a few days ago and I really enjoy using it. The API turned out to be great and being able to have middleware is amazing.

Our websocket use case is mostly very unidirectional from Server to Client. Let me give you an example:

  1. User A sends a RESTful request to the Server
  2. Server persists some things into the database and performs other actions.
  3. Server then needs to notify Users B, C that something has changed.

As of now, all my REST api tests are api endpoint tests using trait('Test/ApiClient') and the testing experience + code confidence are incomparable to any other tests I write.

Ideally, I would like to also have a SocketClient trait so that I can register a fake socket Client to a channel, send some HTTP requests and then assert the messages received by my mocked socket Client.

Is there a better way of testing this and how would I go about mocking the Socket Client (which typically runs in the Browser) in node?

CodingDive avatar May 24 '19 10:05 CodingDive

The testing section for sockets is also missing from the docs for which I'll happily send a PR.

CodingDive avatar May 24 '19 10:05 CodingDive