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: actionability not retrying in after hooks where the test failed #30831

Merged
merged 13 commits into from
Jan 31, 2025

Conversation

jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Jan 7, 2025

Additional details

When an action (such as click or type) is performed in an after hook where the test has failed, the actionability check is not retried and the click/type/other action? does not execute as expected. This is because Cypress is seeing that state('error') is set (since the test failed) and exiting because it believes the current runnable is in an error state so should stop retrying the check.

return cy.retry(retryActionability, options)

In actuality, we're in a different runnable - where the state has not errored. So we should continue retrying in the new runnable where the error is not present.

To fix the issue, I removed the check for state('error') altogether in the retries logic. This seems like it was put there for a purpose - and that tests would fail if you remove it, but all of our tests pass. I'm assuming that logic changed at some point where the condition is met properly regardless of this check now, but it'd be great to have some deeper verification.

Steps to test

Added tests to click.ts and type.ts although I feel like this isn't quite the right place for this logic since it's addressing an issue in retries, but no unit tests are there.

How has the user experience changed?

Click and type in after hooks now execute properly.

PR Tasks

Copy link

cypress bot commented Jan 10, 2025

cypress    Run #60162

Run Properties:  status check passed Passed #60162  •  git commit f680eb0dac: changelog update to be more specific
Project cypress
Branch Review after-hook-action-fix
Run status status check passed Passed #60162
Run duration 15m 07s
Commit git commit f680eb0dac: changelog update to be more specific
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 827
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 5687
View all changes introduced in this branch ↗︎

@jennifer-shehane jennifer-shehane changed the title fix: actions not running in after hooks that fail fix: actionability not retrying in after hooks where the test failed Jan 10, 2025
@jennifer-shehane jennifer-shehane self-assigned this Jan 10, 2025
cli/CHANGELOG.md Outdated Show resolved Hide resolved
@@ -116,7 +115,7 @@ export const create = (Cypress: ICypress, state: StateFunc, timeout: $Cy['timeou
// bug in bluebird with not propagating cancellations
// fast enough in a series of promises
// https://github.com/petkaantonov/bluebird/issues/1424
return state('canceled') || state('error') || runnableHasChanged()
return state('canceled') || runnableHasChanged()
Copy link
Contributor

Choose a reason for hiding this comment

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

Any idea if this code have any impact on before/beforeEach blocks? We have quite a few tests for this I believe in https://github.com/cypress-io/cypress/blob/after-hook-action-fix/packages/app/cypress/e2e/runner/runner.mochaEvents.cy.ts so it appears to not. Usually if the before/beforeEach fails I believe we skip the suite but I don't think that marks the runnable as canceled, but has the same effect?

I don't think we are going to know the true impact of this until we release it to the general public which might introduce the use/test case we are missing here... or it may not introduce anything at all except a fix!

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't have any negative side effects because the code running in hook runnables is (and should be running) - its just that commands weren't retrying.

cli/CHANGELOG.md Outdated Show resolved Hide resolved
@jennifer-shehane jennifer-shehane merged commit 9222e86 into develop Jan 31, 2025
88 of 89 checks passed
@jennifer-shehane jennifer-shehane deleted the after-hook-action-fix branch January 31, 2025 16:33
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.

Click and type events in after or afterEach hook don't work if one test fails
4 participants