is there a way to mock server functions rpc calls in e2e tests eg playwright?
I am building apps with start and I want to write e2e tests but we have external api and it is not possible to run with start in CI so I am looking for a way to mock server functions rpc calls in playwright tests
13 Replies
afraid-scarlet•8mo ago
just thinking out loud here: maybe try taking a look at the network tab and see if recreating the rest calls being made works
rival-black•8mo ago
unclear what the problem is. please explain in detail
xenial-blackOP•8mo ago
the problem is the request url of the server function is generated

afraid-scarlet•8mo ago
side note: also for true e2e or even integration tests you'll want to test the comunication between actual services otherwise it's more of a unit test
rival-black•8mo ago
and what does the server fn do?
afraid-scarlet•8mo ago
you can use * in that case i think all the needed data is within the payload
xenial-blackOP•8mo ago
yes, I am aware of the fact that I need to do full e2e but in our case now it is more valuable and faster to do test with mocking BE, all our server functions are just proxy to an external api to keep all communication on the server and manage our own session from the frontend server(start/h3/nitro prod build)
xenial-blackOP•8mo ago
@Manuel Schiller calling external api client

xenial-blackOP•8mo ago
I know that each server function has a
url
key, tried to import server function in the playwright but as expected diffrent budling code so it did not work 😄
@abcdmku I can not use * since each rpc/server function has its own url, it is not like trpc or graphqlrival-black•8mo ago
so and what would you want to mock out?
xenial-blackOP•8mo ago
response of the server function
to test UI with different data etc
rival-black•8mo ago
and why not call the server function and mock away the API that the server function calls?
xenial-blackOP•8mo ago
since the API is only used from server functions it will require me to manage start's server per tests, mocking the network from playwright is simple because the server can start once and I don't have to restart it or do complex logic to start different instance for different tests, since tests run in parallel