WebSocket Test examples
Are there any examples of test automation using websockets against a worker ? Don’t see any among https://developers.cloudflare.com/workers/testing/vitest-integration/recipes/ wondering how this is done
Cloudflare Docs
Recipes and examples
Examples that demonstrate how to write unit and integration tests with the Workers Vitest integration.
3 Replies
I have started to work through this myself and have run into various issues along the way. @Kevin had a message in the itty servers that really helped me get started and over the biggest hurdle I was having: He noted that to return web sockets from DurableObjects it can only be done through the fetch call -- others via the RPC mechanism fail because it can't serialize the WebSocket. I had been staring at that error message for hours not really understanding what I was doing wrong from my 'createWebSocket' method.
The other keys of course are paying attention to the "Known Issues" page at: https://developers.cloudflare.com/workers/testing/vitest-integration/known-issues/ identifying that using WebSockets with Durable Objects needs the isolatedStorage flag set to false (which implied that it was possible to test WebSockets with the vitest integration). But I've spent a couple hours this weekend to get to something that works for my testing needs.
I did post up some examples for anyone else looking for something like this:
https://github.com/darsovit/cf-durable-object-testing
GitHub
GitHub - darsovit/cf-durable-object-testing: Cloudflare Durable Obj...
Cloudflare Durable Object Unit Testing Examples. Contribute to darsovit/cf-durable-object-testing development by creating an account on GitHub.
ohhh thank you for that hint at Response.webSocket