-
-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support server-sent events (SSE) #2299
base: main
Are you sure you want to change the base?
Conversation
Augmenting actual server-sent eventssse(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 |
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: nodejs/undici#3676 |
Test updateI've resolved the infinite request issue that failed the majority of SSE tests (was using legacy passthrough header; migrating to Two tests are still failing, both seem to be related to errors. There's an odd rogue |
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