-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show XHR responses #61
Comments
Mostly sounds good. I would leave 'cy:xhr' and add 'cy:xhr:res' to avoid breaking change. Only showing response data when the endpoint is failing also makes sense. The only problem I have with this is that in case of xhr that are actually captured by cy route we would be displaying the information twice as I understand. Maybe we should investigate if we can somehow detect this duplication and do not log twice. |
Looks like each XHR has an ID field, so we can keep track of logged XHR IDs to avoid duplication. |
When writing tests for this, I noticed that the XHR response log updates are not sent immediately, and sometimes Cypress manages to log a couple commands after it actually received the response, before we receive the XHR response log update. This makes logging the responses separately pretty much useless and even potentially misleading. 😞 But we could still update the original XHR log message like Cypress UI does. And to give some indication of how long the XHR took, we could show the duration given by Here are some ideas how the XHR log could, considering different cases:
In this case, it would probably make sense to always update the XHR log with the response status and duration, but maybe still only show the response body if it is not logged by cy.route and if the request failed? |
Updating the logs always instead of writing them separately sounds better to me. It's more clear that way. And in that case we indeed need to support 2 formats: one where we only log the request (in case we didn't receive the log update from cypress: ex after test finishes) and one where we log it both request and response. Logging the time spent on request is a good feature and if we always get that information easily then why not. I would leave this always enabled as why would we disable it ? Regarding which format to show with the status code placement: I like the one where we show on the same line with the url. But we should also keep consistency with the cy.request logging. |
Released in 2.4.0 |
Currently
cypress-terminal-report
only shows XHR requests when they are sent and doesn't show anything related to the server responses. It would be useful to see at least the server response status codes in the logs when investigating test failures.The Cypress UI adds the response information to the initial request message in its command log once it arrives, but I would actually rather see the responses as their own log messages, so that we see when those responses arrived during the test execution. This would be very helpful in investigating flaky tests, which are often caused by irregular timings of network requests.
To easily separate the requests from the responses, they could have different log types, e.g.
cy:xhr:req
andcy:xhr:res
. Here's an example of how it could look when runningxhrTypes.spec.js
:We could also include the response body, but that should be somehow limited to avoid flooding the logs, e.g. only show it for non-2xx responses (that would be also shown as warnings).
What do you think of this idea, could this funtionality be added? I could work on a PR for it. The XHR responses are sent to the
log:changed
listener.The text was updated successfully, but these errors were encountered: