-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
test.js
40 lines (33 loc) · 955 Bytes
/
test.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
'use strict'
const {createServer: createHttpServer, get: httpGet} = require('http')
const {strictEqual} = require('assert')
const startServer = require('./server')
const startClient = require('./client')
const showError = (err) => {
if (!err) return;
console.error(err)
process.exit(1)
}
const httpServer = createHttpServer((_, res) => res.end('yay!'))
httpServer.listen(5000, (err) => {
if (err) return showError(err)
const server = startServer(8080, (err) => {
if (err) return showError(err)
const headers = {
foo: 'BaR',
hello: 'world',
}
const client = startClient('ws://localhost:8080', 'localhost:5000', 5001, {headers}, (err) => {
if (err) return showError(err)
httpGet('http://localhost:5001', (res) => {
res.once('data', (data) => {
strictEqual(data.toString('utf-8'), 'yay!')
console.info('works!')
client.close()
server.httpServer.close()
httpServer.close()
})
})
})
})
})