forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisit_spec.js
237 lines (200 loc) · 5.44 KB
/
visit_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
const _ = require('lodash')
const Bluebird = require('bluebird')
const cert = require('@packages/https-proxy/test/helpers/certs')
const https = require('https')
const useragent = require('express-useragent')
const { allowDestroy } = require('@packages/network')
const systemTests = require('../lib/system-tests').default
// create an HTTPS server that forces TLSv1
const startTlsV1Server = (port) => {
return Bluebird.fromCallback((cb) => {
const opts = _.merge({
secureProtocol: 'TLSv1_server_method',
}, cert)
const serv = https.createServer(opts, (req, res) => {
res.setHeader('content-type', 'text/html')
return res.end('foo')
})
allowDestroy(serv)
serv.listen(port, (err) => {
return cb(null, serv)
})
return serv.on('error', cb)
})
}
const onServer = function (app) {
app.get('/agent.json', (req, res) => {
const source = req.headers['user-agent'] != null ? req.headers['user-agent'] : ''
const ua = useragent.parse(source)
return res.send({ agent: ua })
})
app.get('/agent.html', (req, res) => {
const source = req.headers['user-agent'] != null ? req.headers['user-agent'] : ''
const ua = useragent.parse(source)
return res.send(`\
<html>
<a href='/agent.html'>agent</a>
<div id="agent">
${JSON.stringify(ua)}
</div>
</html\
`)
})
app.get('/headers.html', (req, res) => {
return res.send(`\
<html>
<div id="headers">
${JSON.stringify(req.headers)}
</div>
</html>\
`)
})
app.get('/fail', (req, res) => {
return res.sendStatus(500)
})
app.get('/timeout', (req, res) => {
const ms = req.query.ms != null ? req.query.ms : 0
return setTimeout(() => {
return res.send(`<html>timeout: <span>${ms}</span></html>`)
}
, ms)
})
app.get('/response_never_finishes', (req, res) => {
// dont ever end this response
return res.type('html').write('foo\n')
})
// https://github.com/cypress-io/cypress/issues/5602
app.get('/invalid-header-char', (req, res) => {
// express/node may interfere if we just use res.setHeader
res.connection.write(
`\
HTTP/1.1 200 OK
Content-Type: text/html
Set-Cookie: foo=bar-${String.fromCharCode(1)}-baz
foo\
`,
)
return res.connection.end()
})
app.post('/redirect-post', (req, res) => {
const code = Number(req.query.code)
if (!code) {
return res.end('no code supplied')
}
// 307 keeps the same HTTP method
const url = code === 307 ? '/post-only' : '/timeout'
res.redirect(code, url)
})
app.post('/post-only', (req, res) => {
res.end('<html>it posted</html>')
})
}
describe('e2e visit', () => {
context('low response timeout', () => {
systemTests.setup({
settings: {
responseTimeout: 500,
pageLoadTimeout: 1000,
e2e: {},
},
servers: {
port: 3434,
static: true,
onServer,
},
})
systemTests.it('passes', {
browser: '!webkit', // TODO(webkit): fix+unskip
spec: 'visit.cy.js',
snapshot: true,
onRun (exec) {
return startTlsV1Server(6776)
.then((serv) => {
return exec()
.then(() => {
return serv.destroy()
})
})
},
})
systemTests.it('passes with experimentalSourceRewriting', {
browser: '!webkit', // TODO(webkit): fix+unskip
spec: 'source_rewriting.cy.js',
config: {
experimentalSourceRewriting: true,
},
snapshot: true,
onRun (exec) {
return startTlsV1Server(6776)
.then((serv) => {
return exec()
.then(() => {
return serv.destroy()
})
})
},
})
// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23252
systemTests.it.skip('fails when network connection immediately fails', {
spec: 'visit_http_network_error_failing.cy.js',
snapshot: true,
expectedExitCode: 1,
})
systemTests.it('fails when server responds with 500', {
spec: 'visit_http_500_response_failing.cy.js',
snapshot: true,
expectedExitCode: 1,
})
// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23162
systemTests.it.skip('fails when file server responds with 404', {
spec: 'visit_file_404_response_failing.cy.js',
snapshot: true,
expectedExitCode: 1,
})
systemTests.it('fails when content type isnt html', {
spec: 'visit_non_html_content_type_failing.cy.js',
snapshot: true,
expectedExitCode: 1,
})
systemTests.it('calls onBeforeLoad when overwriting cy.visit', {
snapshot: true,
spec: 'issue_2196.cy.js',
})
})
context('low responseTimeout, normal pageLoadTimeout', () => {
systemTests.setup({
settings: {
responseTimeout: 2000,
e2e: {},
},
servers: {
port: 3434,
static: true,
onServer,
},
})
systemTests.it('fails when response never ends', {
spec: 'visit_response_never_ends_failing.cy.js',
snapshot: true,
expectedExitCode: 3,
})
})
context('normal response timeouts', () => {
systemTests.setup({
settings: {
pageLoadTimeout: 1000,
e2e: {},
},
servers: {
port: 3434,
static: true,
onServer,
},
})
systemTests.it('fails when visit times out', {
spec: 'visit_http_timeout_failing.cy.js',
snapshot: true,
expectedExitCode: 2,
})
})
})