7 ms·
MSW 2.0 – Mock Service Worker
- candylifter 3y agoNice to see more and more tools adopting standard Fetch API Request/Response interfaces.
- flakes 3y agoAgreed. The more non-intrusive your APIs are, the better the overall experience is going to be for developers. Diverging from official/standard APIs means higher chance framework lock-in, which has kept me away from a lot of tooling. Always try to ask myself when adding tooling: What's the chance I'll want to remove this later, and how painful is that going to be?
- milkglass 3y agoWhy does the site need us to allow ads? On the getting started page I see this: "Please enable ads on this website. Thank you."
- wccrawford 3y agoIf I enable ads, it shows an ad for an ad service to target developers.
- ranting-moth 3y agoThey're probably trying to make some money for their work that people take for granted. I don't like ads, but I can't blame them.
- orthecreedence 3y agoFor a second I thought it was Magic Seaweed 2. RIP.
- smallerfish 3y agoGuess we are stuck with surfline. I'd be interested in creating a competitor if I knew more about the data sources though - fun problem.
- codybontecou 3y agoStormsurf provides tutorials and public data source links if you are genuinely curious: http://stormsurf.com/page2/tutorials/menu.html http://stormsurf.com/page2/tutorials/menu.html
- smallerfish 3y agoCool, thanks. Bookmarked for a weekend.
- IggleSniggle 3y agoSuper 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!
- sph 3y ago[flagged]
- teaearlgraycold 3y agoI don't think they have VC money. I think the people building it just know what they're doing. Do you see anything that indicates this is a VC-funded project? It looks to me like they're only getting a little bit of money from Github Sponsors (https://github.com/sponsors/mswjs https://github.com/sponsors/mswjs).
- sph 3y agoThat's a lot of time and effort, for people earning next to nothing, for an open-source library. I'm not saying it's bad they have a beautiful website to rival any small SaaS, but how is even possible they have the time and energy to spend on that, rather than on the code itself? What would Linux or GNOME or leftpad look like with a proportional amount of marketing effort? Last time I checked, testing libraries did not have custom iconset and a testimonial section to rival the Stripe homepage.
- CPLNTN 3y agoI don’t understand, your complaint is that the project is too well done?
- teaearlgraycold 3y agoA few things: 1. It's actually pretty easy to get a pretty site these days. The SaaS layout is so standardized you can just buy a template to get your React site up and running and looking professional for a couple hundred dollars and a few hours of work. The site overall definitely took more time than that. 2. This is a library for front-end developers. It's made by front-end developers who probably have some design skills of their own. That makes it easier for them than Linux's kernel hacker team to set up a nice website. 3. Is this just a matter of insecurity on your part? I'm sure you have plenty of dev skills but maybe they don't extend to UI and you don't like that this team can throw together a beautiful site for something that's merely a side-project?
- revskill 3y ago[flagged]
- michaelmior 3y agoI'm not sure what you're getting at here. Not all open source projects are trying to turn users into products. A lot of open source projects derive value from getting external contributions that they wouldn't otherwise if something was kept closed source and in-house. Paying for software isn't always necessary. That said, the project also has several sponsors: https://github.com/sponsors/mswjs https://github.com/sponsors/mswjs
- revskill 3y agoIt's always like that. I can't find any exception, sorry. It's natural right ? You can't just have your cake and eat it, too.
- Uehreka 3y agoSo when I use, say, ffmpeg: In what sense am I their product? They don’t collect telemetry, they don’t serve me ads, the output can be used with any other tool so there’s no lock in, there’s no FFmpeg Pro (TM) with features withheld from the base version. This seems a little silly I know, but GP was talking about open source projects and you literally said “I can’t find any exception”.
- morbicer 3y agoEnlighten us how exactly are we products of Linux, Python, PostgreSQL and myriad of other open source which I am pretty sure you are using as well.
- skrebbel 3y agoIf you can’t find any exception then you’ve missed like 80% of the FOSS ecosystem. Incl every BSD, most linuxes, most python libs and so on and so forth.
- ElectricalUnion 3y ago
- Andrew018 3y ago[dead]
- dcre 3y agoAt 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 https://oxide-console-preview.vercel.app More details: https://github.com/oxidecomputer/oxide.ts https://github.com/oxidecomputer/oxide.ts https://github.com/oxidecomputer/console https://github.com/oxidecomputer/console https://oxide.computer/podcasts/oxide-and-friends/1426644 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.)
- berziunas 3y agoIs it ok if I see I am logged in as as Hannah and can launch new instances after clicking the first link?
- jonchurch_ 3y agoIt's all mocked, so you're not really Hannah, and you're not really launching instances. Their console is open source, and when you run it in dev mode locally this is also what you see.
- refulgentis 3y agoJust when I think I get the whacky web kids, hell, that maybe I've even one of them, an article like this and functionality like this comes along. I don't know how a mock library enables a revolution of having test data. I don't know why the library couldn't change it's favorite method signature because a subset of versions of one JS framework couldn't...fetch? or why the mock library can only have one dependency... ...and I feel _really_ out of the loop because I can't understand the tone, hinting at years of sweat and though that I'm more used to from a consumer product launch. But that's why I respect the web more than ever. The reaction is real, and it means something, even if I don't understand it. People put _years_ into making (gestures) this work, so millions of developers can benefits, so billions, hell, _humanity_ can benefit. All in the open. Shine on, you crazy diamonds. https://www.youtube.com/watch?v=54W8kktFE_o https://www.youtube.com/watch?v=54W8kktFE_o
- danwee 3y agoOff-topic: I think I've seen this page layout before https://mswjs.io/docs https://mswjs.io/docs . Did they use a css-html template/framework for it?
- dargy 3y agoLooking through the page source + some Google landed me here: https://docs.astro.build/en/getting-started/ https://docs.astro.build/en/getting-started/
- ok123456 3y agoWhat is the benefit of using MSW over mocking a service with a small express server?
- meiraleal 3y agoNo need to run a small express server? MSW runs in the browser so you can develop against a mocked API.
- ljm 3y agoYou can generate TS from an OpenAPI spec and then create type-safe mocks of network calls. Basic mocks and fake servers run the risk of falling out of sync and giving false positives, or just being outright wrong to short-cut some of the work. It's also less code to maintain when a service worker can intercept the call, instead of orchestrating a load of mock APIs. It won't stop you making breaking changes on the API but it will keep you honest on consuming the API on the client.
- Klaster_1 3y agoToo bad this only gets you so far. Last time I checked, the OpenAPI specs are not as flexible as TS types and the people who author these - probably the team members responsible for the backend - won't necessarily even be able to list all the invariants due to framework and host language constraints. And OpenAPI does not support WebSockets. The project I work on has a frontend written in TypeScript, a Java backend, an Express-based dev-server that shares same types with FE, but none of the solutions the team evaluated enables the type sharing across all three beyond simple "an object can have these fields" - no algebraic data types, no WebSocket support. In the end, we resorted to agreeing on as much as possible in plain text before greenlighting the new endpoint, and then double checking the implementation and client usage for unexpected behaviors.
- ljm 3y agoFor those use-cases you might just be better off with either contract tests or simply making the payload itself typesafe with something like protobuf. OpenAPI/Swagger is basically inextricably bound to REST/JSON APIs over HTTP. I also think they're quite abstruse in terms of defining non-trivial interfaces.
- T3RMINATED 3y ago[dead]
- scottlamb 3y agoHow 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/5ea5d27908f1a3e84daacebcc518a6961220b3de/ui/src/Login.test.tsx#L36 https://github.com/scottlamb/moonfire-nvr/blob/5ea5d27908f1a... [2] https://github.com/scottlamb/moonfire-nvr/blob/5ea5d27908f1a3e84daacebcc518a6961220b3de/ui/src/List/VideoList.test.tsx#L133 https://github.com/scottlamb/moonfire-nvr/blob/5ea5d27908f1a...