1
- var caronte = require ( '../lib/caronte' ) ,
2
- expect = require ( 'expect.js' ) ,
3
- http = require ( 'http' ) ,
4
- ws = require ( 'ws' ) ;
1
+ var caronte = require ( '../lib/caronte' ) ,
2
+ expect = require ( 'expect.js' ) ,
3
+ http = require ( 'http' ) ,
4
+ ws = require ( 'ws' )
5
+ io = require ( 'socket.io' ) ,
6
+ ioClient = require ( 'socket.io-client' ) ;
7
+
5
8
6
9
describe ( 'lib/caronte.js' , function ( ) {
7
10
describe ( '#createProxyServer' , function ( ) {
@@ -194,6 +197,7 @@ describe('lib/caronte.js', function() {
194
197
195
198
client . on ( 'message' , function ( msg ) {
196
199
expect ( msg ) . to . be ( 'Hello over websockets' ) ;
200
+ client . close ( ) ;
197
201
proxyServer . close ( ) ;
198
202
destiny . close ( ) ;
199
203
done ( ) ;
@@ -208,4 +212,35 @@ describe('lib/caronte.js', function() {
208
212
} ) ;
209
213
} ) ;
210
214
} ) ;
215
+
216
+ describe ( '#createProxyServer using the ws-incoming passes' , function ( ) {
217
+ it ( 'should proxy a socket.io stream' , function ( done ) {
218
+ var proxy = caronte . createProxyServer ( {
219
+ target : 'ws://127.0.0.1:8080' ,
220
+ ws : true
221
+ } ) ,
222
+ proxyServer = proxy . listen ( '8081' ) ,
223
+ destiny = io . listen ( 8080 , function ( ) {
224
+ var client = ioClient . connect ( 'ws://127.0.0.1:8081' ) ;
225
+
226
+ client . on ( 'connect' , function ( ) {
227
+ client . emit ( 'incoming' , 'hello there' ) ;
228
+ } ) ;
229
+
230
+ client . on ( 'outgoing' , function ( data ) {
231
+ expect ( data ) . to . be ( 'Hello over websockets' ) ;
232
+ proxyServer . close ( ) ;
233
+ destiny . server . close ( ) ;
234
+ done ( ) ;
235
+ } ) ;
236
+ } ) ;
237
+
238
+ destiny . sockets . on ( 'connection' , function ( socket ) {
239
+ socket . on ( 'incoming' , function ( msg ) {
240
+ expect ( msg ) . to . be ( 'hello there' ) ;
241
+ socket . emit ( 'outgoing' , 'Hello over websockets' ) ;
242
+ } ) ;
243
+ } )
244
+ } ) ;
245
+ } )
211
246
} ) ;
0 commit comments