Skip to content

Commit

Permalink
[tests] added tests for websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
cronopio committed Sep 17, 2013
1 parent 4090250 commit 02007ed
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion 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() {
Expand Down Expand Up @@ -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');
});
});
});
});
});

0 comments on commit 02007ed

Please sign in to comment.