forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins_spec.js
251 lines (224 loc) · 7.22 KB
/
plugins_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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
const path = require('path')
const systemTests = require('../lib/system-tests').default
const Fixtures = require('../lib/fixtures')
const e2eProject = Fixtures.projectPath('e2e')
describe('e2e plugins', function () {
systemTests.setup()
// this tests verifies stdout manually instead of via snapshot because
// there's a degree of randomness as to whether the error occurs before or
// after the run output starts. the important thing is that the run is
// failed and the right error is displayed
systemTests.it('fails when there is an async error at the root', {
browser: 'chrome',
spec: 'app.cy.js',
project: 'plugins-root-async-error',
expectedExitCode: 1,
onRun (exec) {
return exec().then(({ stdout }) => {
expect(stdout).to.include('We stopped running your tests because your config file crashed.')
expect(stdout).to.include('Your configFile threw an error from: cypress.config.js')
expect(stdout).to.include('Error: Root async error from config file')
})
},
})
// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23493
it.skip('fails when there is an async error inside an event handler', function () {
return systemTests.exec(this, {
spec: 'app.cy.js',
project: 'plugins-async-error',
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
config: {
video: false,
},
})
})
it('can modify config from plugins', function () {
return systemTests.exec(this, {
spec: 'app.cy.js',
env: 'foo=foo,bar=bar',
config: { pageLoadTimeout: 10000 },
project: 'plugin-config',
sanitizeScreenshotDimensions: true,
snapshot: true,
})
})
it('passes version correctly', function () {
return systemTests.exec(this, {
project: 'plugin-config-version',
})
})
it('catches invalid viewportWidth returned from plugins', function () {
// the test project returns config object with a bad value
return systemTests.exec(this, {
project: 'plugin-returns-bad-config',
expectedExitCode: 1,
snapshot: true,
})
})
it('catches invalid browsers list returned from plugins', function () {
return systemTests.exec(this, {
project: 'plugin-returns-empty-browsers-list',
expectedExitCode: 1,
snapshot: true,
})
})
it('catches invalid browser returned from plugins', function () {
return systemTests.exec(this, {
project: 'plugin-returns-invalid-browser',
expectedExitCode: 1,
snapshot: true,
})
})
it('can filter browsers from config', function () {
return systemTests.exec(this, {
project: 'plugin-filter-browsers',
// the test project filters available browsers
// and returns a list with JUST Electron browser
// and we ask to run in Chrome
// thus the test should fail
browser: 'chrome',
expectedExitCode: 1,
snapshot: true,
// we are interested in the actual filtered available browser name
// which should be "electron"
normalizeStdoutAvailableBrowsers: false,
})
})
systemTests.it('works with user extensions', {
browser: 'chrome',
spec: 'app.cy.js',
headed: true,
project: 'plugin-extension',
sanitizeScreenshotDimensions: true,
snapshot: true,
})
const pluginAfterScreenshot = 'plugin-after-screenshot'
it('calls after:screenshot for cy.screenshot() and failure screenshots', function () {
return systemTests.exec(this, {
spec: 'after_screenshot.cy.js',
project: pluginAfterScreenshot,
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
})
})
// https://github.com/cypress-io/cypress/issues/8079
it('does not report more screenshots than exist if user overwrites previous screenshot in afterScreenshot', function () {
return systemTests.exec(this, {
spec: 'after_screenshot_overwrite.cy.js',
project: pluginAfterScreenshot,
snapshot: true,
})
})
it('fails when invalid event is registered', function () {
return systemTests.exec(this, {
spec: 'app.cy.js',
project: 'plugin-validation-error',
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
})
})
it('fails when invalid event handler is registered', function () {
return systemTests.exec(this, {
spec: 'app.cy.js',
project: 'plugin-invalid-event-handler-error',
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
})
})
it('fails when setupNodeEvents is not a function', function () {
return systemTests.exec(this, {
spec: 'app.cy.js',
project: 'plugin-empty',
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
})
})
it('fails when there is no function exported', function () {
return systemTests.exec(this, {
spec: 'app_spec.js',
project: 'plugin-no-function-return',
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
})
})
it('fails when require throws synchronously', function () {
return systemTests.exec(this, {
spec: 'app_spec.js',
project: 'plugins-root-sync-error',
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
})
})
it('fails when require has a syntax error', function () {
return systemTests.exec(this, {
spec: 'app_spec.js',
project: 'plugins-root-syntax-error',
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
})
})
it('fails when function throws synchronously', function () {
return systemTests.exec(this, {
spec: 'app_spec.js',
project: 'plugins-function-sync-error',
sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
})
})
describe('preprocessor', function () {
it('passes with working preprocessor', function () {
return systemTests.exec(this, {
spec: 'app.cy.js',
project: 'working-preprocessor',
sanitizeScreenshotDimensions: true,
snapshot: true,
})
})
it('supports node builtins', function () {
return systemTests.exec(this, {
spec: 'node_builtins.cy.js',
})
})
// https://github.com/cypress-io/cypress/issues/8361
it('supports .mjs files', function () {
return systemTests.exec(this, {
spec: 'mjs_spec.cy.mjs',
})
})
})
describe('extra properties', function () {
it('passes projectRoot and default configFile to plugins function', function () {
return systemTests.exec(this, {
spec: 'plugins_config_extras.cy.js',
config: {
env: {
projectRoot: e2eProject,
configFile: path.join(e2eProject, 'cypress.config.js'),
},
},
})
})
it('passes custom configFile to plugins function', function () {
return systemTests.exec(this, {
spec: 'plugins_config_extras.cy.js',
configFile: 'cypress-alt.config.js',
config: {
env: {
projectRoot: e2eProject,
configFile: path.join(e2eProject, 'cypress-alt.config.js'),
},
},
})
})
})
})