Msw/2/Upgrade Recipe

1.0.4Last update Jul 24, 2024
by@alexbit-codemod
Msw
migration

This recipe is a set of codemods that will upgrade your project from using msw v1 to v2.

The recipe includes the following codemods:

FNs

This 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:

export function mockFactory<T extends MyComplexType>(
url: string,
resolver: MyResolverType,
) {
return rest.get(url, resolver);
}
const handlers = [
mockFactory('/some/url', (req, res, ctx) => {
return res(ctx.status(200));
}),
];

Also, 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.

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now