msw 2.12.13 → 2.12.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/utils/matching/matchRequestUrl.js +1 -1
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/iife/index.js +1 -1
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/utils/matching/matchRequestUrl.test.ts +87 -3
- package/src/core/utils/matching/matchRequestUrl.ts +2 -2
package/lib/mockServiceWorker.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const PACKAGE_VERSION = '2.12.
|
|
10
|
+
const PACKAGE_VERSION = '2.12.14'
|
|
11
11
|
const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82'
|
|
12
12
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
13
13
|
const activeClientIds = new Set()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.14",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./lib/core/index.js",
|
|
@@ -285,7 +285,7 @@
|
|
|
285
285
|
"vitest-environment-miniflare": "^2.14.4",
|
|
286
286
|
"webpack": "^5.95.0",
|
|
287
287
|
"webpack-http-server": "^0.5.0",
|
|
288
|
-
"msw": "2.12.
|
|
288
|
+
"msw": "2.12.14"
|
|
289
289
|
},
|
|
290
290
|
"peerDependencies": {
|
|
291
291
|
"typescript": ">= 4.8.x"
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* @vitest-environment jsdom
|
|
3
|
-
*/
|
|
1
|
+
// @vitest-environment jsdom
|
|
4
2
|
import { coercePath, matchRequestUrl } from './matchRequestUrl'
|
|
5
3
|
|
|
6
4
|
describe('matchRequestUrl', () => {
|
|
@@ -87,6 +85,77 @@ describe('matchRequestUrl', () => {
|
|
|
87
85
|
})
|
|
88
86
|
})
|
|
89
87
|
|
|
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
|
+
|
|
90
159
|
test('returns true for matching WebSocket URL', () => {
|
|
91
160
|
expect(
|
|
92
161
|
matchRequestUrl(new URL('ws://test.mswjs.io'), 'ws://test.mswjs.io'),
|
|
@@ -130,6 +199,17 @@ describe('matchRequestUrl', () => {
|
|
|
130
199
|
},
|
|
131
200
|
})
|
|
132
201
|
})
|
|
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
|
+
})
|
|
133
213
|
})
|
|
134
214
|
|
|
135
215
|
describe('coercePath', () => {
|
|
@@ -156,6 +236,10 @@ describe('coercePath', () => {
|
|
|
156
236
|
expect(coercePath('https://example.com:8080/:5678')).toEqual(
|
|
157
237
|
'https\\://example.com\\:8080/:5678',
|
|
158
238
|
)
|
|
239
|
+
expect(coercePath('http://localhost:*')).toEqual(
|
|
240
|
+
'http\\://localhost\\:(.*)',
|
|
241
|
+
)
|
|
242
|
+
expect(coercePath('ws://localhost:*')).toEqual('ws\\://localhost\\:(.*)')
|
|
159
243
|
})
|
|
160
244
|
|
|
161
245
|
test('replaces wildcard with an unnnamed capturing group', () => {
|
|
@@ -40,9 +40,9 @@ export function coercePath(path: string): string {
|
|
|
40
40
|
)
|
|
41
41
|
/**
|
|
42
42
|
* Escape the port so that "path-to-regexp" can match
|
|
43
|
-
* absolute URLs
|
|
43
|
+
* absolute URLs with numeric or wildcard ports.
|
|
44
44
|
*/
|
|
45
|
-
.replace(/([^/])(:)(
|
|
45
|
+
.replace(/([^/])(:)(?=(?:\d+|\(\.\*\))(?=\/|$))/, '$1\\$2')
|
|
46
46
|
/**
|
|
47
47
|
* Escape the protocol so that "path-to-regexp" could match
|
|
48
48
|
* absolute URL.
|