Writing Intercept middleware to capture and record all requests. #21141
Unanswered
zacharybussey
asked this question in
Questions and Help
Replies: 1 comment
-
Digging around in the source, I found this: So, if I change my test code to do the following, I will get the supplied fixture file contents in the cy.intercept('GET', '/account/profile', (req) => {
req.continue((res) => {
const body = { ...res.body };
body.modified = true;
// res.send({ body });
res.send({ fixture: 'someFile.json' });
});
}); I think this behavior is somewhat inconsistent. I can see that you would want to populate the response in the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing a VCR style record/playback system for the API calls that an application makes. We've already gotten this working with
cy.route
some time ago, but would like to upgrade and simplify it withcy.intercept
. I've got this close to working but have hit a few snags with the intercept execution order.I have the following in a
support
folder plugin.Sometimes in our tests, its helpful to intercept a request and modify the response. I can do that easily in the test file.
But, given this example, the "after:response" handler never gets a
body.modified = true
value. This is specified in the docs.It seems like a somewhat odd choice to leave the modifications out. If I try to subscribe to the
response
event instead, it never executes because theintercept
was finished by the test file callingres.send
.Is there any way to see the responses as the browser actually receives them when setting up a middleware intercept similar to this?
Beta Was this translation helpful? Give feedback.
All reactions