CodeVetter
← All unpacks
CodeVetter · Repo Unpack evidence

mswjs/msw

Scanned commit 6d6aef1640 dated 2026-09-30 — last upstream commit. Generated by codevetter 1.15.0 on 2026-10-02.

github.com/mswjs/msw ↗ · 517 files · 1.4 MB

Mock Service Worker The industry standard for API mocking in JavaScript.

Deep analysis by cli:codex via the codex CLI on 2026-10-02 (448s) — every claim below links to its cited source files. Source inspection; upstream code and tests were not executed.

Overview

MSW 3.0.1 is an ESM JavaScript library for describing mocked HTTP, GraphQL, WebSocket, and Server-Sent Events behavior during development and testing. Browser and Node setup APIs share a network-source, frame, and handler pipeline, while browser HTTP interception crosses a Service Worker message channel and Node interception uses @mswjs/interceptors. The inspected implementation also provides scoped Node handler overrides, persistent browser mock cookies, cross-runtime WebSocket clients, a worker-installation CLI, and Vite integration.

System map

The package exposes separate environment and protocol entrypoints around one shared network engine. Browser HTTP interception uses a Service Worker when available, with an interceptor fallback; WebSocket interception remains a separate source. Node combines four interceptor types and adds asynchronous handler contexts. Distribution consists of ESM modules, declarations, an IIFE bundle, and a generated worker asset, with release automation targeting npm.

Feature catalog

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.

Data flow

Sources normalize intercepted traffic into protocol frames before shared resolution. HTTP handlers parse matching inputs and invoke resolvers in order, with handler state owning one-time and generator behavior. Browser response transport serializes across worker ports, whereas Node responds through interceptor controllers. Cookies and WebSocket client metadata have distinct persistence paths, and SSE sends encoded frames through a ReadableStream.

Behavior traces

The following traces follow concrete startup, response, persistence, isolation, and reload paths through the inspected source. Browser startup waits for worker activation and a client confirmation before returning a registration. HTTP resolution distinguishes explicit bypass, unhandled traffic, fallthrough, and mocked responses. Node boundaries and browser persistence preserve different kinds of state, while Vite serializes network changes around hot updates.

Testing signals

Tests and CI were inspected, not executed; their existence does not establish a passing result. Vitest separates unit, Node, browser, memory, typings, and CLI suites, while Playwright handles page lifecycle and multi-tab scenarios. Read assertions cover several important persistence, isolation, streaming, and teardown branches. This is a bounded inspection, and configured browser coverage is Chromium rather than evidence of cross-browser parity.

Risk map

These are source observations and explicitly marked hypotheses, not confirmed vulnerabilities. Network passthrough, persistent cookies, worker messaging, and serialized handler exceptions are the principal security-sensitive boundaries inspected. Shared lifecycle and streaming code has a broad behavioral impact, with regression tests documenting past failure modes. Documentation and automation also contain drift that should be verified before relying on their instructions.

Extension points

The experimental API exposes the same source/frame abstractions used by the built-in environments. Handler factories, custom predicates, controllers, and sibling graphs provide additional composition boundaries. WebSocket extensions can change both runtime messages and inferred APIs. Storage implementations and Vite hooks are identifiable implementation seams, with public export/build configuration determining what consumers can import.

Contributor handoff

Start with current manifests and the shared network engine, then follow the affected environment and protocol boundary. Tests and CI were inspected, not executed; this brief provides no passing checks or exhaustive coverage assessment. Existing scripts and filename conventions identify focused checks for a later task that authorizes execution. Preserve worker protocol compatibility, handler ordering, cleanup semantics, and build/export boundaries when making small changes.

Languages

LanguageFilesShare of source
TypeScript44398%
JSON21docs/config
YAML12docs/config
JavaScript92%
Markdown9docs/config
HTML7docs/config
Shell10%

Start reading here

Probable source entrypoint: src/ — inferred from the directory tree and manifest, not the upstream docs.

Source roots

src/ (166 files)

Repository structure

Top-level pathFiles
test/298
src/166
media/12
.github/11
config/4
decisions/4
cli/3

Docs found: CONTRIBUTING.mdLICENSE.mdREADME.md

Package

package.json — msw v3.0.1, 54 declared dependencies.

@commitlint/cli@commitlint/config-conventional@epic-web/test-server@fastify/websocket@graphql-typed-document-node/core@inquirer/confirm@msw/url@mswjs/interceptors@ossjs/release@playwright/test@types/express@types/json-bigint

CI & config entrypoints

Structural health signals

Average score 8.9/10 across 96 analyzed source files; 6 hotspots surfaced.

These are deterministic review leads — size, churn, and structural signals — not proof of a bug in this project.

Recent history