|
1 | 1 | var caronte = require('../lib/caronte'),
|
2 | 2 | expect = require('expect.js'),
|
3 |
| - http = require('http'); |
| 3 | + http = require('http'), |
| 4 | + ws = require('ws'); |
4 | 5 |
|
5 | 6 | describe('lib/caronte.js', function() {
|
6 | 7 | describe('#createProxyServer', function() {
|
@@ -176,4 +177,35 @@ describe('lib/caronte.js', function() {
|
176 | 177 | }).end();
|
177 | 178 | });
|
178 | 179 | });
|
| 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 | + }); |
179 | 211 | });
|
0 commit comments