Open kettanaito opened 1 month ago
sse(url, ({ source, server }) => {
// This creates a new EventSource request
// and propagates all the events from here
// to the underlying pending stream for `source`.
server.connect()
})
Modifying the event is similar to that in WebSockets: prevent its default and send a new event:
sse(url, ({ source, server }) => {
server.connect()
server.addEventListener('message', (event) => {
// Prevent this server event from reaching the client.
event.preventDefault()
const newEvent = modify(event.data)
source.send(newEvent)
})
})
May be a good idea to rename source
to client
and have a consistent SSE/WebSocket experience.
The tests are failing likely due to Node.js bump to v20 in CI.
Edit: Looks like an issue specific to a particular version of Node.js. Reported here: https://github.com/nodejs/undici/issues/3676
Todo
OutgoingEvents
type argument atsse()
to make type-safeevent
property on the mock payload.passthrough()
. How do you intercept an EventSource, interact with it from the mock, and then passthrough after that?withCredentials
affecting the request cookies propagation.passthrough()
? What if I want to let theEventSource
receive whichever events the actual server sends from now on? Still manual?.use()
withsse()
.retry
typeof EventSource !== 'undefined'
to let the developer know when they are usingsse()
in the environment that doesn't support it.References