stomp-js / stompjs

Javascript and Typescript Stomp client for Web browsers and node.js apps
Apache License 2.0
737 stars 80 forks source link

Options for Mock Stompjs Server #382

Open IgnacioHR opened 2 years ago

IgnacioHR commented 2 years ago

Hello,

I'm missing a Mock Stomp Server that can be used to automate tests with jest. And documentation about how to write basic tests.

I've already tested https://github.com/rufusraghunath/js-stomp-utils/tree/master/packages/mock-stomp-broker with no success. The issue will be reported in that repository.

Thank you in advance!

kum-deepak commented 2 years ago

I know it makes a lot of sense to have a mock stomp broker.

For testing this library I needed one, at that time I could not find any reasonable one, so, ended up using a complete RabbitMQ server. To simulate errors (like missing heartbeats), I use a wrapper over the WebSocket which can alter (or eat away) responses. See the specs folder and the Doockerfile to check the current setup.

If one wants to use this code as a base, they can use quite a lot of classes, like Frame, Parser, etc. to implement a Mock broker. That would additionally allow mocks to run within even the browser (without using a TCP port). This will make tests run much faster.

If you would like to attempt and need details, please let me know.

sergiykh commented 2 years ago

@IgnacioHR We are using https://github.com/rufusraghunath/js-stomp-utils/tree/master/packages/mock-stomp-broker in our e2e tests. It works fine to mock stomp responses.