forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_sent_events_spec.js
74 lines (59 loc) · 1.34 KB
/
server_sent_events_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
const SseStream = require('ssestream')
const systemTests = require('../lib/system-tests').default
let clients = 0
const onServer = function (app, srv) {
app.get('/clients', (req, res) => {
return res.json({ clients })
})
app.get('/foo', (req, res) => {
return res.send('<html>foo></html>')
})
return app.get('/sse', (req, res) => {
return req.socket.destroy()
})
}
const onSSEServer = (app) => {
return app.get('/sse', function (req, res) {
let int
clients += 1
res.on('close', () => {
clearInterval(int)
clients -= 1
})
res.set({
'Access-Control-Allow-Origin': '*',
})
this.sseStream = new SseStream(req)
this.sseStream.pipe(res)
let i = 0
int = setInterval(() => {
i += 1
return this.sseStream.write({
data: `${i}`,
})
}
, 100)
})
}
const onSSEsServer = function (app) {}
describe('e2e server sent events', () => {
systemTests.setup({
servers: [{
port: 3038,
static: true,
onServer,
}, {
port: 3039,
onServer: onSSEServer,
}, {
port: 3040,
onServer: onSSEsServer,
}],
})
// https://github.com/cypress-io/cypress/issues/1440
systemTests.it('passes', {
browser: '!webkit', // TODO(webkit): fix+unskip
spec: 'server_sent_events.cy.js',
snapshot: true,
})
})