Skip to content

Commit 3ad06db

Browse files
panzarinokuceb
andauthored
fix: it.skip no longer causes hooks to be assigned to the wrong test (#8113)
Co-authored-by: Ben Kucera <[email protected]>
1 parent 580087d commit 3ad06db

File tree

5 files changed

+147
-49
lines changed

5 files changed

+147
-49
lines changed

Diff for: packages/driver/src/cypress/runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ const _runnerListeners = (_runner, Cypress, _emissions, getTestById, getTest, se
622622
// hooks do not have their own id, their
623623
// commands need to grouped with the test
624624
// and we can only associate them by this id
625-
const test = getTest() || getTestFromHookOrFindTest(hook)
625+
const test = getTestFromHookOrFindTest(hook)
626626

627627
if (!test) {
628628
// we couldn't find a test to run with this hook

Diff for: packages/runner/cypress/fixtures/hooks/only_spec.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
describe('test wrapper', () => {
2+
it('test 1', () => {
3+
cy.log('testBody 1')
4+
})
5+
6+
describe('nested suite 1', () => {
7+
beforeEach(() => {
8+
cy.log('beforeEachHook 1')
9+
})
10+
11+
it.only('test 2', () => {
12+
cy.log('testBody 2')
13+
})
14+
})
15+
16+
describe('nested suite 2', () => {
17+
beforeEach(() => {
18+
cy.log('beforeEachHook 2')
19+
})
20+
21+
it('test 3', () => {
22+
cy.log('testBody 3')
23+
})
24+
})
25+
26+
describe('nested suite 3', () => {
27+
it.only('test 4', () => {
28+
cy.log('testBody 4')
29+
})
30+
})
31+
})

Diff for: packages/runner/cypress/fixtures/hooks/skip_spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe('outer suite', () => {
2+
it.skip('test 1', () => {
3+
cy.log('testBody 1')
4+
})
5+
6+
describe('inner suite', () => {
7+
before(() => {
8+
cy.log('beforeHook 1')
9+
})
10+
11+
it('test 2', () => {
12+
cy.log('testBody 2')
13+
})
14+
})
15+
})

Diff for: packages/runner/cypress/integration/reporter.hooks.spec.js

+100-48
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,119 @@ const { createCypress } = helpers
44
const { runIsolatedCypress } = createCypress()
55

66
describe('hooks', function () {
7-
beforeEach(function () {
8-
this.editor = {}
9-
10-
return runIsolatedCypress(`cypress/fixtures/hook_spec.js`, {
11-
onBeforeRun: ({ win }) => {
12-
this.win = win
13-
14-
win.runnerWs.emit.withArgs('get:user:editor')
15-
.yields({
16-
preferredOpener: this.editor,
17-
})
18-
},
7+
describe('displays hooks', function () {
8+
beforeEach(function () {
9+
return runIsolatedCypress(`cypress/fixtures/hooks/basic_spec.js`)
1910
})
20-
})
2111

22-
it('displays commands under correct hook', function () {
23-
cy.contains('tests 1').click()
12+
it('displays commands under correct hook', function () {
13+
cy.contains('tests 1').click()
2414

25-
cy.contains('before all').closest('.collapsible').should('contain', 'beforeHook 1')
26-
cy.contains('before each').closest('.collapsible').should('contain', 'beforeEachHook 1')
27-
cy.contains('test body').closest('.collapsible').should('contain', 'testBody 1')
28-
cy.contains('after each').closest('.collapsible').should('contain', 'afterEachHook 1')
29-
})
15+
cy.contains('before all').closest('.collapsible').should('contain', 'beforeHook 1')
16+
cy.contains('before each').closest('.collapsible').should('contain', 'beforeEachHook 1')
17+
cy.contains('test body').closest('.collapsible').should('contain', 'testBody 1')
18+
cy.contains('after each').closest('.collapsible').should('contain', 'afterEachHook 1')
19+
})
3020

31-
it('displays hooks without number when only one of type', function () {
32-
cy.contains('tests 1').click()
21+
it('displays hooks without number when only one of type', function () {
22+
cy.contains('tests 1').click()
3323

34-
cy.contains('before all').should('not.contain', '(1)')
35-
cy.contains('before each').should('not.contain', '(1)')
36-
cy.contains('after each').should('not.contain', '(1)')
24+
cy.contains('before all').should('not.contain', '(1)')
25+
cy.contains('before each').should('not.contain', '(1)')
26+
cy.contains('after each').should('not.contain', '(1)')
27+
})
28+
29+
it('displays hooks separately with number when more than one of type', function () {
30+
cy.contains('tests 2').click()
31+
32+
cy.contains('before all (1)').closest('.collapsible').should('contain', 'beforeHook 2')
33+
cy.contains('before all (2)').closest('.collapsible').should('contain', 'beforeHook 3')
34+
cy.contains('before each (1)').closest('.collapsible').should('contain', 'beforeEachHook 1')
35+
cy.contains('before each (2)').closest('.collapsible').should('contain', 'beforeEachHook 2')
36+
cy.contains('test body').closest('.collapsible').should('contain', 'testBody 2')
37+
cy.contains('after each (1)').closest('.collapsible').should('contain', 'afterEachHook 2')
38+
cy.contains('after each (2)').closest('.collapsible').should('contain', 'afterEachHook 1')
39+
cy.contains('after all (1)').closest('.collapsible').should('contain', 'afterHook 2')
40+
cy.contains('after all (2)').closest('.collapsible').should('contain', 'afterHook 1')
41+
})
3742
})
3843

39-
it('displays hooks separately with number when more than one of type', function () {
40-
cy.contains('tests 2').click()
41-
42-
cy.contains('before all (1)').closest('.collapsible').should('contain', 'beforeHook 2')
43-
cy.contains('before all (2)').closest('.collapsible').should('contain', 'beforeHook 3')
44-
cy.contains('before each (1)').closest('.collapsible').should('contain', 'beforeEachHook 1')
45-
cy.contains('before each (2)').closest('.collapsible').should('contain', 'beforeEachHook 2')
46-
cy.contains('test body').closest('.collapsible').should('contain', 'testBody 2')
47-
cy.contains('after each (1)').closest('.collapsible').should('contain', 'afterEachHook 2')
48-
cy.contains('after each (2)').closest('.collapsible').should('contain', 'afterEachHook 1')
49-
cy.contains('after all (1)').closest('.collapsible').should('contain', 'afterHook 2')
50-
cy.contains('after all (2)').closest('.collapsible').should('contain', 'afterHook 1')
44+
describe('open in IDE', function () {
45+
beforeEach(function () {
46+
this.editor = {}
47+
48+
return runIsolatedCypress(`cypress/fixtures/hooks/basic_spec.js`, {
49+
onBeforeRun: ({ win }) => {
50+
this.win = win
51+
52+
win.runnerWs.emit.withArgs('get:user:editor')
53+
.yields({
54+
preferredOpener: this.editor,
55+
})
56+
},
57+
})
58+
})
59+
60+
it('creates open in IDE button', function () {
61+
cy.contains('tests 1').click()
62+
63+
cy.get('.hook-open-in-ide').should('have.length', 4)
64+
})
65+
66+
it('properly opens file in IDE at hook', function () {
67+
cy.contains('tests 1').click()
68+
69+
cy.contains('Open in IDE').invoke('show').click().then(function () {
70+
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].file).to.include('basic_spec.js')
71+
// chrome sets the column to right before "before("
72+
// while firefox sets it right after "before("
73+
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].column).to.be.eq(Cypress.browser.family === 'firefox' ? 10 : 3)
74+
expect(this.win.runnerWs.emit.withArgs('open:file').lastCall.args[1].line).to.be.eq(2)
75+
})
76+
})
5177
})
5278

53-
it('creates open in IDE button', function () {
54-
cy.contains('tests 1').click()
79+
describe('skipped tests', function () {
80+
beforeEach(function () {
81+
return runIsolatedCypress(`cypress/fixtures/hooks/skip_spec.js`)
82+
})
83+
84+
it('does not display commands from skipped tests', function () {
85+
cy.contains('test 1').click()
86+
87+
cy.contains('test 1').parents('.collapsible').first().should('not.contain', 'testBody 1')
88+
})
89+
90+
// https://github.com/cypress-io/cypress/issues/8086
91+
it('displays before hook when following it.skip', function () {
92+
cy.contains('test 2').click()
5593

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

59-
it('properly opens file in IDE at hook', function () {
60-
cy.contains('tests 1').click()
98+
describe('only tests', function () {
99+
beforeEach(function () {
100+
return runIsolatedCypress(`cypress/fixtures/hooks/only_spec.js`)
101+
})
102+
103+
it('only displays tests with .only', function () {
104+
cy.contains('test wrapper').parents('.collapsible').first().should(($suite) => {
105+
expect($suite).not.to.contain('test 1')
106+
expect($suite).to.contain('nested suite 1')
107+
expect($suite).to.contain('test 2')
108+
expect($suite).not.to.contain('nested suite 2')
109+
expect($suite).not.to.contain('test 3')
110+
expect($suite).to.contain('nested suite 3')
111+
expect($suite).to.contain('test 4')
112+
})
113+
114+
cy.contains('test 2').click()
61115

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

0 commit comments

Comments
 (0)