-
-
Notifications
You must be signed in to change notification settings - Fork 503
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 mocking WebSocket APIs #2011
base: main
Are you sure you want to change the base?
Conversation
📦
|
Node tests on |
Supporting
|
📦
|
Roadmap
Extend.Handler
inRequestHandler
. This wayHttpHandler
andGraphQLHandler
will be assignable to typeHandler
, andArray<Handler>
can annotate both HTTP and WebSocket handlersRequestHandler
relies on caching to clone requests, parsed result, etc. Not enough common ground to reuse between it andWebSocketHandler
. WS handler is better off as a standalone class (doesn't supportonce
anyway).handleWebSocketEvent()
inSetupWorkerApi
andSetupServerApi
.instanceof RequestHandler
to skip WebSocket handlers.@mswjs/interceptors
that shipsWebSocketInterceptor
.data
argument of message listeners must be annotated across the board (includes annotating theMessageEvent
in the Interceptors).data
you receive is stillstring | Blob | ArrayBuffer
. You cannot just cast it to something else. Instead, introduce a custom parser that does that casting, as well as the runtimetypeof
checks. That's the way.pnpm test:modules:node
hangs forever onsetupServer()
without the explicitprocess.exit()
in the generatedruntime.*
scripts..use()
override tests (i.e.event.stopImmediatePropagation()
)..start()
/.listen()
calls.server.close()
API (a task for Interceptors, here just add tests).onUnhandledRequest()
(or similar) for unhandled WebSocket connections. Technically, there are no requests, so the existing method reads weird. WebSocket Support Beta #2010 (comment).broadcast()
not broadcasting from N(1) -> N+ but working from N+ -> N+. (discovered in add WebSocket + ws example examples#111) (fix(WebSocketClientManager): use localStorage for clients persistence #2127).this: WebSocket
in theclient
/server
event listeners.localStorage
(fix: fix: purge persisted clients on page reload #2133)console.log
(msw/src/core/ws/WebSocketClientManager.ts
Line 71 in f692222
event.preventDefault()
. (proof)WebSocketClientManager
still has the "first-tab-only" issue with multiple tabs.