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: 5.0 runner hangs on nested hook #8379

Merged
merged 4 commits into from
Aug 24, 2020
Merged

fix: 5.0 runner hangs on nested hook #8379

merged 4 commits into from
Aug 24, 2020

Conversation

kuceb
Copy link
Contributor

@kuceb kuceb commented Aug 21, 2020

User facing changelog

  • Bug fix: fix issue causing tests to hang when spec code includes nested hook declarations

Additional details

  • an uncaught error was being thrown inbetween the runnable.next() calls, causing the runner to never progress to the next runnable
  • we never intended for hooks to be nested since it provides no real use case. However some users have written nested hooks and it's a simple fix for this regression that occurred in 5.0
  • NOTE: we should probably error when we detect a nested hook was declared (leads to reporter issues as well). However that is more of a change than this PR which fixes a bug introduced in 5.0. Most users are accidentally writing nested hooks which can lead to performance problems, especially when nesting each hooks inside of each hooks:
// this is bad, and will register a new afterEach hook for every test
beforeEach(()=>{
  // setup...
  afterEach(()=>{
  // tear down...
  })
})

How has the user experience changed?

PR Tasks

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

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 21, 2020

Thanks for taking the time to open a PR!

Comment on lines +1019 to +1021
const hookName = isHook && getHookName(r)
const isBeforeEachHook = isHook && !!hookName.match(/before each/)
const isAfterEachHook = isHook && !!hookName.match(/after each/)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all these isHook && are not very pretty 😅

specWindow.beforeEach = () => {}
specWindow.afterEach = () => {}
specWindow.after = () => {}
specWindow.describe = () => {}
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we will see if this was added for a reason...

@kuceb kuceb changed the title fix: Runner hangs on nested hook fix: 5.0 runner hangs on nested hook Aug 21, 2020
@cypress
Copy link

cypress bot commented Aug 21, 2020



Test summary

8128 0 108 3


Run details

Project cypress
Status Passed
Commit 2ee35a9
Started Aug 21, 2020 10:17 PM
Ended Aug 21, 2020 10:24 PM
Duration 07:05 💡
OS Linux Debian - 10.2
Browser Multiple

View run in Cypress Dashboard ➡️


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

Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

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

I verified this fixes the original issue. Is tested 👍


// https://github.com/cypress-io/cypress/issues/8350
describe('issue-8350', () => {
it('does not hang on nested hook', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add more tests for different cases like beforeEach in beforeEach, afterEach in beforeEach, before in before?

Copy link
Contributor Author

@kuceb kuceb Aug 24, 2020

Choose a reason for hiding this comment

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

the bug occurs when a hook is registered after the test has started, so it applies to more than just nested hooks. for that reason I think this covers it, but we could rename he test to something more generic

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.

Nesting hooks within other hooks causes the test to never finish (runs forever)
3 participants