diff --git a/test/lib-caronte-test.js b/test/lib-caronte-test.js index dbb278f..06ab11e 100644 --- a/test/lib-caronte-test.js +++ b/test/lib-caronte-test.js @@ -1,6 +1,7 @@ var caronte = require('../lib/caronte'), expect = require('expect.js'), - http = require('http'); + http = require('http'), + ws = require('ws'); describe('lib/caronte.js', function() { describe('#createProxyServer', function() { @@ -176,4 +177,35 @@ describe('lib/caronte.js', function() { }).end(); }); }); + + describe('#createProxyServer using the ws-incoming passes', function () { + it('should proxy the websockets stream', function (done) { + var proxy = caronte.createProxyServer({ + target: 'ws://127.0.0.1:8080', + ws: true + }), + proxyServer = proxy.listen('8081'), + destiny = new ws.Server({ port: 8080 }, function () { + var client = new ws('ws://127.0.0.1:8081'); + + client.on('open', function () { + client.send('hello there'); + }); + + client.on('message', function (msg) { + expect(msg).to.be('Hello over websockets'); + proxyServer.close(); + destiny.close(); + done(); + }); + }); + + destiny.on('connection', function (socket) { + socket.on('message', function (msg) { + expect(msg).to.be('hello there'); + socket.send('Hello over websockets'); + }); + }); + }); + }); });