Skip to content

Commit

Permalink
fix: tests don't hang when there's an error in before() block. (#9527)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Dec 7, 2020
1 parent d8f8593 commit 7289a45
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/driver/src/cypress/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,19 @@ const _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, se
delete hook.ctx.currentTest
}

// set the hook's id from the test because
// hooks do not have their own id, their
// commands need to grouped with the test
// and we can only associate them by this id
const test = getTestFromHookOrFindTest(hook)
let test = getTest()

// https://github.com/cypress-io/cypress/issues/9162
// In https://github.com/cypress-io/cypress/issues/8113, getTest() call was removed to handle skip() properly.
// But it caused tests to hang when there's a failure in before().
// That's why getTest() is revived and checks if the state is 'pending'.
if (!test || test.state === 'pending') {
// set the hook's id from the test because
// hooks do not have their own id, their
// commands need to grouped with the test
// and we can only associate them by this id
test = getTestFromHookOrFindTest(hook)
}

if (!test) {
// we couldn't find a test to run with this hook
Expand Down
9 changes: 9 additions & 0 deletions packages/runner/cypress/fixtures/issues/issue-9162.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('should not hang when an error is thrown in a before() block', () => {
before(() => {
expect(true).to.be.false
})

after(() => {})
it('has a test')
it('has another test')
})
15 changes: 15 additions & 0 deletions packages/runner/cypress/integration/issues/issue-9162.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const helpers = require('../../support/helpers')

const { createCypress } = helpers
const { runIsolatedCypress } = createCypress()

// https://github.com/cypress-io/cypress/issues/9162
describe('issue 9162', () => {
beforeEach(function () {
return runIsolatedCypress(`cypress/fixtures/issues/issue-9162.js`)
})

it('tests does not hang even if there is a fail in before().', function () {
cy.contains('expected true to be false')
})
})

2 comments on commit 7289a45

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7289a45 Dec 7, 2020

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.1.0/circle-develop-7289a45c123bd7abdcdf40825a3504503a34b9c9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7289a45 Dec 7, 2020

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.1.0/circle-develop-7289a45c123bd7abdcdf40825a3504503a34b9c9/cypress.tgz

Please sign in to comment.