Skip to content

Commit

Permalink
fix: it.skip no longer causes hooks to be assigned to the wrong test (#…
Browse files Browse the repository at this point in the history
…8113)

Co-authored-by: Ben Kucera <[email protected]>
  • Loading branch information
panzarino and kuceb authored Aug 4, 2020
1 parent 580087d commit 3ad06db
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 49 deletions.
2 changes: 1 addition & 1 deletion packages/driver/src/cypress/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ const _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, se
// 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 = getTest() || getTestFromHookOrFindTest(hook)
const test = getTestFromHookOrFindTest(hook)

if (!test) {
// we couldn't find a test to run with this hook
Expand Down
31 changes: 31 additions & 0 deletions packages/runner/cypress/fixtures/hooks/only_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe('test wrapper', () => {
it('test 1', () => {
cy.log('testBody 1')
})

describe('nested suite 1', () => {
beforeEach(() => {
cy.log('beforeEachHook 1')
})

it.only('test 2', () => {
cy.log('testBody 2')
})
})

describe('nested suite 2', () => {
beforeEach(() => {
cy.log('beforeEachHook 2')
})

it('test 3', () => {
cy.log('testBody 3')
})
})

describe('nested suite 3', () => {
it.only('test 4', () => {
cy.log('testBody 4')
})
})
})
15 changes: 15 additions & 0 deletions packages/runner/cypress/fixtures/hooks/skip_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe('outer suite', () => {
it.skip('test 1', () => {
cy.log('testBody 1')
})

describe('inner suite', () => {
before(() => {
cy.log('beforeHook 1')
})

it('test 2', () => {
cy.log('testBody 2')
})
})
})
148 changes: 100 additions & 48 deletions packages/runner/cypress/integration/reporter.hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,119 @@ const { createCypress } = helpers
const { runIsolatedCypress } = createCypress()

describe('hooks', function () {
beforeEach(function () {
this.editor = {}

return runIsolatedCypress(`cypress/fixtures/hook_spec.js`, {
onBeforeRun: ({ win }) => {
this.win = win

win.runnerWs.emit.withArgs('get:user:editor')
.yields({
preferredOpener: this.editor,
})
},
describe('displays hooks', function () {
beforeEach(function () {
return runIsolatedCypress(`cypress/fixtures/hooks/basic_spec.js`)
})
})

it('displays commands under correct hook', function () {
cy.contains('tests 1').click()
it('displays commands under correct hook', function () {
cy.contains('tests 1').click()

cy.contains('before all').closest('.collapsible').should('contain', 'beforeHook 1')
cy.contains('before each').closest('.collapsible').should('contain', 'beforeEachHook 1')
cy.contains('test body').closest('.collapsible').should('contain', 'testBody 1')
cy.contains('after each').closest('.collapsible').should('contain', 'afterEachHook 1')
})
cy.contains('before all').closest('.collapsible').should('contain', 'beforeHook 1')
cy.contains('before each').closest('.collapsible').should('contain', 'beforeEachHook 1')
cy.contains('test body').closest('.collapsible').should('contain', 'testBody 1')
cy.contains('after each').closest('.collapsible').should('contain', 'afterEachHook 1')
})

it('displays hooks without number when only one of type', function () {
cy.contains('tests 1').click()
it('displays hooks without number when only one of type', function () {
cy.contains('tests 1').click()

cy.contains('before all').should('not.contain', '(1)')
cy.contains('before each').should('not.contain', '(1)')
cy.contains('after each').should('not.contain', '(1)')
cy.contains('before all').should('not.contain', '(1)')
cy.contains('before each').should('not.contain', '(1)')
cy.contains('after each').should('not.contain', '(1)')
})

it('displays hooks separately with number when more than one of type', function () {
cy.contains('tests 2').click()

cy.contains('before all (1)').closest('.collapsible').should('contain', 'beforeHook 2')
cy.contains('before all (2)').closest('.collapsible').should('contain', 'beforeHook 3')
cy.contains('before each (1)').closest('.collapsible').should('contain', 'beforeEachHook 1')
cy.contains('before each (2)').closest('.collapsible').should('contain', 'beforeEachHook 2')
cy.contains('test body').closest('.collapsible').should('contain', 'testBody 2')
cy.contains('after each (1)').closest('.collapsible').should('contain', 'afterEachHook 2')
cy.contains('after each (2)').closest('.collapsible').should('contain', 'afterEachHook 1')
cy.contains('after all (1)').closest('.collapsible').should('contain', 'afterHook 2')
cy.contains('after all (2)').closest('.collapsible').should('contain', 'afterHook 1')
})
})

it('displays hooks separately with number when more than one of type', function () {
cy.contains('tests 2').click()

cy.contains('before all (1)').closest('.collapsible').should('contain', 'beforeHook 2')
cy.contains('before all (2)').closest('.collapsible').should('contain', 'beforeHook 3')
cy.contains('before each (1)').closest('.collapsible').should('contain', 'beforeEachHook 1')
cy.contains('before each (2)').closest('.collapsible').should('contain', 'beforeEachHook 2')
cy.contains('test body').closest('.collapsible').should('contain', 'testBody 2')
cy.contains('after each (1)').closest('.collapsible').should('contain', 'afterEachHook 2')
cy.contains('after each (2)').closest('.collapsible').should('contain', 'afterEachHook 1')
cy.contains('after all (1)').closest('.collapsible').should('contain', 'afterHook 2')
cy.contains('after all (2)').closest('.collapsible').should('contain', 'afterHook 1')
describe('open in IDE', function () {
beforeEach(function () {
this.editor = {}

return runIsolatedCypress(`cypress/fixtures/hooks/basic_spec.js`, {
onBeforeRun: ({ win }) => {
this.win = win

win.runnerWs.emit.withArgs('get:user:editor')
.yields({
preferredOpener: this.editor,
})
},
})
})

it('creates open in IDE button', function () {
cy.contains('tests 1').click()

cy.get('.hook-open-in-ide').should('have.length', 4)
})

it('properly opens file in IDE at hook', function () {
cy.contains('tests 1').click()

cy.contains('Open in IDE').invoke('show').click().then(function () {
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].file).to.include('basic_spec.js')
// chrome sets the column to right before "before("
// while firefox sets it right after "before("
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].column).to.be.eq(Cypress.browser.family === 'firefox' ? 10 : 3)
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].line).to.be.eq(2)
})
})
})

it('creates open in IDE button', function () {
cy.contains('tests 1').click()
describe('skipped tests', function () {
beforeEach(function () {
return runIsolatedCypress(`cypress/fixtures/hooks/skip_spec.js`)
})

it('does not display commands from skipped tests', function () {
cy.contains('test 1').click()

cy.contains('test 1').parents('.collapsible').first().should('not.contain', 'testBody 1')
})

// https://github.com/cypress-io/cypress/issues/8086
it('displays before hook when following it.skip', function () {
cy.contains('test 2').click()

cy.get('.hook-open-in-ide').should('have.length', 4)
cy.contains('test 2').parents('.collapsible').first().should('contain', 'before all')
})
})

it('properly opens file in IDE at hook', function () {
cy.contains('tests 1').click()
describe('only tests', function () {
beforeEach(function () {
return runIsolatedCypress(`cypress/fixtures/hooks/only_spec.js`)
})

it('only displays tests with .only', function () {
cy.contains('test wrapper').parents('.collapsible').first().should(($suite) => {
expect($suite).not.to.contain('test 1')
expect($suite).to.contain('nested suite 1')
expect($suite).to.contain('test 2')
expect($suite).not.to.contain('nested suite 2')
expect($suite).not.to.contain('test 3')
expect($suite).to.contain('nested suite 3')
expect($suite).to.contain('test 4')
})

cy.contains('test 2').click()

cy.contains('Open in IDE').invoke('show').click().then(function () {
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].file).to.include('hook_spec.js')
// chrome sets the column to right before "before("
// while firefox sets it right after "before("
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].column).to.be.eq(Cypress.browser.family === 'firefox' ? 10 : 3)
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].line).to.be.eq(2)
cy.contains('test 2').parents('.collapsible').first().should(($test) => {
expect($test).to.contain('before each')
expect($test).to.contain('test body')
})
})
})
})

4 comments on commit 3ad06db

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3ad06db Aug 4, 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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.12.1/linux-x64/circle-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-412595/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.12.1/circle-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-412571/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3ad06db Aug 4, 2020

Choose a reason for hiding this comment

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

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.12.1/win32-x64/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.12.1/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.12.1/win32-x64/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.12.1/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.12.1/win32-x64/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.12.1/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.12.1/win32-x64/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.12.1/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3ad06db Aug 4, 2020

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.12.1/win32-ia32/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.12.1/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.12.1/win32-ia32/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.12.1/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.12.1/win32-ia32/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.12.1/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.12.1/win32-ia32/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.12.1/appveyor-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-34466514/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3ad06db Aug 4, 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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.12.1/darwin-x64/circle-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-412601/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.12.1/circle-develop-3ad06dba54760cbeac36b993f1fdcd6492d0b619-412598/cypress.tgz

Please sign in to comment.