Skip to content

fix: find waiting for cy.intercept when it has been overwritten by the user#9596

Merged
bahmutov merged 14 commits into
developfrom
intercept-overwrite
Dec 11, 2020
Merged

fix: find waiting for cy.intercept when it has been overwritten by the user#9596
bahmutov merged 14 commits into
developfrom
intercept-overwrite

Conversation

@bahmutov
Copy link
Copy Markdown
Contributor

@bahmutov bahmutov commented Dec 9, 2020

User facing changelog

If the user overwrites cy.intercept, it still works with cy.wait(alias)

This used to show an error on cy.wait, and now it works

Cypress.Commands.overwrite('intercept', function (originalIntercept, ...args) {
  return cy.log('intercept!').then(() => {
    return originalIntercept(...args)
  })
})

cy.intercept('/foo', 'my value').as('netAlias')
cy.wait('@netAlias')

PR Tasks

  • Have tests been added/updated?
  • Has the original issue or this PR been tagged with a release in ZenHub?

@cypress-bot
Copy link
Copy Markdown
Contributor

cypress-bot Bot commented Dec 9, 2020

Thanks for taking the time to open a PR!

@bahmutov
Copy link
Copy Markdown
Contributor Author

bahmutov commented Dec 9, 2020

Notes: I built this PR on top of #9589 but probably will have clean merge

Also this PR will need reconcile with #9594

@cypress
Copy link
Copy Markdown

cypress Bot commented Dec 9, 2020



Test summary

9150 0 118 3Flakiness 1


Run details

Project cypress
Status Passed
Commit 454e420
Started Dec 11, 2020 3:53 PM
Ended Dec 11, 2020 4:05 PM
Duration 12:28 💡
OS Linux Debian - 10.5
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

cypress/integration/retries.ui.spec.js Flakiness
1 runner/cypress retries.ui.spec > opens attempt on each attempt failure for the screenshot, and closes after test passes

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

@bahmutov bahmutov marked this pull request as ready for review December 9, 2020 19:46
@bahmutov bahmutov requested a review from flotwig December 9, 2020 19:46
Comment on lines +172 to +176
const findNetworkAlias = (alias) => {
const routes = cy.state('routes') || {}

return _.find(_.values(routes), { alias })
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this doesn't cover dynamic aliases with req.alias i don't think

but luckily you can use getAliasedRequests: https://github.com/cypress-io/cypress/blob/c6f03e390f2b3c55f9c3b9a08611c6aabad2d607/packages/driver/src/cy/net-stubbing/aliasing.ts#L14-L28

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems to work as is, I have added a test to confirm it

Copy link
Copy Markdown
Contributor

@flotwig flotwig left a comment

Choose a reason for hiding this comment

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

nice

@bahmutov bahmutov requested a review from flotwig December 9, 2020 21:20
@bahmutov bahmutov changed the base branch from develop to command-overwrite December 9, 2020 21:31
flotwig
flotwig previously approved these changes Dec 9, 2020
Copy link
Copy Markdown
Contributor

@flotwig flotwig left a comment

Choose a reason for hiding this comment

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

Does not fix #3890, but as #3890 is getting deprecated anyways, I'll allow it, LGTM

@bahmutov bahmutov changed the base branch from command-overwrite to develop December 11, 2020 15:44
@bahmutov bahmutov dismissed flotwig’s stale review December 11, 2020 15:44

The base branch was changed.

@bahmutov bahmutov changed the title fix: find route alias for waiting even if the intercept has been overwritten by the user fix: find waiting for cy.intercept when it has been overwritten by the user Dec 11, 2020
@bahmutov bahmutov merged commit 49db3a6 into develop Dec 11, 2020
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.

Alias for intercept is not working if overwriting cy.intercept command

3 participants