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

@waitkit/msw

v0.1.3

Published

Waitkit delay/error/timeout simulation for MSW handlers.

Downloads

355

Readme

@waitkit/msw

MSW handler wrapper for applying Waitkit delay, error, and timeout simulation.

@waitkit/msw wraps MSW v2 resolver functions so Waitkit rules run inside the MSW handler pipeline — no globalThis.fetch patching needed.

Requirements

  • msw v2 or later
  • @waitkit/core v0.3 or later (installed automatically)

Installation

npm install -D @waitkit/msw
# or
pnpm add -D @waitkit/msw
# or
yarn add -D @waitkit/msw
# or
bun add -D @waitkit/msw

Usage

withWaitKit(rule, resolver)

Wraps an MSW resolver with a WaitKitMswRule. The rule is evaluated before the resolver runs: delay first, then timeout, then error.

import { http, HttpResponse } from 'msw';
import { withWaitKit } from '@waitkit/msw';

export const handlers = [
  // 1.5 second delay before responding
  http.get(
    '/api/users',
    withWaitKit({ delay: 1500 }, () => HttpResponse.json([{ id: 1, name: 'Alice' }])),
  ),

  // 30% chance of a 500 error
  http.post(
    '/api/orders',
    withWaitKit(
      { errorRate: 0.3, errorResponse: { status: 500, body: { message: 'Server Error' } } },
      async ({ request }) => {
        const body = await request.json();
        return HttpResponse.json({ id: 99, ...body });
      },
    ),
  ),

  // always timeout after 3 seconds
  http.get(
    '/api/slow',
    withWaitKit({ timeoutRate: 1, timeoutMs: 3000 }, () => HttpResponse.json({})),
  ),
];

WaitKitMswRule

A subset of WaitKitRule without url and method. MSW handlers already know their URL and method, so those fields are not needed.

import type { WaitKitMswRule } from '@waitkit/msw';

const slowNetworkRule: WaitKitMswRule = {
  delay: [800, 2000], // fixed ms or [min, max] range
  errorRate: 0.2, // probability of error (0–1)
  errorResponse: {
    status: 503,
    body: { message: 'Unavailable' },
  },
  timeoutRate: 0, // probability of timeout (0–1)
  timeoutMs: 5000, // timeout duration in ms (default 30000)
};

Switching scenarios with server.use()

Use MSW's server.use() to override handlers at runtime.

import { server } from './msw-server';
import { http } from 'msw';
import { withWaitKit } from '@waitkit/msw';

// activate slow-network scenario
server.use(
  http.get(
    '/api/*',
    withWaitKit({ delay: 2000 }, ({ request }) => fetch(request)),
  ),
);

// reset to original handlers
server.resetHandlers();

Timeout behavior

When timeoutRate triggers, WaitKitTimeoutError is thrown. MSW treats an unhandled thrown error as a network failure.

import { WaitKitTimeoutError } from '@waitkit/core';

try {
  await fetch('/api/slow');
} catch (error) {
  if (error instanceof WaitKitTimeoutError) {
    console.log('request timed out');
  }
}

Evaluation order

For each request, the rule options are evaluated in this order:

  1. delay — wait before calling the resolver
  2. timeoutRate — if triggered, throw WaitKitTimeoutError
  3. errorRate — if triggered, return an errorResponse-based HttpResponse
  4. call the original resolver

License

MIT