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: added validation for timeout for query operations #29327

Merged
merged 17 commits into from
Apr 23, 2024

Conversation

percytrar
Copy link
Contributor

@percytrar percytrar commented Apr 14, 2024

Additional details

When an invalid timeout value like {} is passed in options to a query method like get it resulted in infinite waiting, the test simply didn't timed out.
Affects query methods - get, shadow and contains

Steps to test

Add this to the querying.cy.js test file

cy.get('#some-el', { timeout: {} })

How has the user experience changed?

Before fix -
Screenshot 2024-04-14 at 11 42 32 AM

After fix -
Screenshot 2024-04-14 at 11 37 35 AM

PR Tasks

@CLAassistant
Copy link

CLAassistant commented Apr 14, 2024

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

@percytrar percytrar changed the title fix: added validation for timeout for query operations #29323 fix: added validation for timeout for query operations Apr 14, 2024
Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

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

@percytrar Thanks for the contribution. I have some suggestions on the error message.

@@ -142,13 +142,21 @@ function getAlias (selector, log, cy) {
}

export default (Commands, Cypress, cy, state) => {
function validateTimeoutFromOpts (options: GetOptions | ContainsOptions | ShadowOptions = {}) {
if (_.isPlainObject(options) && options.hasOwnProperty('timeout') && !_.isFinite(options.timeout)) {
$errUtils.throwErr(new Error(`contains invalid timeout - ${options.timeout}`))
Copy link
Member

Choose a reason for hiding this comment

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

Typically we keep error messages within our error_messages.ts file and call into that to throw the error message (for simplicity). You can see an example of this in line 153 of this same file. Could you refactor this to put the message there?

For the error message, to match other error messages to give the user all the info they need to fix it, I would suggest:

{{cmd}} only accepts a number for its `timeout` option. You passed: \`{{timeout}}\`

So that for the user it will print:

`cy.get` only accepts a number for its `timeout` option. You passed: `abc`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info, added new error msgs 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is addressed.

@@ -18,6 +18,64 @@ describe('src/cy/commands/querying', () => {
})
})

describe('should throw when timeout is not a number', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding tests!

@percytrar
Copy link
Contributor Author

After updating error messages -
Screenshot 2024-04-15 at 11 55 23 PM

Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

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

The types seem to already correctly warn when timeout is invalid.
Screenshot 2024-04-15 at 2 42 48 PM

Verified locally that this now errors instead of hanging forever when the element is not found.

Before

Screenshot 2024-04-15 at 2 45 53 PM

After

Screenshot 2024-04-15 at 2 47 00 PM

@percytrar
Copy link
Contributor Author

How much time does it take for these runs to execute? Or they are run in batch at a particular time of the day?
Screenshot 2024-04-17 at 9 35 05 AM

@jennifer-shehane
Copy link
Member

@percytrar We have to manually approve all contributor PRs to run to ensure there's nothing nefarious about to run in our CI machines unfortunately, so it just sits there until we push a button.

@percytrar
Copy link
Contributor Author

percytrar commented Apr 20, 2024

@jennifer-shehane By when can we expect that this PR will be merged? We need 2 approvals.

@cacieprins
Copy link
Contributor

Just a small performance-related note, otherwise looks good!

@percytrar percytrar requested a review from cacieprins April 22, 2024 15:51
@jennifer-shehane
Copy link
Member

@percytrar I'll try to get this merged for the next release.

@jennifer-shehane jennifer-shehane merged commit c5fa260 into cypress-io:develop Apr 23, 2024
67 checks passed
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 23, 2024

Released in 13.8.1.

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

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

Successfully merging this pull request may close these issues.

If anything but a number is passed as the timeout option on cy.get(), the test never reaches the failure state
5 participants