-
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: Adding an existing command with Cypress.Commands.add()
will throw an error
#18587
fix: Adding an existing command with Cypress.Commands.add()
will throw an error
#18587
Conversation
Thanks for taking the time to open a PR!
|
Cypress.Commands.add()
will throw an errorCypress.Commands.add()
will throw an error
Test summaryRun details
View run in Cypress Dashboard ➡️ Flakiness
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 |
…/cypress-io/cypress into issue-18572-add-existing-command
Co-authored-by: Chris Breiding <[email protected]>
@davidmunechika @chrisbreiding Is there a way to get a better stack trace on this or a code frame where it is called? I guess my main concern is that the use case for this may be that Cypress adds an |
Are we sure this is a Also, should probably update the user-facing changelog with the fact that this only applies to builtin cypress commands (and they can continue to use cy.add() to overwrite their own commands, a'la in beforeEach()). |
Co-authored-by: Jennifer Shehane <[email protected]>
669d364
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.
@jennifer-shehane We improved the error stack so it now points to the user's code and shows a code frame.
I agree with @BlueWinds that this should probably be considered a breaking change and noted as such in the changelog.
* develop: (329 commits) chore: Update Chrome (stable) to 96.0.4664.45 (#18931) fix: Loading of specs with % in the filename (#18877) chore: refactor `create` into class `$Cy` (#18715) chore: Update Chrome (beta) to 96.0.4664.45 (#18891) fix: flaky `system-tests-firefox` job (#18848) release 9.0.0 feat: ensure major release have conduit app wait on localhost:3000 fix install-required-node use --legacy-peer-deps feat: ensure major release fix darwin node install chore(driver): fix integration test retry configuration (#18643) feat(deps): update dependency electron to v15 🌟 (#18317) chore: Bind this correctly when setting response headers with cy.route() (#18859) feat: create config package for config validation (#18589) chore: patch `winston` to suppress `padLevels` warning (#18824) chore: test out major release build fix: remove outdated npm registry links (#18727) fix: Adding an existing command with `Cypress.Commands.add()` will throw an error (#18587) ...
User facing changelog
Attempting to add an existing built-in Cypress command using
Cypress.Commands.add()
will throw an error, indicating thatCypress.Commands.overwrite()
should be used instead to overwrite the behavior of existing commands. This is a breaking change since errors will now be thrown if users had previously added any new commands which already existed in Cypress.Additional details
Previously, Cypress would not warn you when you are trying to add a command that already exists in Cypress. This could lead to unexpected behavior with the command since it is unclear which would take precedence.
Now, if a user tries to add a command that already exists (such as
Cypress.Commands.add('get', ...)
), Cypress will throw an error indicating thatoverwrite
should be used in these situations instead.Note: the implementation in this PR will NOT throw if a user attempts to add a duplicate custom command that they have already defined. This only checks for collisions with core Cypress commands.
PR Tasks
cypress-documentation
? Adding an existing command or reserved internal function withCypress.Commands.add()
will throw an error cypress-documentation#4178type definitions
?cypress.schema.json
?