forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage_loading_spec.js
85 lines (72 loc) · 1.99 KB
/
page_loading_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
const bodyParser = require('body-parser')
const systemTests = require('../lib/system-tests').default
let count = 0
const onServer = function (app) {
app.use(bodyParser.json())
app.get('/first', (req, res) => {
// reset the count anytime we visit first again
count = 0
return res.send('<html><h1>first</h1><a href=\'/second\'>second</a></html>')
})
app.get('/second', (req, res) => {
count += 1
return res.send(`<html><h1>second</h1><a href='/slow'>slow</a><span id='count'>${count}</span></html>`)
})
app.get('/slow', (req, res) => {
return setTimeout(() => {
return res.send('<html><h1>slow</h1></html>')
}
, 2000)
})
app.get('/form', (req, res) => {
return res.send(`\
<html>
<iframe src="http://localhost:17170/index.html"></iframe>
<form action="/redirected-to"></form>
</html>\
`)
})
app.get('/redirected-to', (req, res) => {
return res.send(`\
<html>
<h1>I AM THE NEW PAGE</h1>
<script src="http://localhost:17170/static/jquery.js"></script>
<script>
$.get('/cypress.json')
$.get('/cypress.json')
$.get('/cypress.json')
$.get('/cypress.json')
</script>
</html>\
`)
})
app.post('/json', (req, res) => {
return res.json({
body: req.body,
})
})
return app.get('/html', (req, res) => {
return res.send('<html>content</html>')
})
}
describe('e2e page_loading', () => {
systemTests.setup({
servers: [{
port: 1717,
onServer,
}, {
port: 17170,
static: true,
}],
})
// this tests that __cypress.initial is set correctly whilst navigating
// between pages, or during cy.reload
// additionally this creates an edge case where after __cypress.initial is
// set we send an XHR which should not inject because its requested for JSON
// but that another XHR which is requested for html should inject
systemTests.it('passes', {
browser: '!webkit', // TODO(webkit): fix+unskip (related to document.cookie issue?)
spec: 'page_loading.cy.js',
snapshot: true,
})
})