WebSocket support for Mock engine
See original GitHub issueSubsystem
Client (Mock
engine), WebSocket
Is your feature request related to a problem? Please describe.
Currently there is no WebSocket
support for the Mock
engine on the client part. This could be particularly useful when testing clients that interact with WebSockets.
Describe the solution you’d like
I think there should be a method inside the Mock
engine that allows to setup a proper WebSocket mock. This could be something like
private val client = HttpClient(MockEngine) {
engine {
addWebSocketHandler(host = "localhost", port = 8080, path = "/ws") { incoming, outgoing ->
}
}
}
Motivation to include to ktor This feature could be useful to all the people that want to test a client that interacts with a websocket without having to spin one up.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:11
- Comments:5 (1 by maintainers)
Top Results From Across the Web
jest-websocket-mock - npm
jest-websocket-mock exposes a WS class that can instantiate mock websocket servers that keep track of the messages they receive, and in turn can ......
Read more >The WebSocket API (WebSockets) - Web APIs - MDN Web Docs
desktop desktop
Chrome Edge
WebSocket Full support. Chrome4. Toggle history Full support. Edge12. Toggl...
WebSocket() constructor Full support. Chrome4. Toggle history Full support. Edge12. Toggl...
Read more >Is there any way to mock a request for websocket
I am writing a test method to verify the application removing all the external dependencies. I am using Fiddler to intercept the request...
Read more >Testing Sails sockets using Jest - Medium
This web app uses Sails to handle requests and sockets. Sails uses SocketIO behind the scenes, and I found this library jest-websocket-mock ......
Read more >Socket.IO
In most cases, the connection will be established with WebSocket, providing a low-overhead communication channel between the server and the client.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@e5l This issue seems to be about websocket client testing, and you closed this issue out mentioning it is supported with the
withTestApplication
function… I could be missing something butwithTestApplication
seems to be pretty focused on the ktor server testing as it requires an Application.method to be provided. I looked and couldn’t find any client-only focused mock engines that support websockets. The current docs (v1.6) still recommend usingMockEngine
withHttpClient
, butMockEngine
doesn’t seem to support websockets as far as I can tell.Are you aware of any client-only websocket testing library besides OkHTTP’s
MockWebServer
? If so can you please point me in the right direction? For context, I have JVM-hosted websocket client that needs to consume a third party service over websockets and I’m not finding helpful examples that are unit testable. I was hoping to find something that doesn’t require running a server to test the client code - something similar to ktor’s HttpClient+MockEngine that makes it possible to test client code without running a server.If you aren’t aware of any libraries fitting my description I wonder if it could be helpful to reopen this issue?
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.