mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[tests] added tests for websockets
This commit is contained in:
parent
40902506af
commit
02007ed0fb
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user