forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_error_handling_spec.js
62 lines (55 loc) · 1.49 KB
/
js_error_handling_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
const fs = require('fs')
const Fixtures = require('../lib/fixtures')
const systemTests = require('../lib/system-tests').default
const onServer = function (app) {
app.get('/index.html', (req, res) => {
return res.send(`\
<html>
<body>
some bad js a comin'
</body>
</html>\
`)
})
app.get('/gzip-bad.html', (req, res) => {
const buf = fs.readFileSync(Fixtures.path('server/gzip-bad.html.gz'))
return res.set({
'content-type': 'text/html',
'content-encoding': 'gzip',
})
.send(buf)
})
return app.get('/gzip-bad.js', (req, res) => {
const buf = fs.readFileSync(Fixtures.path('server/gzip-bad.html.gz'))
return res.set({
'content-type': 'application/javascript',
'content-encoding': 'gzip',
})
.send(buf)
})
}
describe('e2e js error handling', () => {
systemTests.setup({
servers: [{
port: 1122,
static: true,
}, {
port: 1123,
onServer,
}],
})
systemTests.it('fails', {
spec: 'js_error_handling_failing.cy.js',
snapshot: true,
expectedExitCode: 5,
config: {
video: false,
},
onStdout (stdout) {
// firefox has a stack line for the cross-origin error that other browsers don't
return stdout
.replace(/cross-origin-script-error\s+?\(Results/, 'cross-origin-script-error\n\n (Results')
.replace(/cross-origin-script-error\s+at <unknown> \(http:\/\/localhost:1122\/static\/fail\.js:0:0\)\s+?\(Results/, 'cross-origin-script-error\n\n (Results')
},
})
})