-
-
Notifications
You must be signed in to change notification settings - Fork 760
Expand file tree
/
Copy patheventsource-constructor-stringify.js
More file actions
30 lines (25 loc) · 1001 Bytes
/
eventsource-constructor-stringify.js
File metadata and controls
30 lines (25 loc) · 1001 Bytes
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
'use strict'
const assert = require('node:assert')
const { once } = require('node:events')
const http = require('node:http')
const { test, describe } = require('node:test')
const { EventSource } = require('../../lib/web/eventsource/eventsource')
describe('EventSource - constructor stringify', () => {
test('should stringify argument', async () => {
const server = http.createServer({ joinDuplicateHeaders: true }, (req, res) => {
assert.strictEqual(req.headers.connection, 'keep-alive')
res.writeHead(200, 'OK', { 'Content-Type': 'text/event-stream' })
res.end()
})
await once(server.listen(0), 'listening')
const port = server.address().port
const eventSourceInstance = new EventSource({ toString: function () { return `http://localhost:${port}` } })
eventSourceInstance.onopen = () => {
eventSourceInstance.close()
server.close()
}
eventSourceInstance.onerror = () => {
assert.fail('Should not have errored')
}
})
})