Skip to content
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

Response body sometimes not displayed in console props for xhr request #21361

Closed
mschile opened this issue May 5, 2022 · 2 comments · Fixed by #21373
Closed

Response body sometimes not displayed in console props for xhr request #21361

mschile opened this issue May 5, 2022 · 2 comments · Fixed by #21373

Comments

@mschile
Copy link
Contributor

mschile commented May 5, 2022

Current behavior

The response body is not always displayed in the console props for xhr requests. There appears to be a race condition between the xhr request finishing and the proxy sending the response:received event.

Proxy sends the response:received event:

this.res.on('close', () => {
this.socket.toDriver('request:event', 'response:received', {
requestId,
headers: this.res.getHeaders(),
status: this.res.statusCode,
})
})

Call made to update the console props after receiving the event:
proxyRequest.updateConsoleProps()

Console props are updated with the xhr values. However, if the xhr isn't fully complete (i.e. readystate === DONE), then these values are not valid.
if (this.xhr) {
if (!consoleProps['Response Headers']) consoleProps['Response Headers'] = this.xhr.responseHeaders
if (!consoleProps['Response Status Code']) consoleProps['Response Status Code'] = this.xhr.xhr.status
consoleProps['Response Body'] = this.xhr.xhr.response

This is causing flake in the following test:
Screen Shot 2022-05-05 at 4 50 41 PM

Correct console props:

Screen Shot 2022-05-05 at 4 22 27 PM

Incorrect console props:

Screen Shot 2022-05-05 at 4 21 02 PM

Desired behavior

Console props always contains the xhr response body.

Test code to reproduce

Run the following test multiple times until it fails:

it('xhr log has response body/status code when xhr response is logged second', (done) => {

Cypress Version

develop

Other

No response

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 9, 2022

The code for this is done in cypress-io/cypress#21373, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 9, 2022

Released in 9.6.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.6.1, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants