• Msw/2/Upgrade Recipe

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

    by@alexbit-codemod
  • Msw/2/Type Args

    There is a change to generic type interface of rest.method() calls. This codemod puts the generic arguments in the correct order to keep type safety.

    by@codemod
  • Msw/2/Response Usages

    To send a response from MSW handler, one would previously use something like res(ctx.text("Hello world")). In msw v2, this is achieved by returning a native WebAPI Response object. msw v2 conveniently exposes a HttpResponse function that has useful methods for creating just that object with a desired body. This codemod replaces the old res calls with the new HttpResponse function calls and a bunch of ctx utilities that usually go with it. See examples below.

    by@codemod
  • Msw/2/Request Changes

    Following the original msw upgrade guide, the signature of the request handler have changed. Some of the parameters have changed their type, some widely used objects are available directly on the callback argument object for convenience. Following changes are applied by this codemod:

    by@codemod
  • Msw/2/Req Passthrough

    A new way of calling a passthrough is available in msw v2. This codemod replaces req.passthrough() calls with the new way of doing that using exported function.

    by@codemod
  • Msw/2/Print Handler

    A new way of listing all handlers is preferred in msw v2. This codemod replaces printHandlers() calls with the new way of doing that.

    by@codemod
  • Msw/2/Lifecycle Events Signature

    In msw v2, lifecycle events callback methods have changed their signature. This codemod replaces usages if its arguments with the new ones.

    by@codemod
  • Msw/2/Ctx Fetch

    ctx.fetch(req) is now meant to be called as fetch(bypass(req)) where bypass is a new function available in the msw library. Changes applied by this codemod:

    by@codemod
  • Msw/2/Callback Signature

    Following the original msw upgrade guide, the signature of the request handler have changed. This codemod hard replaces the callback signature to the new one and cleans up unused variables.

    by@codemod