@@ -265,4 +265,86 @@ describe('DevServerPlugin util', () => {
265
265
266
266
expect ( typeof entries === 'function' ) . toBe ( true ) ;
267
267
} ) ;
268
+
269
+ // 'npm run prepare' must be done for this test to pass
270
+ const sockjsClientPath = require . resolve (
271
+ '../../../client/clients/SockJSClient'
272
+ ) ;
273
+
274
+ describe ( 'getWebsocketTransport' , ( ) => {
275
+ it ( "should work with client.transport: 'sockjs'" , ( ) => {
276
+ let result ;
277
+
278
+ expect ( ( ) => {
279
+ const devServerPlugin = new DevServerPlugin ( {
280
+ client : {
281
+ transport : 'sockjs' ,
282
+ } ,
283
+ webSocketServer : 'sockjs' ,
284
+ } ) ;
285
+
286
+ result = devServerPlugin . getWebsocketTransport ( ) ;
287
+ } ) . not . toThrow ( ) ;
288
+
289
+ expect ( result ) . toEqual ( sockjsClientPath ) ;
290
+ } ) ;
291
+
292
+ it ( 'should work with client.transport: SockJSClient full path' , ( ) => {
293
+ let result ;
294
+
295
+ expect ( ( ) => {
296
+ const devServerPlugin = new DevServerPlugin ( {
297
+ client : {
298
+ transport : sockjsClientPath ,
299
+ } ,
300
+ webSocketServer : 'sockjs' ,
301
+ } ) ;
302
+
303
+ result = devServerPlugin . getWebsocketTransport ( ) ;
304
+ } ) . not . toThrow ( ) ;
305
+
306
+ expect ( result ) . toEqual ( sockjsClientPath ) ;
307
+ } ) ;
308
+
309
+ it ( 'should throw with client.transport: bad path' , ( ) => {
310
+ expect ( ( ) => {
311
+ const devServerPlugin = new DevServerPlugin ( {
312
+ client : {
313
+ transport : '/bad/path/to/implementation' ,
314
+ } ,
315
+ webSocketServer : 'sockjs' ,
316
+ } ) ;
317
+
318
+ devServerPlugin . getWebsocketTransport ( ) ;
319
+ } ) . toThrow ( / c l i e n t .t r a n s p o r t m u s t b e a s t r i n g / ) ;
320
+ } ) ;
321
+
322
+ it ( 'should throw with transportMode.client: bad type' , ( ) => {
323
+ expect ( ( ) => {
324
+ const devServerPlugin = new DevServerPlugin ( {
325
+ client : {
326
+ transport : 1 ,
327
+ } ,
328
+ webSocketServer : 'sockjs' ,
329
+ } ) ;
330
+
331
+ devServerPlugin . getWebsocketTransport ( ) ;
332
+ } ) . toThrow ( / c l i e n t .t r a n s p o r t m u s t b e a s t r i n g / ) ;
333
+ } ) ;
334
+
335
+ it ( 'should throw with client.transport: unimplemented client' , ( ) => {
336
+ expect ( ( ) => {
337
+ const devServerPlugin = new DevServerPlugin ( {
338
+ client : {
339
+ transport : 'foo' ,
340
+ } ,
341
+ webSocketServer : 'sockjs' ,
342
+ } ) ;
343
+
344
+ devServerPlugin . getWebsocketTransport ( ) ;
345
+ } ) . toThrow (
346
+ 'When you use custom web socket implementation you must explicitly specify client.transport'
347
+ ) ;
348
+ } ) ;
349
+ } ) ;
268
350
} ) ;
0 commit comments