-
-
Notifications
You must be signed in to change notification settings - Fork 544
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
Interception broken due to instanceof
handlers check (dual publish)
#2346
Comments
I think this issue is caused by the new My initial assessment is that there is some inconsistency regarding when the |
@robbtraister, so the class identity doesn't survive due to different classes being loaded in different contexts. That's interesting. I'd like to know how come you get CJS and ESM builds running at the same time. What you are experiencing is one of the symptoms of dual-published hazard, and that's the root cause of the issue, not the Could you please look around and see what causes different bundles to be loaded in your test case? Can it be that your Playwright config gets the CJS version of MSW, somehow? |
instanceof
handlers check (dual publish)
@funes79, hi 👋 Did you by chance forget to push the code to your reproduction repo? It's empty. Please push the reproduction there and then I can take a look at this. None of our existing tests recreate this behavior so I suspect it has to do with the project setup. |
@kettanaito it looks like the import inconsistency may be happening via the playwright-msw package. That package looks to be published only as CJS, but my app test code is using ESM. I attempted to wire up my app test code without the |
@robbtraister, yes, we are using MSW and Playwright without any other packages at https://github.com/mswjs/examples/tree/main/examples/with-playwright. Could you give that repo a try and if there's still an issue submit reproduction steps? |
That approach requires that msw be built into your application so that you're either shipping extra code in production or testing a non-production build. It also makes writing tests much more complicated because the mock handlers must essentially be defined within the app, meaning it doesn't really support handler customization per test. In order to customize the handlers, you have to wait until the page has already loaded (giving access to the msw library baked into the app), but at that point unintercepted requests may already have fired. |
The way you integrate MSW for development already does this (ref). If anything, it's a single setup for any in-browser need, which I quite like.
It does! I know the examples don't showcase that, but if you expose await page.evaluate(() => {
const { worker, http } = window.msw
worker.use(http.get('/override', yep)
})
This is a valid point. How would you address it though? To register the worker, you have to visit the app, no matter if you do that in your app code or in a third-party package. |
I don't have a good answer to this. It seems that the This has worked really well up to this point, allowing us to register intercepts prior to test execution, and also using shared handlers that work in any msw context (we also use msw with vitest and storybook). |
As a quick-fix to verify this is the real issue, I patched |
Well, then it's not MSW at this point, but Playwright relying on the request handler API and using different interception algorithm (
Which means the issue is in |
I understand this perspective as a maintainer, but as a consumer I find it unsatisfying. Essentially, you're suggesting that the entire ecosystem is effectively bifurcated, regardless of the work done to make CJS/ESM cross-compatible. Would you consider an approach similar to |
I have a similar issue but for a micro-frontends setup. This block and this block are causing the issue for my setup. |
I've opened a fix at #2349 that moves away from |
Released: v2.6.1 🎉This has been released in v2.6.1! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
@kettanaito thank you for looking into this. It seems that I personally consider msw support for Playwright essential for a great integration testing experience. Since you wrote this above:
I wanted to ask you if you would consider migrating |
I am generally in favor of migrating community packages with large demand. Practically speaking, I need to look into I have tool-specific integrations planned as an endeavor for the next year. For now, you can use Could you consider joining my Discord to stay in touch? We can also share thoughts about the Playwright integration there. |
That makes sense, thank you for your explanation! I will join the Discord soon. |
Prerequisites
Environment check
msw
versionBrowsers
Chromium (Chrome, Brave, etc.)
Reproduction repository
https://github.com/funes79/nocode
Reproduction steps
I tested 2.4.0, 2.3.0, 2.5.0, all works as expected. But upgrade to 2.6.0 breaks intercepting, in client components:
handlers file:
Current behavior
[MSW] Warning: intercepted a request without a matching request handler:
GET https://github.com/reviews2
Expected behavior
Should return:
{"reviews":"Hello, World!"}
[MSW] 14:41:28 GET https://github.com/reviews2 (200 OK)
The text was updated successfully, but these errors were encountered: