from Hacker News

MSW 2.0 – Mock Service Worker

by milkers on 10/23/23, 2:01 PM with 55 comments

  • by dcre on 10/23/23, 5:04 PM

    At my job we've found working with MSW + OpenAPI to be near miraculous. I work on a web frontend and do most of my development against a mock API powered by MSW. This live preview runs against the mock API running fully in-browser.

    https://oxide-console-preview.vercel.app

    More details:

    https://github.com/oxidecomputer/oxide.ts

    https://github.com/oxidecomputer/console

    https://oxide.computer/podcasts/oxide-and-friends/1426644

    Really excited about this next step for MSW — we'll be upgrading soon. Building on web standards buys you so much.

    (Reposted at top level because the parent got flagged.)

  • by candylifter on 10/23/23, 3:40 PM

    Nice to see more and more tools adopting standard Fetch API Request/Response interfaces.
  • by scottlamb on 10/23/23, 11:01 PM

    How do folks test timing-related stuff with MSW? AFAIK, MSW doesn't get along with jest.useFakeTimers. It drives me nuts; I have a bunch of disabled tests in an open-source project and at least one that is flaky because it uses real timers where I'd like to be using fake timers. [1, 2]

    I've been thinking about ripping out MSW from my tests in favor of my own API-level mock for this reason. But it seems like many other folks are happy with MSW. I have to assume there's something I'm not getting. I'm a fish out of water with frontend stuff in general...

    [1] https://github.com/scottlamb/moonfire-nvr/blob/5ea5d27908f1a...

    [2] https://github.com/scottlamb/moonfire-nvr/blob/5ea5d27908f1a...

  • by IggleSniggle on 10/23/23, 4:20 PM

    Super excited to see this land. I've been following this closely and experimenting with the beta branch; the ability to swap out real network requests with mocked ones in process is a huge upgrade for any kind of work you might have wanted to do with a proxy.

    Congrats on the release!

  • by danwee on 10/23/23, 5:14 PM

    Off-topic: I think I've seen this page layout before https://mswjs.io/docs . Did they use a css-html template/framework for it?
  • by milkglass on 10/23/23, 3:58 PM

    Why does the site need us to allow ads? On the getting started page I see this:

    "Please enable ads on this website. Thank you."

  • by orthecreedence on 10/23/23, 4:13 PM

    For a second I thought it was Magic Seaweed 2. RIP.
  • by ok123456 on 10/23/23, 5:18 PM

    What is the benefit of using MSW over mocking a service with a small express server?