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

playwright-msw is broken after recent update to msw 2.6.0 #104

Open
rolule opened this issue Nov 4, 2024 · 6 comments
Open

playwright-msw is broken after recent update to msw 2.6.0 #104

rolule opened this issue Nov 4, 2024 · 6 comments

Comments

@rolule
Copy link

rolule commented Nov 4, 2024

Hi, thank you for this amazing package. Unfortunately, the latest 2.6.0 release of msw breaks it completely, as the handlers do not get registered anymore.

To reproduce this, I built a minimal example in CodeSandbox: https://codesandbox.io/p/devbox/cocky-cerf-cwj96y

  1. When you are on [email protected], the single test works perfectly fine when running npx playwright test:
    Screenshot 2024-11-04 at 16 09 36

  2. Now run npm install [email protected] (you might have to fork the CodeSandbox to make changes) and run npx playwright test again:
    Screenshot 2024-11-04 at 16 11 33

=> it is obvious that our single handler (in playwright/test.ts) did not register properly and the test timed out.

I hope this issue can be fixed soon, as we rely on it for our Playwright tests. Thank you!

@rolule
Copy link
Author

rolule commented Nov 4, 2024

I have analyzed the problem further and it seems to be the following three new lines in executeHandlers.ts that causes the issue:

if (!(handler instanceof RequestHandler)) {
  continue
}

Somehow the handlers created by playwright-msw do not seem to fulfill the instanceof check. Therefore the request ist not processed at all. If I comment these three lines out, everything works again as before.

The question is what to do about this issue. I am not fluent enough in this repo to easily fix this.

@rolule
Copy link
Author

rolule commented Nov 7, 2024

I have confirmed the issue is due to esm/cjs. We use Playwright with "type": "module" in the package.json file. I do not know exactly what happens when Playwright imports the playwright-msw module, but it seems like two instances of the RequestHandler are loaded into context at the same time (maybe one is esm and one is cjs). Therefore when the handler instanceof RequestHandler check is executed, we compare apple with orange and get false.

The issue can be solved by providing an esm compatible module. I could assist in creating a merge request.

@bitttttten
Copy link

We also see flaky tests on msw 2.4.4 and playwright-msw 3.0.1 where our handlers are not being registered and they go call the "live" endpoint underneath.

We have one specs file with two test calls in it and the second one was failing to register handlers.

Any help I can provide too lmk, @rolule did you work on the PR yet for esm support?

@rolule
Copy link
Author

rolule commented Nov 18, 2024

@bitttttten

Any help I can provide too lmk, @rolule did you work on the PR yet for esm support?

Thank you, though I think the problem is that the package does not seem to be maintained anymore. @valendres please confirm so we could create a fork to fix the problem.

@nathanhannig
Copy link

Looks related, new version of msw might fix?

mswjs/msw#2346

@kristojorg
Copy link

Newest version of MSW did not fix this for me. It looks like we will need to patch playwright-msw or fork it and continue maintaining it on our own

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants