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

Dl/cypress@12 expect fix #235

Merged
merged 10 commits into from
Aug 30, 2023
Merged

Dl/cypress@12 expect fix #235

merged 10 commits into from
Aug 30, 2023

Conversation

wKich
Copy link
Member

@wKich wKich commented Aug 16, 2023

Motivation

Fix #234

Approach

It seems Cypress@12 doesn't expose _commands field https://github.com/cypress-io/cypress/blob/ae4cf2b553255f38ca83e14a09dd891b487e1a39/packages/driver/src/cypress/commands.ts#L45 which cause the error mentioned in #234

Signed-off-by: Dmitriy Lazarev <[email protected]>
Signed-off-by: Dmitriy Lazarev <[email protected]>
@wKich wKich requested a review from cowboyd August 16, 2023 12:49
@changeset-bot
Copy link

changeset-bot bot commented Aug 16, 2023

🦋 Changeset detected

Latest commit: 4615e5b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@interactors/with-cypress Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Aug 16, 2023

Deploy Preview for interactors canceled.

Name Link
🔨 Latest commit 4615e5b
🔍 Latest deploy log https://app.netlify.com/sites/interactors/deploys/64ef18b605b4a50007bcf2c0

Signed-off-by: Dmitriy Lazarev <[email protected]>
// NOTE: Add interaction assertion function, Cypress also overrides `expect` method to a wrapper function
Cypress.Commands.overwrite('expect', interactionExpect);
if ('_commands' in Cypress.Commands) {
// @ts-expect-error Cypress stores a reference to commands object and use it to check overwiritability of commands
Copy link
Contributor

Choose a reason for hiding this comment

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

pedantic: s/overwiritability/overwritability/

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks :)

Signed-off-by: Dmitriy Lazarev <[email protected]>
Copy link
Member

@cowboyd cowboyd left a comment

Choose a reason for hiding this comment

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

Good to go! Although it looks like it's not passing on CI.

@ostapwd
Copy link

ostapwd commented Aug 28, 2023

Hi @wKich!
It looks like cypres.json should be replaced by cypress.config.ts in /packages/with-cypress dir

image

@cowboyd
Copy link
Member

cowboyd commented Aug 28, 2023

@wKich Odd that this is still failing Any idea what's up?

@wKich
Copy link
Member Author

wKich commented Aug 28, 2023

@cowboyd yep. It's time to fix cypress-io/cypress#22733

@ostapwd
Copy link

ostapwd commented Aug 29, 2023

Hi @cowboyd @wKich
In my team, we are using Interactors for the FOLIO project, and we need the latest version of the Cypress. As a workaround is there a chance to add a new command instead of overriding existing, somethings like 'expectThat' (cy.expectThat())?

This approach might look ugly but we will avoid any conflicts in the future.
Also if it's possible to keep this logic
cy.expectThat = ( interaction: AssertionInteraction<Element> | AssertionInteraction<Element>[] | unknown, message?: string ) => { let interactions = Array.isArray(interaction) ? interaction : [interaction] if (isInteractions(interactions)) { return interactionExpect(interactions) } else { return chaiExpect(interaction, message) } }
all we have to do in our project is just to replace cy.expect() with cy.expectThat and that shouldn't be painful

@wKich
Copy link
Member Author

wKich commented Aug 29, 2023

@ostapwd added a fallback expectInteractor. According cypress code they are trying to restrict users from overwriting built-in commands. So I think we need to do a breaking change and rename cy.expect to something else. In this PR I just added the fallback.

@cowboyd fyi

@cowboyd
Copy link
Member

cowboyd commented Aug 29, 2023

I really like @ostapwd's suggestion! cy.expectThat() /cc @wKich

@wKich wKich merged commit 944d64b into main Aug 30, 2023
5 checks passed
@wKich wKich deleted the dl/cypress@12-expect-fix branch August 30, 2023 10:37
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.

Interactors don't work after updating to Cypress 12
4 participants