Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypassing MSW does not work with MSW 2.X #916

Closed
Jokinen opened this issue Nov 7, 2023 · 2 comments
Closed

Bypassing MSW does not work with MSW 2.X #916

Jokinen opened this issue Nov 7, 2023 · 2 comments
Labels
enhancement New feature or request released

Comments

@Jokinen
Copy link

Jokinen commented Nov 7, 2023

This is more of a FYI.

In version 3.1.0, the x-msw-bypass header was introduced in order to have better out of the box support for MSW.

MSW released a new version two weeks ago. Version 2.0 no longer respects the x-msw-bypass header. It seems that this header was considered to be an implementation detail as it's not documented as a breaking change.

MSW 2.0 has a new utility called bypass. Based on the implementation, it seems that the new header that gets bypassed is:

'x-msw-intention': 'bypass'

I'm not suggesting similar support should be implemented for MSW 2.x as existed fro MSW 1.x. I just want to bring this change into your attention.

Alternatives and workarounds

As a workaround, the old header can be respected in userland:

  server.listen({
    onUnhandledRequest(request, print) {
      if (request.headers.get('x-msw-bypass') === 'true') {
        return;
      }

      print.warning();
    },
  })
);

Not sure if the new bypass utility can be used in some way that allows the implementation to not depend on implementation details.

@Jokinen Jokinen added the enhancement New feature or request label Nov 7, 2023
@Xunnamius
Copy link
Owner

Xunnamius commented Nov 7, 2023

Thanks for this! I'll release an update shortly.

UPDATE: I was thinking my unit tests should have caught this, but it turns out I wasn't testing the MSW integration. New regression test should catch this going forward.

Xunnamius added a commit that referenced this issue Jan 4, 2024
## [3.2.0](v3.1.10...v3.2.0) (2024-01-04)

#### ✨ Features

* Update headers for msw@2 compatibility ([93b8a3c](93b8a3c)) <sup>closes [#916](https://github.com/Xunnamius/next-test-api-route-handler/issues/916)</sup>
@Xunnamius
Copy link
Owner

🎉 This issue has been resolved in version 3.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

No branches or pull requests

2 participants