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

fix: cy.intercept delay works correctly with 204 No Content #17126

Merged
merged 1 commit into from
Jul 13, 2021

Conversation

sainthkh
Copy link
Contributor

User facing changelog

delay now works correctly with the statusCode: 204.

Additional details

  • Why was this change necessary? => delay didn't work correctly with statusCode: 204.
  • What is affected by this change? => N/A
  • Any implementation details to explain? => It was happening because of setTimeout inside the getBodyStream. It is called after the delay when response is not an empty body but it isn't when it's not. I fixed this by changing getBodyStream as async.

How has the user experience changed?

N/A

PR Tasks

  • Have tests been added/updated?

Sorry, something went wrong.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 28, 2021

Thanks for taking the time to open a PR!

Comment on lines 228 to 210
function wait (fn, ms) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(fn())
}, ms)
})
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the right place for this utility function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bluebird offers Promise.delay which may meet your needs. If it's just used in this function/file then this is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the code with Promise.delay.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sainthkh There seems to be a type error with the change

@sainthkh sainthkh marked this pull request as ready for review June 28, 2021 05:36
@sainthkh sainthkh requested a review from a team as a code owner June 28, 2021 05:36
@sainthkh sainthkh requested review from flotwig and kuceb and removed request for a team June 28, 2021 05:36
flotwig
flotwig previously approved these changes Jul 7, 2021
Copy link
Contributor

@flotwig flotwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good, nice fix.

Comment on lines 228 to 210
function wait (fn, ms) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(fn())
}, ms)
})
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bluebird offers Promise.delay which may meet your needs. If it's just used in this function/file then this is fine.

@jennifer-shehane
Copy link
Member

@sainthkh Is this ready for rereview?

Copy link
Contributor

@flotwig flotwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check create-build-artifacts, there is a type error

@sainthkh sainthkh force-pushed the issue-15188 branch 2 times, most recently from 941601d to 09d78a3 Compare July 12, 2021 23:54
@sainthkh
Copy link
Contributor Author

I rolled back and decided to use wait function instead. To use bluebird inside net-stubbing package, it should be included as a dependency.

@flotwig flotwig merged commit 0fc3944 into cypress-io:develop Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cy.intercept: delay is not working on 204 No Content
3 participants