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: remove unnecessary eventemitter2 type definitions from cy, Cypress #21286

Merged
merged 8 commits into from May 11, 2022

Conversation

sainthkh
Copy link
Contributor

@sainthkh sainthkh commented May 2, 2022

User facing changelog

Remove unnecessary eventemitter2 type definitions from cy and Cypress.

Additional details

  • Why was this change necessary? => Remove undocumented eventemitter2 definitions from cy and Cypress. Especially, cy.waitFor is really confusing with cy.wait for beginners.
  • What is affected by this change? => N/A
  • Any implementation details to explain? => Created a new interface and cherry-picked the definitions.

How has the user experience changed?

cy.waitFor() // Before: type passes. After: Type fails.

PR Tasks

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

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 2, 2022

Thanks for taking the time to open a PR!

@sainthkh sainthkh marked this pull request as ready for review May 3, 2022 07:21
@sainthkh sainthkh requested a review from a team as a code owner May 3, 2022 07:21
@sainthkh sainthkh requested review from jennifer-shehane and removed request for a team May 3, 2022 07:21
@jennifer-shehane jennifer-shehane removed their request for review May 5, 2022 18:07
@@ -87,3 +87,17 @@ namespace CypressActionCommandOptionTests {
cy.get('el').click({scrollBehavior: false})
cy.get('el').click({scrollBehavior: true}) // $ExpectError
}

namespace CyEventEmitterTests {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we put a comment here (or alongside the types themselves) explaining why we'd expect errors for waitFor/prependListener? Without context, these assertions seem a little random.

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 wrote the reason like below:

// `waitFor` doesn't exist in Node EventEmitter 
// and it confuses the users with `cy.wait`

off: CyActions
emit: EventEmitter2['emit']
removeListener: EventEmitter2['removeListener']
removeAllListeners: EventEmitter2['removeAllListeners']
Copy link
Contributor

Choose a reason for hiding this comment

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

Our docs say that Cypress/cy are "standard Node event emitters": https://docs.cypress.io/api/events/catalog-of-events#Binding-to-Events

I'm wondering if we need to either:

  • Change the wording there if we only intend to support a subset of the API
  • Add more functions here to align with what Node's event emitter provides, like addListener. The other missing APIs are probably less frequently used, but it's hard to say.

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 decided to change the type to Omit<EventEmitter2, 'waitFor'>.

Because other functions are harmless, they're really unlikely to be used in the real world cases, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

@tbiethman tbiethman merged commit 9b11e2c into cypress-io:develop May 11, 2022
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.

Why can I use cy.waitFor()?
4 participants