@@ -223,4 +223,95 @@ describe('serverMode option', () => {
223
223
} , 5000 ) ;
224
224
} ) ;
225
225
} ) ;
226
+
227
+ describe ( 'without a header' , ( ) => {
228
+ let mockWarn ;
229
+ beforeAll ( ( done ) => {
230
+ server = testServer . start (
231
+ config ,
232
+ {
233
+ port,
234
+ serverMode : class MySockJSServer extends BaseServer {
235
+ constructor ( serv ) {
236
+ super ( serv ) ;
237
+ this . socket = sockjs . createServer ( {
238
+ // Use provided up-to-date sockjs-client
239
+ sockjs_url : '/__webpack_dev_server__/sockjs.bundle.js' ,
240
+ // Limit useless logs
241
+ log : ( severity , line ) => {
242
+ if ( severity === 'error' ) {
243
+ this . server . log . error ( line ) ;
244
+ } else {
245
+ this . server . log . debug ( line ) ;
246
+ }
247
+ } ,
248
+ } ) ;
249
+
250
+ this . socket . installHandlers ( this . server . listeningApp , {
251
+ prefix : this . server . sockPath ,
252
+ } ) ;
253
+ }
254
+
255
+ send ( connection , message ) {
256
+ connection . write ( message ) ;
257
+ }
258
+
259
+ close ( connection ) {
260
+ connection . close ( ) ;
261
+ }
262
+
263
+ onConnection ( f ) {
264
+ this . socket . on ( 'connection' , ( connection ) => {
265
+ f ( connection ) ;
266
+ } ) ;
267
+ }
268
+
269
+ onConnectionClose ( connection , f ) {
270
+ connection . on ( 'close' , f ) ;
271
+ }
272
+ } ,
273
+ } ,
274
+ done
275
+ ) ;
276
+
277
+ mockWarn = jest . spyOn ( server . log , 'warn' ) . mockImplementation ( ( ) => { } ) ;
278
+ } ) ;
279
+
280
+ it ( 'results in an error' , ( done ) => {
281
+ const data = [ ] ;
282
+ const client = new SockJS ( `http://localhost:${ port } /sockjs-node` ) ;
283
+
284
+ client . onopen = ( ) => {
285
+ data . push ( 'open' ) ;
286
+ } ;
287
+
288
+ client . onmessage = ( e ) => {
289
+ data . push ( e . data ) ;
290
+ } ;
291
+
292
+ client . onclose = ( ) => {
293
+ data . push ( 'close' ) ;
294
+ } ;
295
+
296
+ setTimeout ( ( ) => {
297
+ expect ( data ) . toMatchSnapshot ( ) ;
298
+ const calls = mockWarn . mock . calls ;
299
+ mockWarn . mockRestore ( ) ;
300
+
301
+ let foundWarning = false ;
302
+ const regExp = / s e r v e r M o d e i m p l e m e n t a t i o n m u s t p a s s h e a d e r s t o t h e c a l l b a c k o f o n C o n n e c t i o n \( f \) / ;
303
+ calls . every ( ( call ) => {
304
+ if ( regExp . test ( call ) ) {
305
+ foundWarning = true ;
306
+ return false ;
307
+ }
308
+ return true ;
309
+ } ) ;
310
+
311
+ expect ( foundWarning ) . toBeTruthy ( ) ;
312
+
313
+ done ( ) ;
314
+ } , 5000 ) ;
315
+ } ) ;
316
+ } ) ;
226
317
} ) ;
0 commit comments