diff --git a/packages/driver/src/cypress/runner.js b/packages/driver/src/cypress/runner.js index 2f0178aa5919..e8723a4feef4 100644 --- a/packages/driver/src/cypress/runner.js +++ b/packages/driver/src/cypress/runner.js @@ -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/) const retryAbleRunnable = isTest || isBeforeEachHook || isAfterEachHook const willRetry = (test._currentRetry < test._retries) && retryAbleRunnable @@ -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 diff --git a/packages/runner/cypress/integration/issues/issue-8350.js b/packages/runner/cypress/integration/issues/issue-8350.js new file mode 100644 index 000000000000..88685799a693 --- /dev/null +++ b/packages/runner/cypress/integration/issues/issue-8350.js @@ -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', () => { + runIsolatedCypress(() => { + before(() => { + beforeEach(() => { + }) + }) + + describe('s1', () => { + it('t1', () => { + // + }) + }) + }) + }) +}) diff --git a/packages/runner/cypress/support/helpers.js b/packages/runner/cypress/support/helpers.js index dba886e316fe..e27671a81283 100644 --- a/packages/runner/cypress/support/helpers.js +++ b/packages/runner/cypress/support/helpers.js @@ -237,11 +237,6 @@ function createCypress (defaultOptions = {}) { if (testsInOwnFile) return generateMochaTestsForWin(specWindow, mochaTestsOrFile) - specWindow.before = () => {} - specWindow.beforeEach = () => {} - specWindow.afterEach = () => {} - specWindow.after = () => {} - specWindow.describe = () => {} }) cy.stub(autCypress, 'run').snapshot(enableStubSnapshots).log(false).callsFake(runIsolatedCypress)