🎉 Announcing MSW 2.0! 🎉
🌎 Migration guidelines: https://t.co/kjGWXV8Jti
📰 Release notes: https://t.co/ldZU5h6zrd
365+ days in development, 200+ commits, 40+ contributors involved. The future of API mocking is here, and it has never been brighter.
Good news for all Cloudflare users! First-party MSW integration is out. Seamless, standard-first, and powerful as you came to expect.
Try this in your tests and submit any issues you find! Thanks.
Enjoy this introduction into E2E testing from my latest workshop "React End-to-End Testing with Playwright"! 🎉
Let's talk about what E2E testing is, how it has nothing to do with the browser, and what is its true goal.
More and more people are asking me about testing resources so let's put everything I've written in one post. Bookmark, share, and, most importantly, please read these.
The True Purpose of Testing
https://t.co/KwnelsWjhp
Developers often overlook the fundamentals and rush into writing tests without properly understanding what a test is and what is its function. No test is inherently useful just because it exists. Read this one to learn what makes it useful.
The Golden Rule of Assertions
https://t.co/3pZ5bcT3lo
There's a lot of debate over what makes a good test. In this one, I'm defining a short and objective way to grade a test's quality no matter the language or the tested system. This is, without a tinge of exaggeration, a game-changer in how you approach your tests.
Anatomy of a Test
https://t.co/yT1ihVfORT
Let's talk about the building blocks that make up any automated test. From JavaScript to Go and Rust—these blocks power tests everywhere. Know your blocks.
Implicit Assertions
https://t.co/WmpC4nN4Zm
Did you know there's a way to express expectations in tests without writing "expect"? Those are called implicit assertions and they are tremendously powerful because they help you express more by writing less.
Inverse Assertions
https://t.co/ItgBFRc5oz
Sometimes you need to assert that something did not happen. That can be tricky, especially if that something is asynchronous. The last thing you want are false positives. What you actually want is inverse assertions.
Making Use of Code Coverage
https://t.co/fr6BJ5BOxT
Code coverage has been an ongoing debate in the engineering circles. Is 100% code coverage in tests good? Bad? When should you strive for it? Why do people say it's harmful? I'm answering all those questions in this one and giving you practical tips on when to use (and not to use) code coverage.
Good Code, Testable Code.
https://t.co/Eenwjb25vV
You've gathered by now that some code is easier to test than the other. But why? Let's take a look at the characteristic of code's testability, what defines it, what is its relationship with complexity, and how to make your code more testable.
What is a Test Boundary?
https://t.co/iF5OoW3xsF
Automated tests rarely involve your entire system (yes, even the end-to-end ones have exceptions). There's often a place where you draw the line. The boundary. Learn what it is and how to use test boundaries efficiently to focus on the exact behaviors you want to test.
Be S.M.A.R.T. About Flaky Tests
https://t.co/CXK6um3mfJ
Flakiness is the scourge of reliability. If you've written a test before, you likely had experience with flakiness. But what is it at its core and what causes it? And how should you deal with flakiness?
Writing Tests That Fail
https://t.co/3HJauq4zRb
You write tests for them to fail. We all enjoy a green CI, but the true value of tests is when they fail. What matters is when and how they fail.
I'm excited to announce "React End-to-end Testing with Playwright"! 🎉
Complete your testing journey by learning how to use Playwright to test your entire app. I'm talking full browser automation, user journeys, auth, search, test setup, debugging tips...
Here's what's inside 👇
📦 [email protected] introduces a new API called "finalize" for scheduling cleanups after the request handler is finished. This is your go-to choice for managing side effect cleanup in your mocks.
It's undocumented, but I released an "onUpgrade" callback to handle connection upgrades from HTTP to WebSocket for matching handlers. This is only relevant for Node.js and custom environments.
I built Data as the means to do data-first API mocking, but it turned out that all you need is schema seeding and ORM-like querying, which are general purpose.
Could you give it a try? Experiment, try breaking it, that kind of stuff. Thanks!
https://t.co/bt91ehTvLE
@jarredsumner Hi, Jarred 👋
I think it's time we made MSW work in Bun. I'm working on the new architecture right now that might actually make that possible. Would you be interested in sponsoring my work and bring first-class API mocking to all Bun users?
💡 Fun fact: Nock uses MSW's interception algorithm under the hood! I've created it as a standalone library anyone can use to build their own MSW and it warms my heart to see Nock adopt it for powerful and unified interception for everyone.
https://t.co/ULF2cEQxml
Super excited to announce that @coderabbitai is joining MSW partners to help make the future of API mocking on the web more sustainable.
Huge thank you! 🎉
Would you pay a small one-time fee to download hand-crafted agent skills for MSW?
Best practices, common mistakes, getting the most out of your mocks. This kind of stuff.
If you like MSW and would like to help make it more sustainable, please consider nominating it at https://t.co/kQzN6rUaYV
Share a short feedback about how it improved your development life. Costs you nothing. Might be a game-changer for its future.
Thank you ❤️
Ever needed to handle API mocking?
Our final speaker, @kettanaito, is the creator of @ApiMocking. He'll be joining us to talk about how the library became a standard for modern development.
We're just 2 days away! Grab one of the last spots! See you there💛
I genuinely want to understand developers that struggle with MSW. If you are one, please share your feedback!
I've worked so hard to make it the best API mocking solution on the web. It's years ahead of the "competition", promotes web standards, has the richest feature set you can find.
But there are still developers who struggle with it, apparently. I want to turn those struggles into features I can add and bugs I can fix. But I need to know them first!
In Node.js, using MSW is no different than using any other solution you're familiar with. Some of them literally use MSW under the hood, providing a different flavor of UX. That part is subjective and I'm fine if some prefer other APIs to what MSW offers. As long as you're using the interception algorithm that doesn't diminish the value of your tests.
In the browser, the only inconvenience I can think of is having to register a Service Worker. I get it, it's an extra step, not everybody is familiar with what that is and why that's needed. I used to wish to get rid of this step, but I find it both educational and secure. There is no better way to intercept the network in the browser than a Service Worker. And that means learning a bit about them and keeping your worker yours.
Please share the things you struggled with in MSW, if any. I'd be grateful.