Industry standard API mocking for JavaScript.
18k
Stars
612
Forks
42
Open issues
30
Contributors
AI Analysis
Mock Service Worker (MSW) is an industry-standard API mocking library for JavaScript that intercepts requests at the network level using the Service Worker API, allowing developers to mock APIs in browsers and Node.js without modifying application code. It serves developers building and testing web applications who need realistic API mocking with Express-like routing syntax, and is particularly valuable for teams practicing test-driven development or working with APIs that don't yet exist. It...
Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.
AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.
MSW intercepts HTTP at the network level, enabling seamless API mocking across browser and Node.js without touching application code
Mock Service Worker (MSW) solves the problem of realistic API mocking in JavaScript applications by intercepting requests at the network layer — using Service Workers in the browser and a custom interceptor in Node.js. This means application code, including fetch calls and third-party HTTP clients, runs unmodified. It targets frontend developers and testing engineers who want a single, environment-agnostic mock definition reusable across unit tests, integration tests, E2E tests, and local development. With 18K+ stars, endorsements from Kent C. Dodds, Egghead courses, and broad ecosystem integration, MSW has achieved genuine mainstream adoption in the JavaScript frontend testing community.
Created in November 2018, MSW introduced Service Worker-based HTTP interception as an alternative to stub-based mocking. It matured through major version releases, adding Node.js support via a low-level interceptor layer, and converged on a unified handler API across environments.
Growth was driven by endorsements from high-profile JavaScript educators (Kent C. Dodds, Testing Library community), its seamless Developer Experience — mocks appear in browser DevTools — and the shift toward integration testing in React/Vue/Angular ecosystems. The reuse of handlers across all environments reduced duplication costs, making adoption sticky once started.
Widely referenced in the React Testing Library and Vitest communities. Endorsed publicly by Kent C. Dodds. Egghead courses indicate commercial ecosystem investment. The 612 forks and 18K stars on a testing-focused library (which typically see lower star counts than UI libraries) indicate substantial real-world usage. npm download data is not available in this metadata, but community evidence strongly suggests production-scale adoption.
Appears to follow a dual-runtime architecture: browser integration uses the native Service Worker API to intercept outgoing requests at the network level, while Node.js integration uses a separate low-level interceptor package (mswjs/interceptors) that patches Node.js HTTP internals. Both environments share the same request handler definitions written with an Express-like routing API. Likely TypeScript-first throughout, given the repository language.
Not documented in README, but the existence of a dedicated examples repository and Egghead courses suggests the project has practical usage scenarios well-covered. Internal test coverage cannot be confirmed from available metadata.
Last push was 2026-05-15, roughly 6 weeks before the evaluation date — indicating active, ongoing maintenance. The project has a Discord server, official documentation site, and commercial partnership with Egghead, all of which are positive sustainability signals. Star velocity of ~34/week is moderate but consistent for a mature library, not a sign of stagnation.
ADOPT IF: you are building a JavaScript/TypeScript frontend or full-stack application and want a single mock definition reusable across browser-based development, unit tests, integration tests, and E2E tests without modifying application code or stubbing individual HTTP clients. AVOID IF: your mocking needs are primarily server-side backend contract testing in a non-JavaScript ecosystem, or you need a shared persistent mock server accessible by multiple services simultaneously. MONITOR IF: you rely on Service Worker availability in environments where it may be constrained (certain CI headless setups, embedded WebViews, or server-side rendering frameworks with unconventional fetch handling).
Independent dimensions
Mainstream potential
8/10
Technical importance
9/10
Adoption evidence
8/10
- Service Worker API requires HTTPS or localhost, which may complicate some CI or staging environments that serve over plain HTTP.
- The dual-runtime architecture (browser vs. Node.js) means subtle behavioral differences between environments remain possible, requiring developers to understand both execution paths.
- Project sustainability depends significantly on a small core maintainer team; the Discord and Egghead partnerships help, but bus-factor risk is non-trivial for an open source project of this scope.
- As JavaScript runtimes (Deno, Bun, edge workers) diversify, maintaining consistent interception behavior across all targets may increase maintenance burden.
- Network-level interception provides high realism but may make it harder to simulate certain low-level transport errors or partial response scenarios compared to in-process stub libraries.
MSW is likely to consolidate its position as the default API mocking tool in the React and broader JavaScript frontend testing ecosystem. Expansion to edge runtime environments and WebSocket mocking (already underway per README) will likely sustain growth at a moderate, stable pace.
Newsletter
Get analyses like this every Monday
Free weekly digest of the most interesting open-source discoveries.
Languages
Information
- Website
- https://mswjs.io
- Language
- TypeScript
- License
- MIT
- Last updated
- 2d ago
- Created
- 93mo ago
- Analyzed with
- anthropic/claude-haiku-4-5
Stars over time
Contributors over time
Top 100 contributors only — repos with more will plateau at 100.
Open issues
Vitest isolation breaks setupWorker in firefox
Two `setupServer()` instances listening at once evaluate every request's handlers twice on Linux — "TypeError: Body is unusable" during handler lookup
Visit website with domain, cause Refused to set unsafe header "cookie"
Unhandled QuotaExceededError in CookieStore.persist() can crash request handling
🔒 Prototype pollution via user-controlled multipart GraphQL `map` paths
Top contributors
Similar repos
| Repository | Stars | Week Δ | Language | Score | Updated |
|---|---|---|---|---|---|
|
|
18k | +22 | TypeScript | 9/10 | 2d ago |
|
|
1.1k | — | TypeScript | 8/10 | 2w ago |
|
|
7.3k | — | Java | 8/10 | 2d ago |
|
|
8.3k | — | TypeScript | 8/10 | 4d ago |
|
|
5.5k | — | JavaScript | 7/10 | 11mo ago |
|
|
2.7k | — | JavaScript | 7/10 | 2w ago |
Mirage intercepts requests by replacing fetch/XMLHttpRequest in-process, meaning it operates inside the application boundary. MSW intercepts at the network level, leaving application code unmodified. MSW's approach provides higher testing confidence and works with any HTTP client without adapters. Mirage has a longer history but appears to have slower recent growth.
WireMock is a standalone server-based mock, primarily Java-ecosystem oriented. It requires running a separate process and is well-suited for microservice contract testing. MSW is co-located with JavaScript code and requires no separate process, making it more ergonomic for frontend-centric workflows. Different primary audiences.
Mockoon is a GUI-based standalone mock server targeting teams who want a no-code or low-code interface for API simulation. MSW is code-first and integrates directly into test suites. Mockoon is better for shared team mock servers; MSW is better for developer-local test isolation.
nock is a Node.js-only HTTP interception library that patches Node's http module. MSW covers both browser and Node.js with shared handler definitions. nock is more established for pure Node.js backend testing but cannot be reused in a browser environment.
A narrow-scope tool that mocks AWS SDK calls specifically. MSW is a general-purpose HTTP interceptor. These tools target different problems and are not direct competitors; aws-sdk-mock may complement MSW in AWS-heavy projects.
