1
- /*globals describe, before, it*/
1
+ /*globals describe, before, it, after */
2
2
'use strict'
3
3
4
4
require ( 'should' )
@@ -17,6 +17,11 @@ describe('text frames', function () {
17
17
} )
18
18
} )
19
19
20
+ after ( function ( done ) {
21
+ testClient . close ( )
22
+ testServer . socket . close ( done )
23
+ } )
24
+
20
25
it ( 'should connect to a websocket server' , function ( done ) {
21
26
var client = getClient ( )
22
27
@@ -115,6 +120,31 @@ describe('text frames', function () {
115
120
} )
116
121
} )
117
122
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
+
118
148
function getClient ( ) {
119
149
testClient . removeAllListeners ( )
120
150
return testClient
0 commit comments