From 02007ed0fb38f798436ae5669bb18d4f27496667 Mon Sep 17 00:00:00 2001 From: cronopio Date: Mon, 16 Sep 2013 20:59:10 -0500 Subject: [PATCH] [tests] added tests for websockets --- test/lib-caronte-test.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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'); + }); + }); + }); + }); });