msw 2.13.5 → 2.13.6
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/handlers/WebSocketHandler.d.mts +5 -2
- package/lib/core/handlers/WebSocketHandler.d.ts +5 -2
- package/lib/core/handlers/WebSocketHandler.js +22 -5
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +22 -5
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/iife/index.js +22 -5
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/handlers/WebSocketHandler.test.ts +58 -0
- package/src/core/handlers/WebSocketHandler.ts +36 -7
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.13.
|
|
10
|
+
const PACKAGE_VERSION = '2.13.6'
|
|
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.13.
|
|
3
|
+
"version": "2.13.6",
|
|
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",
|
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
"vitest-environment-miniflare": "^2.14.4",
|
|
287
287
|
"webpack": "^5.106.2",
|
|
288
288
|
"webpack-http-server": "^0.5.0",
|
|
289
|
-
"msw": "^2.13.
|
|
289
|
+
"msw": "^2.13.6"
|
|
290
290
|
},
|
|
291
291
|
"peerDependencies": {
|
|
292
292
|
"typescript": ">= 4.8.x"
|
|
@@ -125,3 +125,61 @@ describe('parse', () => {
|
|
|
125
125
|
})
|
|
126
126
|
})
|
|
127
127
|
})
|
|
128
|
+
|
|
129
|
+
describe('test', () => {
|
|
130
|
+
it('returns true for a matching string', () => {
|
|
131
|
+
expect(
|
|
132
|
+
new WebSocketHandler('ws://localhost/ws').test('ws://localhost/ws'),
|
|
133
|
+
).toBe(true)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('returns false for a non-matching string', () => {
|
|
137
|
+
expect(
|
|
138
|
+
new WebSocketHandler('ws://localhost/ws').test('ws://localhost/other'),
|
|
139
|
+
).toBe(false)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('returns true for a relative matching string', () => {
|
|
143
|
+
expect(
|
|
144
|
+
new WebSocketHandler('ws://localhost/ws').test('/ws', {
|
|
145
|
+
baseUrl: 'ws://localhost',
|
|
146
|
+
}),
|
|
147
|
+
).toBe(true)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('returns false for a relative non-matching string', () => {
|
|
151
|
+
expect(
|
|
152
|
+
new WebSocketHandler('ws://localhost/ws').test('/other', {
|
|
153
|
+
baseUrl: 'ws://localhost',
|
|
154
|
+
}),
|
|
155
|
+
).toBe(false)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('returns true for a matching URL', () => {
|
|
159
|
+
expect(
|
|
160
|
+
new WebSocketHandler('ws://localhost/ws').test(
|
|
161
|
+
new URL('ws://localhost/ws'),
|
|
162
|
+
),
|
|
163
|
+
).toBe(true)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('returns false for a non-matching URL', () => {
|
|
167
|
+
expect(
|
|
168
|
+
new WebSocketHandler('ws://localhost/ws').test(
|
|
169
|
+
new URL('ws://localhost/other'),
|
|
170
|
+
),
|
|
171
|
+
).toBe(false)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('returns true for a matching HTTP url string', () => {
|
|
175
|
+
expect(
|
|
176
|
+
new WebSocketHandler('ws://localhost/ws').test('http://localhost/ws'),
|
|
177
|
+
).toBe(true)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('returns false for a non-matching HTTP url string', () => {
|
|
181
|
+
expect(
|
|
182
|
+
new WebSocketHandler('ws://localhost/ws').test('http://localhost/other'),
|
|
183
|
+
).toBe(false)
|
|
184
|
+
})
|
|
185
|
+
})
|
|
@@ -57,7 +57,7 @@ export class WebSocketHandler {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
public parse(args: {
|
|
60
|
-
url: URL
|
|
60
|
+
url: string | URL
|
|
61
61
|
resolutionContext?: WebSocketResolutionContext
|
|
62
62
|
}): WebSocketHandlerParsedResult {
|
|
63
63
|
const clientUrl = new URL(args.url)
|
|
@@ -90,22 +90,26 @@ export class WebSocketHandler {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
public predicate(args: {
|
|
93
|
-
url: URL
|
|
93
|
+
url: string | URL
|
|
94
94
|
parsedResult: WebSocketHandlerParsedResult
|
|
95
95
|
}): boolean {
|
|
96
96
|
return args.parsedResult.match.matches
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
public test(
|
|
100
|
+
url: string | URL,
|
|
101
|
+
resolutionContext?: WebSocketResolutionContext & { strict?: boolean },
|
|
102
|
+
): boolean {
|
|
103
|
+
return this.#match(url, resolutionContext) != null
|
|
104
|
+
}
|
|
105
|
+
|
|
99
106
|
public async run(
|
|
100
107
|
connection: WebSocketConnectionData,
|
|
101
108
|
resolutionContext?: WebSocketResolutionContext,
|
|
102
109
|
): Promise<WebSocketHandlerConnection | null> {
|
|
103
|
-
const parsedResult = this.
|
|
104
|
-
url: connection.client.url,
|
|
105
|
-
resolutionContext,
|
|
106
|
-
})
|
|
110
|
+
const parsedResult = this.#match(connection.client.url, resolutionContext)
|
|
107
111
|
|
|
108
|
-
if (
|
|
112
|
+
if (parsedResult == null) {
|
|
109
113
|
return null
|
|
110
114
|
}
|
|
111
115
|
|
|
@@ -125,6 +129,31 @@ export class WebSocketHandler {
|
|
|
125
129
|
return resolvedConnection
|
|
126
130
|
}
|
|
127
131
|
|
|
132
|
+
#match(
|
|
133
|
+
url: string | URL,
|
|
134
|
+
resolutionContext?: WebSocketResolutionContext & { strict?: boolean },
|
|
135
|
+
): WebSocketHandlerParsedResult | null {
|
|
136
|
+
const resolvedUrl = this.#resolveWebSocketUrl(
|
|
137
|
+
url.toString(),
|
|
138
|
+
resolutionContext?.baseUrl,
|
|
139
|
+
)
|
|
140
|
+
const parsedResult = this.parse({
|
|
141
|
+
url: resolvedUrl,
|
|
142
|
+
resolutionContext,
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
if (
|
|
146
|
+
this.predicate({
|
|
147
|
+
url,
|
|
148
|
+
parsedResult,
|
|
149
|
+
})
|
|
150
|
+
) {
|
|
151
|
+
return parsedResult
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return null
|
|
155
|
+
}
|
|
156
|
+
|
|
128
157
|
protected [kConnect](connection: WebSocketHandlerConnection): boolean {
|
|
129
158
|
// Support `event.stopPropagation()` for various client/server events.
|
|
130
159
|
connection.client.addEventListener(
|