1- /**
2- * @vitest -environment jsdom
3- */
1+ // @vitest -environment jsdom
42import { coercePath , matchRequestUrl } from './matchRequestUrl'
53
64describe ( 'matchRequestUrl' , ( ) => {
@@ -87,6 +85,77 @@ describe('matchRequestUrl', () => {
8785 } )
8886 } )
8987
88+ test ( 'returns true when matching URLs with wildcard ports' , ( ) => {
89+ expect
90+ . soft (
91+ matchRequestUrl ( new URL ( 'http://localhost:3000' ) , 'http://localhost:*' ) ,
92+ )
93+ . toEqual ( {
94+ matches : true ,
95+ params : {
96+ '0' : '3000/' ,
97+ } ,
98+ } )
99+
100+ expect
101+ . soft (
102+ matchRequestUrl (
103+ new URL ( 'http://localhost:3000' ) ,
104+ 'http://localhost:*/' ,
105+ ) ,
106+ )
107+ . toEqual ( {
108+ matches : true ,
109+ params : {
110+ '0' : '3000' ,
111+ } ,
112+ } )
113+ } )
114+
115+ test ( 'returns true when matching URLs with wildcard ports and pathnames' , ( ) => {
116+ expect (
117+ matchRequestUrl (
118+ new URL ( 'http://localhost:3000/resource' ) ,
119+ 'http://localhost:*/resource' ,
120+ ) ,
121+ ) . toEqual ( {
122+ matches : true ,
123+ params : {
124+ '0' : '3000' ,
125+ } ,
126+ } )
127+ } )
128+
129+ test ( 'matches wildcard ports with other wildcard parameters' , ( ) => {
130+ expect (
131+ matchRequestUrl (
132+ new URL ( 'http://subdomain.localhost:3000/user/settings' ) ,
133+ 'http://*.localhost:*/user/*' ,
134+ ) ,
135+ ) . toEqual ( {
136+ matches : true ,
137+ params : {
138+ '0' : 'subdomain' ,
139+ '1' : '3000' ,
140+ '2' : 'settings' ,
141+ } ,
142+ } )
143+ } )
144+
145+ test ( 'matches wildcard ports that also match a part of the pathname' , ( ) => {
146+ expect (
147+ matchRequestUrl (
148+ new URL ( 'http://localhost:3000/user/settings' ) ,
149+ 'http://localhost:*/settings' ,
150+ ) ,
151+ ) . toEqual ( {
152+ matches : true ,
153+ params : {
154+ '0' : '3000/user' ,
155+ } ,
156+ } )
157+ } )
158+
90159 test ( 'returns true for matching WebSocket URL' , ( ) => {
91160 expect (
92161 matchRequestUrl ( new URL ( 'ws://test.mswjs.io' ) , 'ws://test.mswjs.io' ) ,
@@ -130,6 +199,17 @@ describe('matchRequestUrl', () => {
130199 } ,
131200 } )
132201 } )
202+
203+ test ( 'returns true for matching WebSocket URLs with wildcard ports' , ( ) => {
204+ expect (
205+ matchRequestUrl ( new URL ( 'ws://localhost:3000' ) , 'ws://localhost:*' ) ,
206+ ) . toEqual ( {
207+ matches : true ,
208+ params : {
209+ '0' : '3000/' ,
210+ } ,
211+ } )
212+ } )
133213} )
134214
135215describe ( 'coercePath' , ( ) => {
@@ -156,6 +236,10 @@ describe('coercePath', () => {
156236 expect ( coercePath ( 'https://example.com:8080/:5678' ) ) . toEqual (
157237 'https\\://example.com\\:8080/:5678' ,
158238 )
239+ expect ( coercePath ( 'http://localhost:*' ) ) . toEqual (
240+ 'http\\://localhost\\:(.*)' ,
241+ )
242+ expect ( coercePath ( 'ws://localhost:*' ) ) . toEqual ( 'ws\\://localhost\\:(.*)' )
159243 } )
160244
161245 test ( 'replaces wildcard with an unnnamed capturing group' , ( ) => {
0 commit comments