-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathcypress-stop.spec.ts
More file actions
200 lines (165 loc) · 7.76 KB
/
cypress-stop.spec.ts
File metadata and controls
200 lines (165 loc) · 7.76 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import systemTests from '../lib/system-tests'
describe('Cypress.stop()', () => {
const getRunnableEventCounts = (stderr: string) => {
const beforeRunCount = (stderr.match(/test:before:run(?!:async)/g) || []).length
const beforeRunAsyncCount = (stderr.match(/test:before:run:async/g) || []).length
const beforeAfterRunAsyncCount = (stderr.match(/test:before:after:run:async/g) || []).length
const afterRunCount = (stderr.match(/test:after:run(?!:async)/g) || []).length
const afterRunAsyncCount = (stderr.match(/test:after:run:async/g) || []).length
return {
beforeRunCount,
beforeRunAsyncCount,
beforeAfterRunAsyncCount,
afterRunCount,
afterRunAsyncCount,
}
}
const getGlobalHooks = (stderr: string) => {
const globalBeforeCalled = (stderr.match(/global before(?!Each)/g) || []).length > 0
const globalBeforeEachCalled = (stderr.match(/global beforeEach/g) || []).length > 0
const globalAfterEachCalled = (stderr.match(/global afterEach/g) || []).length > 0
const globalAfterCalled = (stderr.match(/global after(?!Each)/g) || []).length > 0
return {
globalBeforeCalled,
globalBeforeEachCalled,
globalAfterEachCalled,
globalAfterCalled,
}
}
systemTests.setup()
systemTests.it('stops execution when called in before', {
project: 'cypress-stop',
spec: 'before.cy.js',
snapshot: true,
expectedExitCode: 0,
browser: 'electron',
processEnv: {
ELECTRON_ENABLE_LOGGING: 1,
},
onStderr: (stderr) => {
expect(stderr).to.include('before 1')
expect(stderr).to.include('before 2')
expect(stderr).to.not.include('before 3')
const { globalBeforeCalled, globalBeforeEachCalled, globalAfterEachCalled, globalAfterCalled } = getGlobalHooks(stderr)
expect(globalBeforeCalled, 'globalBeforeCalled').to.be.true
expect(globalBeforeEachCalled, 'globalBeforeEachCalled').to.be.false
expect(globalAfterEachCalled, 'globalAfterEachCalled').to.be.false
expect(globalAfterCalled, 'globalAfterCalled').to.be.false
const { beforeRunCount, beforeRunAsyncCount, beforeAfterRunAsyncCount, afterRunCount, afterRunAsyncCount } = getRunnableEventCounts(stderr)
expect(beforeRunCount, 'beforeRunCount').to.equal(1)
expect(beforeRunAsyncCount, 'beforeRunAsyncCount').to.equal(1)
expect(beforeAfterRunAsyncCount, 'beforeAfterRunAsyncCount').to.equal(1)
expect(afterRunCount, 'afterRunCount').to.equal(1)
expect(afterRunAsyncCount, 'afterRunAsyncCount').to.equal(1)
return stderr
},
})
systemTests.it('stops execution when called in beforeEach', {
project: 'cypress-stop',
spec: 'beforeEach.cy.js',
snapshot: true,
expectedExitCode: 0,
browser: 'electron',
processEnv: {
ELECTRON_ENABLE_LOGGING: 1,
},
onStderr: (stderr) => {
expect(stderr).to.include('beforeEach 1')
expect(stderr).to.include('beforeEach 2')
expect(stderr).to.not.include('beforeEach 3')
const { globalBeforeCalled, globalBeforeEachCalled, globalAfterEachCalled, globalAfterCalled } = getGlobalHooks(stderr)
expect(globalBeforeCalled, 'globalBeforeCalled').to.be.true
expect(globalBeforeEachCalled, 'globalBeforeEachCalled').to.be.true
expect(globalAfterEachCalled, 'globalAfterEachCalled').to.be.false
expect(globalAfterCalled, 'globalAfterCalled').to.be.false
const { beforeRunCount, beforeRunAsyncCount, beforeAfterRunAsyncCount, afterRunCount, afterRunAsyncCount } = getRunnableEventCounts(stderr)
expect(beforeRunCount, 'beforeRunCount').to.equal(1)
expect(beforeRunAsyncCount, 'beforeRunAsyncCount').to.equal(1)
expect(beforeAfterRunAsyncCount, 'beforeAfterRunAsyncCount').to.equal(1)
expect(afterRunCount, 'afterRunCount').to.equal(1)
expect(afterRunAsyncCount, 'afterRunAsyncCount').to.equal(1)
return stderr
},
})
systemTests.it('stops execution when called in test', {
project: 'cypress-stop',
spec: 'test.cy.js',
snapshot: true,
expectedExitCode: 0,
browser: 'electron',
processEnv: {
ELECTRON_ENABLE_LOGGING: 1,
},
onStderr: (stderr) => {
expect(stderr).to.include('test 1')
expect(stderr).to.not.include('test 2')
expect(stderr).to.not.include('test 3')
const { globalBeforeCalled, globalBeforeEachCalled, globalAfterEachCalled, globalAfterCalled } = getGlobalHooks(stderr)
expect(globalBeforeCalled, 'globalBeforeCalled').to.be.true
expect(globalBeforeEachCalled, 'globalBeforeEachCalled').to.be.true
expect(globalAfterEachCalled, 'globalAfterEachCalled').to.be.true
expect(globalAfterCalled, 'globalAfterCalled').to.be.false
const { beforeRunCount, beforeRunAsyncCount, beforeAfterRunAsyncCount, afterRunCount, afterRunAsyncCount } = getRunnableEventCounts(stderr)
expect(beforeRunCount, 'beforeRunCount').to.equal(2)
expect(beforeRunAsyncCount, 'beforeRunAsyncCount').to.equal(2)
expect(beforeAfterRunAsyncCount, 'beforeAfterRunAsyncCount').to.equal(2)
expect(afterRunCount, 'afterRunCount').to.equal(2)
expect(afterRunAsyncCount, 'afterRunAsyncCount').to.equal(2)
return stderr
},
})
systemTests.it('stops execution when called in afterEach', {
project: 'cypress-stop',
spec: 'afterEach.cy.js',
snapshot: true,
expectedExitCode: 0,
browser: 'electron',
processEnv: {
ELECTRON_ENABLE_LOGGING: 1,
},
onStderr: (stderr) => {
expect(stderr).to.include('afterEach 1')
expect(stderr).to.include('afterEach 2')
expect(stderr).to.not.include('afterEach 3')
const { globalBeforeCalled, globalBeforeEachCalled, globalAfterEachCalled, globalAfterCalled } = getGlobalHooks(stderr)
expect(globalBeforeCalled, 'globalBeforeCalled').to.be.true
expect(globalBeforeEachCalled, 'globalBeforeEachCalled').to.be.true
expect(globalAfterEachCalled, 'globalAfterEachCalled').to.be.false
expect(globalAfterCalled, 'globalAfterCalled').to.be.false
const { beforeRunCount, beforeRunAsyncCount, beforeAfterRunAsyncCount, afterRunCount, afterRunAsyncCount } = getRunnableEventCounts(stderr)
expect(beforeRunCount, 'beforeRunCount').to.equal(1)
expect(beforeRunAsyncCount, 'beforeRunAsyncCount').to.equal(1)
expect(beforeAfterRunAsyncCount, 'beforeAfterRunAsyncCount').to.equal(1)
expect(afterRunCount, 'afterRunCount').to.equal(1)
expect(afterRunAsyncCount, 'afterRunAsyncCount').to.equal(1)
return stderr
},
})
systemTests.it('stops execution when called in after', {
project: 'cypress-stop',
spec: 'after.cy.js',
snapshot: true,
expectedExitCode: 0,
browser: 'electron',
processEnv: {
ELECTRON_ENABLE_LOGGING: 1,
},
onStderr: (stderr) => {
expect(stderr).to.include('after 1')
expect(stderr).to.include('after 2')
expect(stderr).to.not.include('after 3')
const { globalBeforeCalled, globalBeforeEachCalled, globalAfterEachCalled, globalAfterCalled } = getGlobalHooks(stderr)
expect(globalBeforeCalled, 'globalBeforeCalled').to.be.true
expect(globalBeforeEachCalled, 'globalBeforeEachCalled').to.be.true
expect(globalAfterEachCalled, 'globalAfterEachCalled').to.be.true
expect(globalAfterCalled, 'globalAfterCalled').to.be.false
const { beforeRunCount, beforeRunAsyncCount, beforeAfterRunAsyncCount, afterRunCount, afterRunAsyncCount } = getRunnableEventCounts(stderr)
expect(beforeRunCount, 'beforeRunCount').to.equal(1)
expect(beforeRunAsyncCount, 'beforeRunAsyncCount').to.equal(1)
expect(beforeAfterRunAsyncCount, 'beforeAfterRunAsyncCount').to.equal(1)
expect(afterRunCount, 'afterRunCount').to.equal(1)
expect(afterRunAsyncCount, 'afterRunAsyncCount').to.equal(1)
return stderr
},
})
})