@@ -1224,6 +1224,34 @@ describe('WebSocket', () => {
12241224 } ) ;
12251225 } ) ;
12261226
1227+ it ( 'honors the `createConnection` option' , ( done ) => {
1228+ const wss = new WebSocket . Server ( { noServer : true , path : '/foo' } ) ;
1229+
1230+ server . once ( 'upgrade' , ( req , socket , head ) => {
1231+ assert . strictEqual ( req . headers . host , 'google.com:22' ) ;
1232+ wss . handleUpgrade ( req , socket , head , NOOP ) ;
1233+ } ) ;
1234+
1235+ const ws = new WebSocket ( 'ws://google.com:22/foo' , {
1236+ createConnection : ( options ) => {
1237+ assert . strictEqual ( options . host , 'google.com' ) ;
1238+ assert . strictEqual ( options . port , '22' ) ;
1239+
1240+ // Ignore the invalid host address, and connect to the server manually:
1241+ return net . createConnection ( {
1242+ host : 'localhost' ,
1243+ port : server . address ( ) . port
1244+ } ) ;
1245+ }
1246+ } ) ;
1247+
1248+ ws . on ( 'open' , ( ) => {
1249+ assert . strictEqual ( ws . url , 'ws://google.com:22/foo' ) ;
1250+ ws . on ( 'close' , ( ) => done ( ) ) ;
1251+ ws . close ( ) ;
1252+ } ) ;
1253+ } ) ;
1254+
12271255 it ( 'emits an error if the redirect URL is invalid (1/2)' , ( done ) => {
12281256 server . once ( 'upgrade' , ( req , socket ) => {
12291257 socket . end ( 'HTTP/1.1 302 Found\r\nLocation: ws://\r\n\r\n' ) ;
0 commit comments