Skip to content

Commit 10a0db4

Browse files
committed
[tests] added test for socket.io proxying
1 parent 0602500 commit 10a0db4

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"coveralls" : "*",
1717
"mocha-lcov-reporter": "*",
1818
"blanket" : "*",
19-
"ws" : "*"
19+
"ws" : "*",
20+
"socket.io" : "*",
21+
"socket.io-client" : "*"
2022
},
2123
"scripts" : {
2224
"blanket" : { "pattern": "lib/caronte" },

test/lib-caronte-test.js

+39-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
var caronte = require('../lib/caronte'),
2-
expect = require('expect.js'),
3-
http = require('http'),
4-
ws = require('ws');
1+
var caronte = require('../lib/caronte'),
2+
expect = require('expect.js'),
3+
http = require('http'),
4+
ws = require('ws')
5+
io = require('socket.io'),
6+
ioClient = require('socket.io-client');
7+
58

69
describe('lib/caronte.js', function() {
710
describe('#createProxyServer', function() {
@@ -194,6 +197,7 @@ describe('lib/caronte.js', function() {
194197

195198
client.on('message', function (msg) {
196199
expect(msg).to.be('Hello over websockets');
200+
client.close();
197201
proxyServer.close();
198202
destiny.close();
199203
done();
@@ -208,4 +212,35 @@ describe('lib/caronte.js', function() {
208212
});
209213
});
210214
});
215+
216+
describe('#createProxyServer using the ws-incoming passes', function () {
217+
it('should proxy a socket.io stream', function (done) {
218+
var proxy = caronte.createProxyServer({
219+
target: 'ws://127.0.0.1:8080',
220+
ws: true
221+
}),
222+
proxyServer = proxy.listen('8081'),
223+
destiny = io.listen(8080, function () {
224+
var client = ioClient.connect('ws://127.0.0.1:8081');
225+
226+
client.on('connect', function () {
227+
client.emit('incoming', 'hello there');
228+
});
229+
230+
client.on('outgoing', function (data) {
231+
expect(data).to.be('Hello over websockets');
232+
proxyServer.close();
233+
destiny.server.close();
234+
done();
235+
});
236+
});
237+
238+
destiny.sockets.on('connection', function (socket) {
239+
socket.on('incoming', function (msg) {
240+
expect(msg).to.be('hello there');
241+
socket.emit('outgoing', 'Hello over websockets');
242+
});
243+
})
244+
});
245+
})
211246
});

0 commit comments

Comments
 (0)