msw 0.33.2 → 0.36.0
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/esm/RequestHandler-deps.js +447 -82
- package/lib/esm/errors-deps.js +15 -1
- package/lib/esm/fetch-deps.js +9 -5
- package/lib/esm/graphql-deps.js +15 -10
- package/lib/esm/graphql.js +1 -0
- package/lib/esm/index-deps.js +2 -1
- package/lib/esm/index.js +90 -3880
- package/lib/esm/index2.js +1 -1
- package/lib/esm/mockServiceWorker.js +21 -12
- package/lib/esm/rest-deps.js +8 -15
- package/lib/esm/rest.js +1 -0
- package/lib/iife/index.js +3 -3
- package/lib/iife/mockServiceWorker.js +21 -12
- package/lib/types/context/data.d.ts +2 -3
- package/lib/types/context/extensions.d.ts +8 -0
- package/lib/types/context/index.d.ts +1 -0
- package/lib/types/graphql.d.ts +2 -1
- package/lib/types/handlers/GraphQLHandler.d.ts +5 -4
- package/lib/types/handlers/RequestHandler.d.ts +1 -1
- package/lib/types/handlers/RestHandler.d.ts +8 -10
- package/lib/types/index.d.ts +17 -7
- package/lib/types/node/glossary.d.ts +4 -14
- package/lib/types/node/index.d.ts +1 -1
- package/lib/types/rest.d.ts +10 -9
- package/lib/types/setupWorker/glossary.d.ts +16 -26
- package/lib/types/setupWorker/start/utils/prepareStartHandler.d.ts +3 -3
- package/lib/types/sharedOptions.d.ts +12 -1
- package/lib/types/typeUtils.d.ts +5 -3
- package/lib/types/utils/handleRequest.d.ts +4 -4
- package/lib/types/utils/internal/getCallFrame.d.ts +1 -1
- package/lib/types/utils/internal/jsonParse.d.ts +2 -2
- package/lib/types/utils/internal/pipeEvents.d.ts +6 -0
- package/lib/types/utils/logging/prepareResponse.d.ts +1 -1
- package/lib/types/utils/matching/matchRequestUrl.d.ts +12 -2
- package/lib/types/utils/matching/normalizePath.d.ts +1 -1
- package/lib/types/utils/request/parseBody.d.ts +2 -2
- package/lib/types/utils/request/parseWorkerRequest.d.ts +2 -2
- package/lib/types/utils/worker/createFallbackRequestListener.d.ts +2 -1
- package/lib/types/utils/worker/createRequestListener.d.ts +2 -1
- package/lib/umd/index.js +1131 -249
- package/lib/umd/mockServiceWorker.js +21 -12
- package/native/lib/index.js +551 -508
- package/node/lib/index.js +553 -510
- package/package.json +19 -19
package/lib/esm/index2.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { d as cookie, e as delay, f as fetch, g as json, b as set, s as status } from './fetch-deps.js';
|
|
2
2
|
export { b as body, t as text, x as xml } from './xml-deps.js';
|
|
3
|
-
export { d as data,
|
|
3
|
+
export { d as data, a as errors, e as extensions } from './errors-deps.js';
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/* tslint:disable */
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Mock Service Worker (0.
|
|
5
|
+
* Mock Service Worker (0.36.0).
|
|
6
6
|
* @see https://github.com/mswjs/msw
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const INTEGRITY_CHECKSUM = '
|
|
11
|
+
const INTEGRITY_CHECKSUM = '02f4ad4a2797f85668baf196e553d929'
|
|
12
12
|
const bypassHeaderName = 'x-msw-bypass'
|
|
13
13
|
const activeClientIds = new Set()
|
|
14
14
|
|
|
@@ -83,11 +83,11 @@ self.addEventListener('message', async function (event) {
|
|
|
83
83
|
}
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
// Resolve the "
|
|
86
|
+
// Resolve the "main" client for the given event.
|
|
87
87
|
// Client that issues a request doesn't necessarily equal the client
|
|
88
88
|
// that registered the worker. It's with the latter the worker should
|
|
89
89
|
// communicate with during the response resolving phase.
|
|
90
|
-
async function
|
|
90
|
+
async function resolveMainClient(event) {
|
|
91
91
|
const client = await self.clients.get(event.clientId)
|
|
92
92
|
|
|
93
93
|
if (client.frameType === 'top-level') {
|
|
@@ -109,7 +109,7 @@ async function resolveMasterClient(event) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
async function handleRequest(event, requestId) {
|
|
112
|
-
const client = await
|
|
112
|
+
const client = await resolveMainClient(event)
|
|
113
113
|
const response = await getResponse(event, client, requestId)
|
|
114
114
|
|
|
115
115
|
// Send back the response clone for the "response:*" life-cycle events.
|
|
@@ -221,13 +221,11 @@ async function getResponse(event, client, requestId) {
|
|
|
221
221
|
|
|
222
222
|
console.error(
|
|
223
223
|
`\
|
|
224
|
-
[MSW]
|
|
224
|
+
[MSW] Uncaught exception in the request handler for "%s %s":
|
|
225
225
|
|
|
226
|
-
${parsedBody.
|
|
227
|
-
(see more detailed error stack trace in the mocked response body)
|
|
226
|
+
${parsedBody.location}
|
|
228
227
|
|
|
229
|
-
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error.
|
|
230
|
-
If you wish to mock an error response, please refer to this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
|
|
228
|
+
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
|
|
231
229
|
`,
|
|
232
230
|
request.method,
|
|
233
231
|
request.url,
|
|
@@ -271,11 +269,22 @@ self.addEventListener('fetch', function (event) {
|
|
|
271
269
|
|
|
272
270
|
return event.respondWith(
|
|
273
271
|
handleRequest(event, requestId).catch((error) => {
|
|
272
|
+
if (error.name === 'NetworkError') {
|
|
273
|
+
console.warn(
|
|
274
|
+
'[MSW] Successfully emulated a network error for the "%s %s" request.',
|
|
275
|
+
request.method,
|
|
276
|
+
request.url,
|
|
277
|
+
)
|
|
278
|
+
return
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// At this point, any exception indicates an issue with the original request/response.
|
|
274
282
|
console.error(
|
|
275
|
-
|
|
283
|
+
`\
|
|
284
|
+
[MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
|
|
276
285
|
request.method,
|
|
277
286
|
request.url,
|
|
278
|
-
error
|
|
287
|
+
`${error.name}: ${error.message}`,
|
|
279
288
|
)
|
|
280
289
|
}),
|
|
281
290
|
)
|
package/lib/esm/rest-deps.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
1
|
+
import { R as RequestHandler, f as cleanUrl, h as getSearchParams, d as devUtils, m as matchRequestUrl, g as getPublicUrlFromRequest, i as prepareRequest, j as prepareResponse, k as getStatusCodeColor, l as getTimestamp } from './RequestHandler-deps.js';
|
|
2
2
|
import { b as set, s as status, d as cookie, g as json, e as delay, f as fetch } from './fetch-deps.js';
|
|
3
3
|
import { b as body, t as text, x as xml } from './xml-deps.js';
|
|
4
4
|
|
|
@@ -58,21 +58,9 @@ class RestHandler extends RequestHandler {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
const searchParams = getSearchParams(path);
|
|
61
|
-
const queryParams = [];
|
|
62
61
|
searchParams.forEach((_, paramName) => {
|
|
63
|
-
queryParams.push(paramName);
|
|
64
62
|
});
|
|
65
|
-
devUtils.warn(
|
|
66
|
-
Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead, and access query parameters in the response resolver function:
|
|
67
|
-
|
|
68
|
-
rest.${method.toLowerCase()}("${url}", (req, res, ctx) => {
|
|
69
|
-
const query = req.url.searchParams
|
|
70
|
-
${queryParams
|
|
71
|
-
.map((paramName) => `\
|
|
72
|
-
const ${paramName} = query.get("${paramName}")`)
|
|
73
|
-
.join('\n')}
|
|
74
|
-
})\
|
|
75
|
-
`);
|
|
63
|
+
devUtils.warn(`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`);
|
|
76
64
|
}
|
|
77
65
|
parse(request, resolutionContext) {
|
|
78
66
|
return matchRequestUrl(request.url, this.info.path, resolutionContext === null || resolutionContext === void 0 ? void 0 : resolutionContext.baseUrl);
|
|
@@ -81,7 +69,11 @@ ${queryParams
|
|
|
81
69
|
return Object.assign(Object.assign({}, request), { params: parsedResult.params || {} });
|
|
82
70
|
}
|
|
83
71
|
predicate(request, parsedResult) {
|
|
84
|
-
|
|
72
|
+
const matchesMethod = this.info.method instanceof RegExp
|
|
73
|
+
? this.info.method.test(request.method)
|
|
74
|
+
: isStringEqual(this.info.method, request.method);
|
|
75
|
+
// console.log({ request, matchesMethod, parsedResult })
|
|
76
|
+
return matchesMethod && parsedResult.matches;
|
|
85
77
|
}
|
|
86
78
|
log(request, response) {
|
|
87
79
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
@@ -105,6 +97,7 @@ function createRestHandler(method) {
|
|
|
105
97
|
};
|
|
106
98
|
}
|
|
107
99
|
const rest = {
|
|
100
|
+
all: createRestHandler(/.+/),
|
|
108
101
|
head: createRestHandler(RESTMethods.HEAD),
|
|
109
102
|
get: createRestHandler(RESTMethods.GET),
|
|
110
103
|
post: createRestHandler(RESTMethods.POST),
|