#SetupServer
No, the main cost if the handler lookup, which happens on request. "setupServer" doesn't do any heavy-lifting until request happens.
November 8, 2024 at 2:37 PM
3. MSW works in the browser and in Node.js through entrypoints (setupServer/setupWorker). Those entrypoints decide on the appropriate interception mechanism for the environment (e.g. Service Worker in the browser, agent-based in Node.js) and route requests through your handlers.
April 3, 2026 at 1:27 PM
I'd also very much like to drop setupServer/setupWorker distinction and have just a single API. This is insanely ambitious and, probably, won't work given how different environments are where users rely on MSW. The library cannot guess them and neither should it.
July 17, 2025 at 9:46 AM
Hmm… I think I miss the point vs our usual setup files (or even beforeEach). What's the gain in setting that up in all files?

I think I would just end up with a setupServer function that accepts params (with a lot of defaults, so 99% it would be setupServer()) like I already do 🤔
November 18, 2025 at 4:45 PM
And once you have this custom setup API, you use it the same you normally would your setupServer function:

const worker = setupCloudflareWorker()
worker.listen()
worker.use(http.get('/resource', resolver)

All those experiences are based on the SetupApi class!
July 11, 2025 at 3:14 PM
curl -o msw.js https://mockbird.mockbird.workers.dev/m/demo/msw.js

import { setupServer } from 'msw/node'
import { handlers } from './msw.js'
setupServer(...handlers).listen()

Tested w/ msw@2.15. db.json ejects to json-server too. One-click: https://mockbird.mockbird.workers.dev/app#new=ecommerce
July 31, 2026 at 6:57 AM
1. note: these results have no statistical significance - they're just the output of my local runs (macbook pro m3).

The bsky e2e suite starts with a setupServer call, I cut that time from the measurements and started after it.
June 11, 2026 at 6:18 PM
setupServer()ですでに登録済みのエンドポイントのハンドラーを、server.use()で追加で登録したら、追加したほうのハンドラーが勝ってくれた🙌これでテストケースごとに必要に応じてハンドラー上書きできるやん
https://zenn.dev/s_takashi/articles/c6ce672dbb1471
August 4, 2023 at 11:49 PM
3. MSW works in the browser and in Node.js via designated entrypoints (setupServer/setupWorker) and can spawn an HTTP server, if you so choose, via its "http-middleware" package. The latter, however, isn't recommended, and here's why...
April 7, 2026 at 2:08 PM
There are two components to mocking:

- The source of requests;
- The source of the mocks.

As a developer, you often communicate both to your mocking library. But not always. E.g. `setupServer` implies it intercepts requests in Node.js, you don't really control that.
December 28, 2025 at 3:13 PM
And if the testing strategy for RSC ends up being in a single Node process (that is of your test), that makes things even easier since you can use the existing "setupServer" API and be done with it.

Betting on the environment-level API mocking does pay off.
June 7, 2023 at 9:27 AM
Could there be an extra API open for like: server.get(url) which gets me a handler for that URL from that server? Maybe not so wise cause it could be prone to race conditions.

But it could exclude handlers added with use(), only those during setupServer().
September 12, 2025 at 1:12 PM
October 5, 2024 at 8:49 AM