1- import type { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'
21import { WebSocketHandler } from './WebSocketHandler'
32
43describe ( 'parse' , ( ) => {
54 it ( 'matches an exact url' , ( ) => {
65 expect (
76 new WebSocketHandler ( 'ws://localhost:3000' ) . parse ( {
8- event : new MessageEvent ( 'connection' , {
9- data : {
10- client : {
11- url : new URL ( 'ws://localhost:3000' ) ,
12- } ,
13- } as WebSocketConnectionData ,
14- } ) ,
7+ url : new URL ( 'ws://localhost:3000' ) ,
158 } ) ,
169 ) . toEqual ( {
1710 match : {
@@ -24,13 +17,7 @@ describe('parse', () => {
2417 it ( 'ignores trailing slash' , ( ) => {
2518 expect (
2619 new WebSocketHandler ( 'ws://localhost:3000' ) . parse ( {
27- event : new MessageEvent ( 'connection' , {
28- data : {
29- client : {
30- url : new URL ( 'ws://localhost:3000/' ) ,
31- } ,
32- } as WebSocketConnectionData ,
33- } ) ,
20+ url : new URL ( 'ws://localhost:3000/' ) ,
3421 } ) ,
3522 ) . toEqual ( {
3623 match : {
@@ -41,13 +28,7 @@ describe('parse', () => {
4128
4229 expect (
4330 new WebSocketHandler ( 'ws://localhost:3000/' ) . parse ( {
44- event : new MessageEvent ( 'connection' , {
45- data : {
46- client : {
47- url : new URL ( 'ws://localhost:3000' ) ,
48- } ,
49- } as WebSocketConnectionData ,
50- } ) ,
31+ url : new URL ( 'ws://localhost:3000/' ) ,
5132 } ) ,
5233 ) . toEqual ( {
5334 match : {
@@ -60,13 +41,7 @@ describe('parse', () => {
6041 it ( 'supports path parameters' , ( ) => {
6142 expect (
6243 new WebSocketHandler ( 'ws://localhost:3000/:serviceName' ) . parse ( {
63- event : new MessageEvent ( 'connection' , {
64- data : {
65- client : {
66- url : new URL ( 'ws://localhost:3000/auth' ) ,
67- } ,
68- } as WebSocketConnectionData ,
69- } ) ,
44+ url : new URL ( 'ws://localhost:3000/auth' ) ,
7045 } ) ,
7146 ) . toEqual ( {
7247 match : {
@@ -81,15 +56,9 @@ describe('parse', () => {
8156 it ( 'ignores "/socket.io/" prefix in the client url' , ( ) => {
8257 expect (
8358 new WebSocketHandler ( 'ws://localhost:3000' ) . parse ( {
84- event : new MessageEvent ( 'connection' , {
85- data : {
86- client : {
87- url : new URL (
88- 'ws://localhost:3000/socket.io/?EIO=4&transport=websocket' ,
89- ) ,
90- } ,
91- } as WebSocketConnectionData ,
92- } ) ,
59+ url : new URL (
60+ 'ws://localhost:3000/socket.io/?EIO=4&transport=websocket' ,
61+ ) ,
9362 } ) ,
9463 ) . toEqual ( {
9564 match : {
@@ -100,15 +69,9 @@ describe('parse', () => {
10069
10170 expect (
10271 new WebSocketHandler ( 'ws://localhost:3000/non-matching' ) . parse ( {
103- event : new MessageEvent ( 'connection' , {
104- data : {
105- client : {
106- url : new URL (
107- 'ws://localhost:3000/socket.io/?EIO=4&transport=websocket' ,
108- ) ,
109- } ,
110- } as WebSocketConnectionData ,
111- } ) ,
72+ url : new URL (
73+ 'ws://localhost:3000/socket.io/?EIO=4&transport=websocket' ,
74+ ) ,
11275 } ) ,
11376 ) . toEqual ( {
11477 match : {
@@ -125,13 +88,7 @@ describe('parse', () => {
12588 */
12689 expect (
12790 new WebSocketHandler ( 'ws://localhost:3000/clients/socket.io/123' ) . parse ( {
128- event : new MessageEvent ( 'connection' , {
129- data : {
130- client : {
131- url : new URL ( 'ws://localhost:3000/clients/socket.io/123' ) ,
132- } ,
133- } as WebSocketConnectionData ,
134- } ) ,
91+ url : new URL ( 'ws://localhost:3000/clients/socket.io/123' ) ,
13592 } ) ,
13693 ) . toEqual ( {
13794 match : {
@@ -142,13 +99,7 @@ describe('parse', () => {
14299
143100 expect (
144101 new WebSocketHandler ( 'ws://localhost:3000' ) . parse ( {
145- event : new MessageEvent ( 'connection' , {
146- data : {
147- client : {
148- url : new URL ( 'ws://localhost:3000/clients/socket.io/123' ) ,
149- } ,
150- } as WebSocketConnectionData ,
151- } ) ,
102+ url : new URL ( 'ws://localhost:3000/clients/socket.io/123' ) ,
152103 } ) ,
153104 ) . toEqual ( {
154105 match : {
0 commit comments