MSW v2 brings the biggest API change to the library since its inception. Alongside the new API, it includes various features, such as ReadableStream
support, ESM-compatibility, and countless bug fixes.
Codemod supports a mostly automated MSW v2 upgrade experience. This page provides tips and resources you may need for a successful migration.
Installation
Run codemods
Inside your project’s root directory, run the MSW v2 upgrade recipe:
Fix false negatives
The upgrade recipe does not change the signatures of MSW handlers, if they were called using a custom factory function, for example to provide more type-safety or else. For example, the following code will only be partially updated:
Additionally, if you were using req.body
in your interceptors, this codemod will blindly assume you want await request.json()
instead of any other type. You will have to correct that manually.