How to conditionally set the response for an intercepted server-side request per test? #2197
-
Hello! I have a remix app that I'm using playwright to write e2e tests for. I have a server-side request that gets a config object. I was able to setup MSW to intercept this, and return my defined handler's response. Unfortunately, this alone is not very useful for me. The I've seen a few examples of how to do this, but none of them seem to be for server-side requests, only client-side. So I'm curious if that's even possible, and, if so, how? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, @Addison-Dalton. That's a great question. What you are describing is currently not supported in any test runner or framework. The idea of affecting the network of a different process is rather new. We have a work-in-progress API to allow you to do precisely what you described called I've designed that API exactly for your use case: to allow per-test server-side network changes during e2e testing. That feature still needs development and you are unlikely to use it in its current state. If this is something you depend on at work, please consider becoming a sponsor. I would be happy to prioritize that feature or even finish it, given enough budget. Otherwise, I will get to it when I have the time. |
Beta Was this translation helpful? Give feedback.
Hi, @Addison-Dalton. That's a great question. What you are describing is currently not supported in any test runner or framework. The idea of affecting the network of a different process is rather new.
We have a work-in-progress API to allow you to do precisely what you described called
setupRemoteServer()
. See #1617. It establishes a WebSocket bridge between any two given processes, allowing one process to affect the network of the other.I've designed that API exactly for your use case: to allow per-test server-side network changes during e2e testing.
That feature still needs development and you are unlikely to use it in its current state. If this is something you depend on at work, ple…