Are there any known practices for writing contract...
# general
j
Are there any known practices for writing contract tests for websockets? And crucially, do these kinds of contracts work with pact stub server?
Like can I open a websocket connection with pact stub server and get the expected messages back to my front end consumer?
m
There are really two approaches:
1. Treat them as a message pact and ignore the transport 2. Write a plugin (so you can test the transport) (1) is your best bet, but we’d love to see a websocket plugin created. There was somebody in the community who created one, I’ll see if I can dig up the name, but they weren’t able to open source it sadly
j
thank you! I will look into this
do we have someone that was able to take this websocket pact and serve it up successfully on pact-stub-server? That's the main use case I need to support to make it work with cypress, since cypress doesn't have a good websocket plugin
a
Hi, yes we created a plugin for this, written in rust. I agree with Matt, plugin is the best option if you have request-response based interactions. We didn't feel async message pacts really covered our use case appropriately. The plugin doesn't technically use the pact-stub-server as we used the plugin to add a new transport. So our plugin stands up a websocket server that stands in for the pact-stub-server in unit tests and then stands in for the websocket client during provider verification. It took a couple of months for one engineer to create but it works really well and we have successfully been using it to create contracts and verify contracts. I have been trying to get it open-sourced for nearly 8 months now. Its just taking a lot longer than anyone would want. I can talk through the process/logic of it all. But I am not allowed to release the source code at this time.
thankyou 1
m
Plugins are currently not supported on the stub server to my knowledge - is that right @uglyog?
I have been trying to get it open-sourced for nearly 8 months now. Its just taking a lot longer than anyone would want. I can talk through the process/logic of it all. But I am not allowed to release the source code at this time. (edited)
thanks for trying! You could always do what Ron did - just open source it and see who yells at you (this was how Pact was open-sourced, at least according to lore…)
😂 1
j
Was it the "stop that" kind of yelling or the "formally worded cease and desist" kind of yelling?
😆 1
a
Tbh I have been tempted to just try open sourcing it and see what happens but I'm not convinced that I'm valuable enough to the company to protect my job if they get upset 😅 Due to this prompt, I have renewed my efforts and trying a different route through the corporate jungle. Let's see if this route is any clearer
😆 1
🙏 1