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
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/driver/src/cypress/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,12 +1010,15 @@ const create = (specWindow, mocha, Cypress, cy) => {
}

const maybeHandleRetry = (runnable, err) => {
if (!err) return

const r = runnable
const isHook = r.type === 'hook'
const isTest = r.type === 'test'
const test = getTest() || getTestFromHook(runnable, getTestById)
const isBeforeEachHook = isHook && !!r.hookName.match(/before each/)
const isAfterEachHook = isHook && !!r.hookName.match(/after each/)
const hookName = isHook && getHookName(r)
const isBeforeEachHook = isHook && !!hookName.match(/before each/)
const isAfterEachHook = isHook && !!hookName.match(/after each/)
Comment on lines +1019 to +1021
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 😅

const retryAbleRunnable = isTest || isBeforeEachHook || isAfterEachHook
const willRetry = (test._currentRetry < test._retries) && retryAbleRunnable

Expand Down Expand Up @@ -1196,8 +1199,8 @@ const create = (specWindow, mocha, Cypress, cy) => {

const isHook = runnable.type === 'hook'

const isAfterEachHook = isHook && runnable.hookName.match(/after each/)
const isBeforeEachHook = isHook && runnable.hookName.match(/before each/)
const isAfterEachHook = isHook && hookName.match(/after each/)
const isBeforeEachHook = isHook && hookName.match(/before each/)

// if we've been told to skip hooks at a certain nested level
// this happens if we're handling a runnable that is going to retry due to failing in a hook
Expand Down
20 changes: 20 additions & 0 deletions packages/runner/cypress/integration/issues/issue-8350.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { createCypress } = require('../support/helpers')
const { runIsolatedCypress } = createCypress()

// 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

runIsolatedCypress(() => {
before(() => {
beforeEach(() => {
})
})

describe('s1', () => {
it('t1', () => {
//
})
})
})
})
})
5 changes: 0 additions & 5 deletions packages/runner/cypress/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,6 @@ function createCypress (defaultOptions = {}) {
if (testsInOwnFile) return

generateMochaTestsForWin(specWindow, mochaTestsOrFile)
specWindow.before = () => {}
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...


cy.stub(autCypress, 'run').snapshot(enableStubSnapshots).log(false).callsFake(runIsolatedCypress)
Expand Down