I ran into the same issue, and it turns out using request.continue
is what was causing it.
request.continue
is expecting a response, but when you get a socket hangup
(ConnResetException
), or in my case the socket being closed before it was finished writing, it triggers a cypress error.
Instead of request.continue
, you'll want to use request.on( 'response', response => {
Your full code snippet should look like this:
cy.intercept('*', (request) => {
request.on( 'response', response => {
if(response.statusMessage !== "OK") {
networkFails.push({request, response})
}
})
})
The cypress documentation does a great job of explaining all of the different options here: https://docs.cypress.io/api/commands/intercept#Request-events
For reference, this was the specific cypress error I was getting while using .continue()
. The error message was a bit different from yours but essentially the same problem requiring the same solution.
A callback was provided to intercept the upstream response, but a network error occurred while making the request:
Error: Socket closed before finished writing response