-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.js
46 lines (38 loc) · 1019 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
41
42
43
44
45
46
var net = require('net');
var test = require('tape');
var tcpSpy = require('./');
var tests = function() {
test('basic test', function(t) {
t.plan(2);
var spy = tcpSpy({port: 4501, forwardPort: 4500}, function() {
var c = net.connect({port: 4501}, function() {
c.write('a');
});
});
spy.on('connection', function(client, server) {
client.on('data', function(data) {
t.equal(data.toString(), 'a', 'client');
});
server.on('data', function(data) {
t.equal(data.toString(), 'b', 'server');
});
});
});
test('same ports', function(t) {
t.plan(1);
var spy = tcpSpy({port: 4500, forwardPort: 4500}, function() {
var c = net.connect({port: 4501}, function() {
c.write('a');
});
});
spy.on('error', t.ok.bind(null, true));
});
test('end', function(t) {
t.end();
process.exit();
});
};
var server = net.createServer(function(conn) {
conn.write('b');
});
server.listen(4500, tests);