-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
79 lines (67 loc) · 1.88 KB
/
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
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
/* global Bare */
const test = require('brittle')
const net = require('.')
const isWindows = Bare.platform === 'win32'
test('tcp', (t) => {
t.plan(8)
const server = net.createServer((socket) => {
t.ok(socket instanceof net.Socket)
socket
.on('data', (data) =>
t.alike(data, Buffer.from('hello client'), 'server received data')
)
.on('close', () => {
t.pass('server socket closed')
server.close(() => t.pass('server closed'))
})
.end('hello server')
})
server.listen(0, () => {
t.pass('listening')
const socket = new net.Socket()
socket
.on('data', (data) =>
t.alike(data, Buffer.from('hello server'), 'client received data')
)
.on('close', () => t.pass('client socket closed'))
.connect(server.address().port, () => {
t.pass('connected')
socket.end('hello client')
})
})
})
test('ipc', (t) => {
t.plan(8)
const server = net.createServer((socket) => {
t.ok(socket instanceof net.Socket)
socket
.on('data', (data) =>
t.alike(data, Buffer.from('hello client'), 'server received data')
)
.on('close', () => {
t.pass('server socket closed')
server.close(() => t.pass('server closed'))
})
.end('hello server')
})
server.listen(name(), () => {
t.pass('listening')
const socket = new net.Socket()
socket
.on('data', (data) =>
t.alike(data, Buffer.from('hello server'), 'client received data')
)
.on('close', () => t.pass('client socket closed'))
.connect(server.address(), () => {
t.pass('connected')
socket.end('hello client')
})
})
})
function name() {
const name =
'bare-pipe-' +
Math.random().toString(16).slice(2) +
Math.random().toString(16).slice(2)
return isWindows ? '\\\\.\\pipe\\' + name : '/tmp/' + name + '.sock'
}