qmetrics.net

MSW

JavaScript API mocking through network-level request interception

Mock Service Worker lets you define HTTP mocks once and reuse them in browsers and Node.js. Applications keep calling real APIs while responses are substituted at the network layer.

Overview

Mock Service Worker (MSW) is a JavaScript library for API mocking in browsers and Node.js. You describe request handlers once and wire them through either a Service Worker in the browser or a Node interception layer, so application code still performs real fetches while selected traffic receives mocked responses.

In the browser, MSW uses the Service Worker API to intercept outgoing requests after they leave your application. Handlers can target REST, GraphQL, server-sent events, and WebSocket traffic. Mocks can appear in developer network tools because the request path stays intact rather than replacing client HTTP code with stubs.

On Node.js, MSW provides setupServer with the same handlers, using a low-level interception approach because Service Workers are unavailable there. The same definitions can support local development, debugging, unit tests, integration tests, and browser end-to-end tooling such as Vitest and Playwright fixtures.

The library emphasizes client-agnostic handlers built around familiar Fetch-style APIs, so mocks are not tied to a single HTTP client. Optional companion projects mentioned in upstream materials include generating handlers from OpenAPI or HAR, data tooling, and serving handlers as HTTP middleware in frameworks like Express, Hono, and Fastify.

Key features

  • Browser Service Worker interception
  • Node.js setupServer API
  • Shared handlers across environments
  • REST, GraphQL, SSE, and WebSocket mocks
  • Playwright network fixture support
  • Storybook addon integration
  • Express server boundary scoping
  • Fetch-oriented handler syntax

Use cases

  • Frontend development without live backends
  • Automated tests with stable network behavior
  • Prototyping API contracts before they exist
  • Debugging UI against error and edge responses
  • End-to-end tests with realistic request paths

Tags

Similar software

Keploy

Record-and-replay API and integration testing from traffic

Keploy captures API calls, database queries, and streaming events, then replays them as tests and dependency mocks without changing application code.

★ 20k⟳ todayApache-2.0

GoReplay

Capture and replay live HTTP traffic

GoReplay records HTTP from network interfaces and replays it to test servers for shadowing, load testing, and debugging. It runs as a command-line daemon without in-path proxy changes.

★ 19.3k⟳ 1 year agoGPL-3.0 · open core
API Development & TestingNo commits in 18+ monthsDesktop/CLI app

supertest

Node.js HTTP server testing via superagent

Supertest offers a fluent API for asserting HTTP behavior against Node.js servers during automated tests. It builds on superagent so you can express status, headers, and body expectations in code.

★ 14.4k⟳ 21 days agoMIT

MeterSphere

Open continuous testing platform with built-in AI assistant

MeterSphere is an open continuous testing tool with AI-assisted case generation, test management, and API testing for teams. It uses a system-organization-project hierarchy for collaboration.

★ 13.7k⟳ 1 month agoGPL-3.0

Karate

Unified open-source test automation framework

Karate combines API testing, mocks, performance testing, and UI automation in one framework with a readable syntax. Tests run via JUnit, a CLI, or CI/CD with parallel execution.

★ 9k⟳ 2 days agoMIT

Mockoon

Local desktop and CLI tools for REST API mocking

Mockoon lets you design and run mock HTTP APIs on your machine without cloud accounts. A desktop app handles editing; a CLI runs mocks in CI, Docker, and serverless setups.

★ 8.5k⟳ 2 days agoMIT