Playwright integration or runtime overrides solution #2404
|
Hi all, I am wondering if anyone has a working example of using MSW with Playwright and enabling runtime handler overrides? I have previously had this working using playwright-msw, but that library appears to be unmaintained and has stopped working for me. I have also taken a look at various examples such at the remix example, but none of the example I could find actually use runtime overrides. I have seen @kettanaito mention that runtime overrides can be enabled by exposing The I'm wondering if anyone has found a working solution to this? If not, shall we open a discussion about how MSW could integrate directly with playwright? |
Replies: 1 comment
|
Hi, @kristojorg.
This sounds like a culprit. I recommend integrating MSW in your app, not the test, so your app never renders until the service worker is up and running (see this). This integration is recommended for a reason, precisely to eliminate the race conditions like the one you're experiencing. Once that's covered, you can expose In the future, I would like to utilize #1617 to make it easier to affect network behaviors in a different process (since your PW test and the browser are two different processes). |
Hi, @kristojorg.
This sounds like a culprit. I recommend integrating MSW in your app, not the test, so your app never renders until the service worker is up and running (see this). This integration is recommended for a reason, precisely to eliminate the race conditions like the one you're experiencing.
Once that's covered, you can expose
window.mswand provide runtime handler overrides. We use this pattern extensively to test MSW itself. Take a look at the/test/browserdirectory for inspiration.In the future, I would like to uti…