msw 3.0.4 → 3.0.5
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/_chunks/interceptor-source.d.ts +15 -1
- package/lib/_chunks/interceptor-source.js +14 -2
- package/lib/_chunks/interceptor-source.js.map +1 -1
- package/lib/iife/index.js +104 -49
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +3 -3
- package/src/core/experimental/frames/http-frame.test.ts +14 -18
- package/src/core/experimental/frames/http-frame.ts +28 -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 = '3.0.
|
|
10
|
+
const PACKAGE_VERSION = '3.0.5'
|
|
11
11
|
const INTEGRITY_CHECKSUM = '0bd5af64c8dc112df5e0c5e9c8a2b15a'
|
|
12
12
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
13
13
|
// Cache Storage is shared by the whole origin. Scope the cache name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "The industry standard for API mocking in JavaScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/core/index.js",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"dependencies": {
|
|
118
118
|
"@inquirer/confirm": "^6.0.11",
|
|
119
119
|
"@msw/url": "^0.1.2",
|
|
120
|
-
"@mswjs/interceptors": "^0.45.
|
|
120
|
+
"@mswjs/interceptors": "^0.45.11",
|
|
121
121
|
"cookie": "^2.0.1",
|
|
122
122
|
"headers-polyfill": "^5.0.1",
|
|
123
123
|
"is-node-process": "^1.2.0",
|
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
"json-bigint": "^1.0.0",
|
|
160
160
|
"knip": "^6.34.0",
|
|
161
161
|
"lint-staged": "^17.1.1",
|
|
162
|
-
"msw": "^3.0.
|
|
162
|
+
"msw": "^3.0.5",
|
|
163
163
|
"oxlint": "^1.75.0",
|
|
164
164
|
"page-with": "^0.6.1",
|
|
165
165
|
"prettier": "^3.9.6",
|
|
@@ -81,15 +81,12 @@ test('resolves a matching request', async () => {
|
|
|
81
81
|
const { events } = spyOnNetworkFrame(frame)
|
|
82
82
|
const unhandledFrameCallback = vi.fn()
|
|
83
83
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
unhandledFrameCallback,
|
|
91
|
-
{ quiet: true },
|
|
92
|
-
)
|
|
84
|
+
const handler = http.get('http://localhost/api', () => {
|
|
85
|
+
return new Response(null, { status: 204 })
|
|
86
|
+
})
|
|
87
|
+
const matches = await frame.resolve([handler], unhandledFrameCallback, {
|
|
88
|
+
quiet: true,
|
|
89
|
+
})
|
|
93
90
|
|
|
94
91
|
expect.soft(matches).toBe(true)
|
|
95
92
|
expect.soft(frame.respondWith).toHaveBeenCalledExactlyOnceWith(
|
|
@@ -110,6 +107,7 @@ test('resolves a matching request', async () => {
|
|
|
110
107
|
type: 'request:match',
|
|
111
108
|
requestId: frame.data.id,
|
|
112
109
|
request: frame.data.request,
|
|
110
|
+
handler,
|
|
113
111
|
}),
|
|
114
112
|
expect.objectContaining({
|
|
115
113
|
type: 'request:end',
|
|
@@ -231,15 +229,12 @@ test('resolves a matched passthrough', async () => {
|
|
|
231
229
|
const { events } = spyOnNetworkFrame(frame)
|
|
232
230
|
const unhandledFrameCallback = vi.fn()
|
|
233
231
|
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
unhandledFrameCallback,
|
|
241
|
-
{ quiet: true },
|
|
242
|
-
)
|
|
232
|
+
const handler = http.get('http://localhost/api', () => {
|
|
233
|
+
// Intentionally do nothing to passthrough.
|
|
234
|
+
})
|
|
235
|
+
const matches = await frame.resolve([handler], unhandledFrameCallback, {
|
|
236
|
+
quiet: true,
|
|
237
|
+
})
|
|
243
238
|
|
|
244
239
|
expect.soft(matches).toBeNull()
|
|
245
240
|
expect.soft(frame.passthrough).toHaveBeenCalledOnce()
|
|
@@ -256,6 +251,7 @@ test('resolves a matched passthrough', async () => {
|
|
|
256
251
|
type: 'request:match',
|
|
257
252
|
requestId: frame.data.id,
|
|
258
253
|
request: frame.data.request,
|
|
254
|
+
handler,
|
|
259
255
|
}),
|
|
260
256
|
expect.objectContaining({
|
|
261
257
|
type: 'request:end',
|
|
@@ -43,6 +43,31 @@ class RequestEvent<
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
class RequestMatchEvent<
|
|
47
|
+
DataType extends {
|
|
48
|
+
requestId: string
|
|
49
|
+
request: Request
|
|
50
|
+
handler: RequestHandler
|
|
51
|
+
} = {
|
|
52
|
+
requestId: string
|
|
53
|
+
request: Request
|
|
54
|
+
handler: RequestHandler
|
|
55
|
+
},
|
|
56
|
+
ReturnType = void,
|
|
57
|
+
EventType extends string = string,
|
|
58
|
+
> extends TypedEvent<DataType, ReturnType, EventType> {
|
|
59
|
+
public readonly requestId: string
|
|
60
|
+
public readonly request: Request
|
|
61
|
+
public readonly handler: RequestHandler
|
|
62
|
+
|
|
63
|
+
constructor(type: EventType, data: DataType) {
|
|
64
|
+
super(...([type, {}] as any))
|
|
65
|
+
this.requestId = data.requestId
|
|
66
|
+
this.request = data.request
|
|
67
|
+
this.handler = data.handler
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
46
71
|
export class ResponseEvent<
|
|
47
72
|
DataType extends {
|
|
48
73
|
requestId: string
|
|
@@ -95,7 +120,7 @@ class UnhandledExceptionEvent<
|
|
|
95
120
|
|
|
96
121
|
export type HttpNetworkFrameEventMap = {
|
|
97
122
|
'request:start': RequestEvent
|
|
98
|
-
'request:match':
|
|
123
|
+
'request:match': RequestMatchEvent
|
|
99
124
|
'request:unhandled': RequestEvent
|
|
100
125
|
'request:end': RequestEvent
|
|
101
126
|
'response:mocked': ResponseEvent
|
|
@@ -239,9 +264,10 @@ export abstract class HttpNetworkFrame extends NetworkFrame<
|
|
|
239
264
|
const { response, handler, parsedResult } = lookupResult
|
|
240
265
|
|
|
241
266
|
this.events.emit(
|
|
242
|
-
new
|
|
267
|
+
new RequestMatchEvent('request:match', {
|
|
243
268
|
requestId,
|
|
244
269
|
request,
|
|
270
|
+
handler,
|
|
245
271
|
}),
|
|
246
272
|
)
|
|
247
273
|
|