Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
breaking: upgrade cy.readFile() to be a query command #25595
breaking: upgrade cy.readFile() to be a query command #25595
Changes from 9 commits
82425e6
3345971
1cd59da
7c50dfb
1616186
29b1b7e
25c0d55
58f6fa7
ee4e87c
b3a0b57
fa514d5
96e75d6
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Similar to the other test changes, this one relied on the state after the first retry; we no longer wait for a server response before "retrying" - so the test needs to be more patient.
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.
Moved the simplest tests higher up in the file. It felt off that we started with detailed assertions about the interaction with the backend before just using the command plainly.
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.
When mocked, the new version always retries one more time than the non-query version. This occurs because the first invocation triggers the promise which reads the file from disk and throws an error; it is always asynchronous, even when mocked.
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.
Having an
on('fail')
handler in thebeforeEach()
block makes it hard to debug actual failures, since if you comment out a test's onFail block, the test will suddenly pass.The only change this makes is that in some tests we see three logs rather than two, because "the stub has been called" log is included (where previously it would have been ignored because of this handler-removal).
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.
No functional change here. While working on these changes, I found it easier to read test failures when they were of the form "unable to read
consoleProps
fromnull
" rather than "unable to destructure intermediate object" (the actual errors are significantly more verbose and harder to read than the above).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.
The way this now works is basically a state machine, with three pieces of state:
The state can be updated in three different places.
return () => {
), if we have afileResult
, return it. Otherwise, create a newfilePromise
if we don't already have one (createFilePromise()
) and throwmostRecentError
.filePromise
resolves (.then((result) => {
), we set the contents tofileResult
, and clearfilePromise
.filePromise
rejects:a. If it rejects ((
.catch((err) => {
)) with "file doesn't exist", we setfileResult
to "no file exists" and clearfilePromise
.b. Otherwise, we set the error to
mostRecentError
, and clearfilePromise
.fileResult
.The end result is that we query the disk for a file, and throw a "timed out" error until we get back a result (including "no file exists"); if the server responds with an unexpected error, we start throwing that instead of "timed out" and retry.
If it succeeds, we start returning that file as the result.
If an upcoming assertion fails (including the implicit "file should exist" assertion), we clear the result and head back into the retry loop.