Skip to content

Commit 02007ed

Browse files
committed
[tests] added tests for websockets
1 parent 4090250 commit 02007ed

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test/lib-caronte-test.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var caronte = require('../lib/caronte'),
22
expect = require('expect.js'),
3-
http = require('http');
3+
http = require('http'),
4+
ws = require('ws');
45

56
describe('lib/caronte.js', function() {
67
describe('#createProxyServer', function() {
@@ -176,4 +177,35 @@ describe('lib/caronte.js', function() {
176177
}).end();
177178
});
178179
});
180+
181+
describe('#createProxyServer using the ws-incoming passes', function () {
182+
it('should proxy the websockets stream', function (done) {
183+
var proxy = caronte.createProxyServer({
184+
target: 'ws://127.0.0.1:8080',
185+
ws: true
186+
}),
187+
proxyServer = proxy.listen('8081'),
188+
destiny = new ws.Server({ port: 8080 }, function () {
189+
var client = new ws('ws://127.0.0.1:8081');
190+
191+
client.on('open', function () {
192+
client.send('hello there');
193+
});
194+
195+
client.on('message', function (msg) {
196+
expect(msg).to.be('Hello over websockets');
197+
proxyServer.close();
198+
destiny.close();
199+
done();
200+
});
201+
});
202+
203+
destiny.on('connection', function (socket) {
204+
socket.on('message', function (msg) {
205+
expect(msg).to.be('hello there');
206+
socket.send('Hello over websockets');
207+
});
208+
});
209+
});
210+
});
179211
});

0 commit comments

Comments
 (0)