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

TS: separate Window type for application under test #7806

Merged
merged 11 commits into from Jul 6, 2020

Conversation

sainthkh
Copy link
Contributor

@sainthkh sainthkh commented Jun 25, 2020

User facing changelog

  • Correct type for Window object
  • Provide way to extend Window object type in Application Window.

Breaking change

  • The required minimum TypeScript version has been risen to 3.4.

Additional details

Why was this change necessary?

TypeScript users cannot use valid typescript types.

What is affected by this change?

N/A

Any implementation details to explain?

N/A

How has the user experience changed?

N/A

PR Tasks

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 25, 2020

Thanks for taking the time to open a PR!

@sainthkh sainthkh mentioned this pull request Jun 25, 2020
5 tasks
@sainthkh sainthkh marked this pull request as ready for review June 25, 2020 02:26
@sainthkh sainthkh added the type: breaking change Requires a new major release version label Jun 25, 2020
@sainthkh sainthkh marked this pull request as draft June 25, 2020 03:18
@sainthkh sainthkh marked this pull request as ready for review June 25, 2020 03:26
@flotwig flotwig mentioned this pull request Jun 26, 2020
21 tasks
cli/types/cypress.d.ts Outdated Show resolved Hide resolved
// Mike Woudenberg <https://github.com/mikewoudenberg>
// Robbert van Markus <https://github.com/rvanmarkus>
// Nicholas Boll <https://github.com/nicholasboll>
// TypeScript Version: 3.4
Copy link
Contributor

Choose a reason for hiding this comment

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

why did the entire file change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. I'll check if there's a change like line-ending.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Line ending was changed at d719f66. Fixed.

Copy link
Contributor

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

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

can we add an e2e test where we have a typescript fixture with ApplicationWindow interface with user property? To confirm the TS passes. Alternatively, and maybe even better is to add a recipe to cypress-example-recipes to show users how to add a property to window and have the types work out of the box.

// Mike Woudenberg <https://github.com/mikewoudenberg>
// Robbert van Markus <https://github.com/rvanmarkus>
// Nicholas Boll <https://github.com/nicholasboll>
// TypeScript Version: 3.4
Copy link
Contributor

Choose a reason for hiding this comment

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

can a PR to cypress-documentation for page https://on.cypress.io/typescript show the ApplicationWindow example AND minimum TypeScript version needed (3.4) in this case?

@@ -2001,7 +2006,7 @@ declare namespace Cypress {
})
```
*/
window(options?: Partial<Loggable & Timeoutable>): Chainable<Window>
window(options?: Partial<Loggable & Timeoutable>): Chainable<Window & typeof globalThis & ApplicationWindow>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there other instances of Chainable<Window> that should also be updated?

cli/types/cypress.d.ts Outdated Show resolved Hide resolved
@brian-mann
Copy link
Member

Can we open an issue documenting this fix and why it's necessary. Also per @bahmutov's comments, it seems like there's a bit more work to do on this PR yeah?

@OliverJAsh
Copy link
Contributor

I had a clear description in my original PR, but sadly that was closed: #6624

@sainthkh
Copy link
Contributor Author

@OliverJAsh

It's recommended to create an issue before submitting a PR in the contributing guide.

If there is not an associated open issue, create an issue using our Issue Template.

Sometimes, ignoring guides can cause unwanted results. (And I also know that it's really tedious to read every contributing guide before contributing.)

Anyway, I opened an issue at #7856.

@sainthkh sainthkh marked this pull request as draft June 30, 2020 03:06
@sainthkh
Copy link
Contributor Author

sainthkh commented Jun 30, 2020

@bahmutov @brian-mann

There are 3 more things to do:

@brian-mann
Copy link
Member

@sainthkh proceed ahead - we are trying to release 5.0.0 in the next day or two and want to get this in.

@jennifer-shehane
Copy link
Member

@sainthkh cy.window() is not the only command to return the Window, will the other command's definitions be extended? The other commands:

  • cy.go()
  • cy.reload()
  • cy.visit()

@jennifer-shehane
Copy link
Member

I've opened a PR for the docs to update the min required version to 3.4+ cypress-io/cypress-documentation#2945

Previously this would type error:

```ts
cy.window().then(window => window.eval('1'));
```
`globalThis` was added in 3.4.
@sainthkh
Copy link
Contributor Author

sainthkh commented Jun 30, 2020

It seems that kitchensink needs update after #7782. (CircleCI result link)

Copy link
Contributor

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

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

I think this is good to go, once merged into v5.0-release we will add testing the recipe cypress-io/cypress-example-recipes#515 PR

@bahmutov bahmutov changed the title Correct Window type. TS: separate Window type for application under test Jul 6, 2020
@bahmutov bahmutov merged commit 9e754d5 into cypress-io:v5.0-release Jul 6, 2020
@cypress-bot cypress-bot bot mentioned this pull request Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: breaking change Requires a new major release version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants