CodeVetter · Repo Unpack · Feature catalog
mswjs/msw
Users describe network behavior through protocol factories and standard Request/Response objects. The public APIs support runtime overrides, lifecycle observation, explicit real-network traffic, and handler cleanup. GraphQL subscriptions and SSE provide imperative streaming controls, while WebSocket links expose clients and broadcast operations. CLI and Vite integration supply the browser worker through different installation paths.
- http provides all, head, get, post, put, delete, patch, and options factories; HttpHandler accepts URL paths, regular expressions, or asynchronous predicates returning matches and optional params.
- HttpResponse decorates standard responses for mock cookies and supplies text, JSON, XML, HTML, and ArrayBuffer helpers; text and JSON helpers calculate Content-Length unless supplied explicitly.
- graphql.link(url) supplies endpoint-scoped query, mutation, operation, and subscription factories; selectors include names, RegExp, DocumentNode, typed document strings, and custom predicates.
- GraphQL subscriptions expose publish, iterable-based from, error, complete, and passthrough controls; from publishes each yielded value without automatically completing the subscription.
- ws.link exposes clients, connection listeners, broadcast, and broadcastExcept; optional ordered extensions transform the message domain and add APIs to connection events, while ws.onUpgrade is replaceable.
- sse(path, resolver) matches GET requests accepting text/event-stream and supplies client send/error/close controls plus server.connect for forwarding an actual upstream stream.
- Worker/server APIs expose events, use, resetHandlers, restoreHandlers, and listHandlers; Node adds boundary, while utilities provide bypass, passthrough, direct getResponse, and numeric/real/infinite delays.
- msw init supports a destination, --cwd, --save, and saved worker directories; msw/vite provides auto or worker-only modes, virtual:msw, development worker serving, and conditional client-build worker emission.