/
reporter.hooks.spec.js
153 lines (123 loc) · 5.49 KB
/
reporter.hooks.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const helpers = require('../support/helpers')
const { createCypress } = helpers
const { runIsolatedCypress } = createCypress()
describe('hooks', function () {
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()
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()
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')
})
})
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)
})
})
})
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.contains('test 2').parents('.collapsible').first().should('contain', 'before all')
})
})
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('test 2').parents('.collapsible').first().should(($test) => {
expect($test).to.contain('before each')
expect($test).to.contain('test body')
})
})
})
// https://github.com/cypress-io/cypress/issues/8189
it('can rerun without timeout error leaking into next run (due to run restart)', () => {
runIsolatedCypress(() => {
const top = window.parent
top.count = top.count || 0
Cypress.config('defaultCommandTimeout', 50)
afterEach(function () {
assert(true, `run ${top.count}`)
})
describe('s1', () => {
it('foo', () => {
cy.once('test:after:run', () => {
if (!top.count) {
requestAnimationFrame(() => {
window.parent.eventManager.reporterBus.emit('runner:restart')
})
}
top.count++
})
})
})
})
// wait until spec has run twice (due to one reload)
cy.window().its('count').should('eq', 2)
})
})