-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Conversation
|
There was a problem hiding this 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}`)) |
There was a problem hiding this comment.
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`
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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. |
@jennifer-shehane By when can we expect that this PR will be merged? We need 2 approvals. |
Just a small performance-related note, otherwise looks good! |
@percytrar I'll try to get this merged for the next release. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Additional details
When an invalid
timeout
value like{}
is passed inoptions
to a query method likeget
it resulted in infinite waiting, the test simply didn't timed out.Affects query methods -
get
,shadow
andcontains
Steps to test
Add this to the
querying.cy.js
test fileHow has the user experience changed?
Before fix -
After fix -
PR Tasks
cypress-documentation
?type definitions
?