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

chore: Reapply state refactor #23092

Merged
merged 7 commits into from Aug 3, 2022
Merged

chore: Reapply state refactor #23092

merged 7 commits into from Aug 3, 2022

Conversation

BlueWinds
Copy link
Contributor

User facing changelog

cy.state('subject') is deprecated, and reading from it will log a warning to the console. Prefer cy.currentSubject() instead.

Additional details

These refactors were previously merged, and reverted when it became clear it was causing issues with one of our develop-only tests. #23047. This PR contains a fix for that test failure - see comments below for details.


This PR is a follow up to #22571, and refactors how Cypress keeps track of the current subject. No behavior has changed, but this is in preparation for addressing Detached DOM errors (#7306).

While we would normally consider internal state to be internal, cypress-testing-library relies on cy.state('subject'). Therefore, this PR includes a shim to keep that call working as before. Once this PR is released, we will follow up with them to move over to the new call, ensuring that no end users (with or without cypress-testing-library) ever experience disruption (beyond the console warning).

Steps to test

The automated tests cover this code extensively, especially the packages/driver e2e tests.

How has the user experience changed?

No change. There is less indirection around how commands are added and invoked, which results in less memory churn and CPU usage (but only a ms here or there, not really noticeable).

PR Tasks

  • Have tests been added/updated? Yes
  • [n/a] Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [n/a] Has a PR for user-facing changes been opened in cypress-documentation?
  • [n/a] Have API changes been updated in the type definitions?

@BlueWinds BlueWinds requested a review from a team as a code owner August 3, 2022 18:34
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 3, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Aug 3, 2022



Test summary

4379 0 51 0Flakiness 0


Run details

Project cypress
Status Passed
Commit 930b4da
Started Aug 3, 2022 9:14 PM
Ended Aug 3, 2022 9:26 PM
Duration 11:43 💡
OS Linux Debian - 11.3
Browser Firefox 99

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@@ -27,7 +27,7 @@ mainBuildFilters: &mainBuildFilters
branches:
only:
- develop
- revert-22742
- reapply-state-refactor
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've updated this branch to run the complete set of linux tasks, including the test-binary-against-todomvc-firefox stage which caused to be be reverted previously.

@@ -29,6 +29,11 @@ describe('src/cy/commands/aliasing', () => {
})
})

it('stores the lookup as an alias when .then() is an intermediate', () => {
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 was the minimal repro of the issue causing the todomvc failure, included in the monorepo to prevent any future regression. Explanation about what was going wrong and how it was fixed in another comment.

@@ -860,8 +846,15 @@ export class $Cy extends EventEmitter2 implements ITimeouts, IStability, IAssert
return memo
}, [initialCommand])

const chainerId = this.state('chainerId')
Copy link
Contributor Author

@BlueWinds BlueWinds Aug 3, 2022

Choose a reason for hiding this comment

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

Here is the change which fixes the todomvc regression. The source of the error was very, very distant from the error that was ultimately thrown.

In the old code, replayCommandFrom() updates the chainerId before cloning - it updates the original command. This was causing a chain of unintended side-effects, ultimately resulting in an undefined subject, rather than the one properly stored in cy.state('subjects').

In the new version, it clones and then updates, leaving the original command intact. Cypress no longer gets confused when replaying commands.


I'm not terribly fussed about the exact details here - this entire "replayCommandsFrom" logic is going to be removed as part of the Detached DOM work. As long as it keeps working in the interim (and we have a lot of tests ensuring it does), I'm not much fussed about exactly what it looks like.

@BlueWinds BlueWinds changed the title Reapply state refactor chore: Reapply state refactor Aug 3, 2022
Comment on lines +223 to +229
* As part of the Detached DOM effort, we're changing the way subjects are determined in Cypress.
* While we usually consider cy.state() to be internal, in the case of cy.state('subject'),
* cypress-testing-library, one of our most popular plugins, relies on it.
* https://github.com/testing-library/cypress-testing-library/blob/1af9f2f28b2ca62936da8a8acca81fc87e2192f7/src/utils.js#L9
*
* Therefore, we've added this shim to continue to support them. The library is actively maintained, so this
* shouldn't need to stick around too long (written 07/22).
Copy link
Member

Choose a reason for hiding this comment

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

Nice work finding usage and shiming to support cypress-testing-library

Co-authored-by: Matt Henkes <mjhenkes@gmail.com>
@lmiller1990
Copy link
Contributor

lmiller1990 commented Aug 3, 2022

Great!

Will leave the CI dance and merging to you.

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.

None yet

3 participants