npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mockmaster/msw-adapter

v1.0.5

Published

MSW integration adapter for mock-master

Downloads

26

Readme

@mockmaster/msw-adapter

Record & replay HTTP requests for deterministic testing

Part of the mock-master monorepo.

Installation

npm install @mockmaster/msw-adapter

Features

  • Record & Replay - Capture real API responses and replay them
  • Scenario Management - Organize recordings into reusable scenarios
  • Persistence - Serialize/deserialize scenarios as JSON
  • Type Safe - Full TypeScript support
  • Deterministic - Replay the same responses every time

Usage

Create a Scenario

import { createScenario } from '@mockmaster/msw-adapter'

const scenario = createScenario('my-api', 'Production API responses')

Record Requests

import { createRecording, addRecordingToScenario } from '@mockmaster/msw-adapter'

// Create a recording
const recording = createRecording(
  {
    method: 'GET',
    url: 'https://api.example.com/users',
    path: '/users',
    timestamp: Date.now(),
  },
  {
    status: 200,
    body: [
      { id: 1, name: 'John Doe' },
      { id: 2, name: 'Jane Smith' },
    ],
    headers: { 'Content-Type': 'application/json' },
    timestamp: Date.now(),
  }
)

// Add to scenario
const updatedScenario = addRecordingToScenario(scenario, recording)

Replay Requests

import { createReplayHandler } from '@mockmaster/msw-adapter'

// Create replay handler
const handler = createReplayHandler(scenario)

// Replay a request
const response = handler({ method: 'GET', path: '/users' })

console.log(response)
// {
//   status: 200,
//   body: [{ id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Smith' }],
//   headers: { 'Content-Type': 'application/json' }
// }

Persist Scenarios

import { serializeScenario, deserializeScenario } from '@mockmaster/msw-adapter'

// Serialize to JSON string
const json = serializeScenario(scenario)

// Save to file (use with @mockmaster/cli or fs)
// await writeFile('scenario.json', json)

// Deserialize from JSON
const loaded = deserializeScenario(json)

API

Scenario Management

  • createScenario(name: string, description?: string): Scenario - Create a new scenario
  • addRecordingToScenario(scenario: Scenario, recording: Recording): Scenario - Add recording to scenario

Recording

  • createRecording(request: RecordedRequest, response: RecordedResponse): Recording - Create a recording

Replay

  • createReplayHandler(scenario: Scenario): ReplayHandler - Create a replay handler
  • handler(request: { method: string, path: string }): RecordedResponse | undefined - Replay a request

Persistence

  • serializeScenario(scenario: Scenario): string - Serialize to JSON
  • deserializeScenario(json: string): Scenario - Deserialize from JSON

Complete Example

import {
  createScenario,
  createRecording,
  addRecordingToScenario,
  createReplayHandler,
  serializeScenario,
} from '@mockmaster/msw-adapter'

// 1. Create scenario
let scenario = createScenario('user-api', 'User management endpoints')

// 2. Add recordings
const getUsers = createRecording(
  { method: 'GET', url: 'https://api.example.com/users', path: '/users', timestamp: Date.now() },
  { status: 200, body: [{ id: 1, name: 'John' }], timestamp: Date.now() }
)

const createUser = createRecording(
  { method: 'POST', url: 'https://api.example.com/users', path: '/users', timestamp: Date.now() },
  { status: 201, body: { id: 2, name: 'Jane' }, timestamp: Date.now() }
)

scenario = addRecordingToScenario(scenario, getUsers)
scenario = addRecordingToScenario(scenario, createUser)

// 3. Save to JSON
const json = serializeScenario(scenario)
console.log('Saved:', json)

// 4. Replay later
const handler = createReplayHandler(scenario)

const response1 = handler({ method: 'GET', path: '/users' })
console.log('GET /users:', response1)

const response2 = handler({ method: 'POST', path: '/users' })
console.log('POST /users:', response2)

Use Cases

  • Integration Tests - Replay recorded API responses for consistent tests
  • Offline Development - Work without network access
  • Contract Testing - Verify client behavior against recorded responses
  • Demo Environments - Present apps without live backend

Related Packages

  • @mockmaster/cli - File system operations for saving/loading scenarios
  • @mockmaster/openapi - Generate scenarios from OpenAPI specs
  • @mockmaster/core - Low-level mocking utilities

Links

License

MIT