1- /*globals describe, before, it*/
1+ /*globals describe, before, it, after */
22'use strict'
33
44require ( 'should' )
@@ -17,6 +17,11 @@ describe('text frames', function () {
1717 } )
1818 } )
1919
20+ after ( function ( done ) {
21+ testClient . close ( )
22+ testServer . socket . close ( done )
23+ } )
24+
2025 it ( 'should connect to a websocket server' , function ( done ) {
2126 var client = getClient ( )
2227
@@ -115,6 +120,31 @@ describe('text frames', function () {
115120 } )
116121} )
117122
123+ describe ( 'handshake' , function ( ) {
124+ before ( function ( done ) {
125+ testServer = ws . createServer ( function ( conn ) {
126+ testConn = conn
127+ // Send frame right after handshake answer
128+ conn . sendText ( 'hello' )
129+ } ) . listen ( TEST_PORT , done )
130+ } )
131+
132+ after ( function ( done ) {
133+ testServer . socket . close ( done )
134+ } )
135+
136+ it ( 'should work when the handshake response is followed by a WS frame' , function ( done ) {
137+ // Server ready, make the first connection
138+ ws . connect ( 'ws://127.0.0.1:' + TEST_PORT , function ( ) {
139+ this . on ( 'text' , function ( str ) {
140+ str . should . be . equal ( 'hello' )
141+ this . close ( )
142+ done ( )
143+ } )
144+ } )
145+ } )
146+ } )
147+
118148function getClient ( ) {
119149 testClient . removeAllListeners ( )
120150 return testClient
0 commit comments