David

Results 284 comments of David

Something like this? ```kotlin @Test fun `sending json works`() = TestUtil.test { app, http -> app.sse("/sse") { it.sendEvent(event, SerializableObject()) it.close() } assertThat(http.sse("/sse").get().body).contains("""data: {"value1":"FirstValue","value2":"SecondValue"}""") } ```

@Incognitowski the `testtools` artifact is different from the internal test util: ``` fun sse(path: String) = Unirest.get(origin + path).header("Accept", "text/event-stream").header("Connection", "keep-alive").header("Cache-Control", "no-cache").asStringAsync() ``` I guess we could add something like...

You need to call `.close()` too. Did you try that?

> I have to say, though, that I'm not happy with the solution, my idea was to test it like you would consume it with an EventSource on the client...

I tried to set something up with `okhttp-sse`, but that client is not documented at all. There appears to be some code here: https://github.com/square/okhttp/issues/5544

Great, looking forward to it.

Could you publish this as a PR? A bit easier to have a look then :)

@Incognitowski After changing `JavalinTest.test(app)` to just `JavalinTest.test`, I had no trouble running your tests.

@Incognitowski I rewrote a bit: ```kotlin @Test fun `testing SSE`() = JavalinTest.test { server, client -> val listOfEvents = mutableListOf() client.sse("/parameter/listen") { listOfEvents.add(it.data) if (listOfEvents.size == 5) { it.closeClient() assert(true)...

Hmm.. not sure if the test is testing...