@@ -85,6 +85,60 @@ describe('WebsocketServer', () => {
85
85
done ( ) ;
86
86
} , 3000 ) ;
87
87
} ) ;
88
+
89
+ it ( 'should match sockPath' , ( done ) => {
90
+ let receivedConnection = false ;
91
+ socketServer . onConnection ( ( connection ) => {
92
+ receivedConnection = true ;
93
+ connection . close ( 4000 ) ;
94
+ } ) ;
95
+
96
+ // eslint-disable-next-line new-cap
97
+ const client = new ws ( `http://localhost:${ port } /ws-server?YEP` ) ;
98
+
99
+ let receivedError = false ;
100
+ client . onerror = ( e ) => {
101
+ receivedError = e . error ;
102
+ } ;
103
+
104
+ client . onclose = ( e ) => {
105
+ expect ( e . code ) . toEqual ( 4000 ) ;
106
+ } ;
107
+
108
+ setTimeout ( ( ) => {
109
+ expect ( receivedConnection ) . toBeTruthy ( ) ;
110
+ expect ( receivedError ) . toBeFalsy ( ) ;
111
+ done ( ) ;
112
+ } , 3000 ) ;
113
+ } ) ;
114
+
115
+ it ( 'should ignore other paths' , ( done ) => {
116
+ let receivedConnection = false ;
117
+ socketServer . onConnection ( ( connection ) => {
118
+ receivedConnection = true ;
119
+ connection . close ( 4000 ) ;
120
+ } ) ;
121
+
122
+ // eslint-disable-next-line new-cap
123
+ const client = new ws ( `http://localhost:${ port } /ws-server-NOT` , {
124
+ handshakeTimeout : 1000 ,
125
+ } ) ;
126
+
127
+ let receivedError = false ;
128
+ client . onerror = ( e ) => {
129
+ receivedError = e . error ;
130
+ } ;
131
+
132
+ client . onclose = ( e ) => {
133
+ expect ( e . code ) . not . toEqual ( 4000 ) ;
134
+ } ;
135
+
136
+ setTimeout ( ( ) => {
137
+ expect ( receivedConnection ) . toBeFalsy ( ) ;
138
+ expect ( receivedError ) . toBeTruthy ( ) ;
139
+ done ( ) ;
140
+ } , 3000 ) ;
141
+ } ) ;
88
142
} ) ;
89
143
90
144
afterAll ( ( done ) => {
0 commit comments