msw 0.42.0 → 0.42.3
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/README.md +7 -1
- package/lib/iife/index.js +30 -18
- package/lib/iife/index.js.map +1 -1
- package/lib/index.d.ts +9 -0
- package/lib/index.js +28 -16
- package/lib/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +37 -19
- package/lib/native/index.mjs +37 -19
- package/lib/node/index.js +37 -19
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +37 -19
- package/lib/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -200,10 +200,16 @@ test('handles login exception', () => {
|
|
|
200
200
|
|
|
201
201
|
### Silver Sponsors
|
|
202
202
|
|
|
203
|
-
> Become our
|
|
203
|
+
> Become our _silver sponsor_ and get your profile image and link featured right here.
|
|
204
204
|
>
|
|
205
205
|
> **Learn more on our [GitHub Sponsors profile](https://github.com/sponsors/mswjs)**.
|
|
206
206
|
|
|
207
|
+
<br />
|
|
208
|
+
|
|
209
|
+
<a href="https://www.chromatic.com/" target="_blank">
|
|
210
|
+
<img src="media/sponsors/chromatic.svg#1" alt="Chromatic" width="75" />
|
|
211
|
+
</a>
|
|
212
|
+
|
|
207
213
|
### Bronze Sponsors
|
|
208
214
|
|
|
209
215
|
> Become our first _bronze sponsor_ and get your profile image and link featured in this section.
|
package/lib/iife/index.js
CHANGED
|
@@ -1444,7 +1444,7 @@ var MockServiceWorker = (() => {
|
|
|
1444
1444
|
}(Error);
|
|
1445
1445
|
exports.InvariantError = InvariantError;
|
|
1446
1446
|
function createInvariantWith(ErrorConstructor) {
|
|
1447
|
-
var
|
|
1447
|
+
var invariant3 = function(predicate, message) {
|
|
1448
1448
|
var positionals = [];
|
|
1449
1449
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1450
1450
|
positionals[_i - 2] = arguments[_i];
|
|
@@ -1457,7 +1457,7 @@ var MockServiceWorker = (() => {
|
|
|
1457
1457
|
throw error2;
|
|
1458
1458
|
}
|
|
1459
1459
|
};
|
|
1460
|
-
return
|
|
1460
|
+
return invariant3;
|
|
1461
1461
|
}
|
|
1462
1462
|
exports.createInvariantWith = createInvariantWith;
|
|
1463
1463
|
function polymorphicInvariant(ErrorClass) {
|
|
@@ -7643,8 +7643,8 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
7643
7643
|
}
|
|
7644
7644
|
const parsedBody = {};
|
|
7645
7645
|
try {
|
|
7646
|
-
for (const
|
|
7647
|
-
const [contentHeaders, ...rest2] =
|
|
7646
|
+
for (const field2 of fields) {
|
|
7647
|
+
const [contentHeaders, ...rest2] = field2.split("\r\n\r\n");
|
|
7648
7648
|
const contentBody = rest2.join("\r\n\r\n");
|
|
7649
7649
|
const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
|
|
7650
7650
|
const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
|
|
@@ -10140,6 +10140,23 @@ spurious results.`);
|
|
|
10140
10140
|
}
|
|
10141
10141
|
};
|
|
10142
10142
|
|
|
10143
|
+
// src/context/field.ts
|
|
10144
|
+
var import_outvariant2 = __toESM(require_lib5());
|
|
10145
|
+
var field = (fieldName, fieldValue) => {
|
|
10146
|
+
return (res) => {
|
|
10147
|
+
validateFieldName(fieldName);
|
|
10148
|
+
const prevBody = jsonParse(res.body) || {};
|
|
10149
|
+
const nextBody = mergeRight(prevBody, { [fieldName]: fieldValue });
|
|
10150
|
+
return json(nextBody)(res);
|
|
10151
|
+
};
|
|
10152
|
+
};
|
|
10153
|
+
function validateFieldName(fieldName) {
|
|
10154
|
+
(0, import_outvariant2.invariant)(fieldName.trim() !== "", devUtils.formatMessage("Failed to set a custom field on a GraphQL response: field name cannot be empty."));
|
|
10155
|
+
(0, import_outvariant2.invariant)(fieldName !== "data", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.data()" instead?', fieldName));
|
|
10156
|
+
(0, import_outvariant2.invariant)(fieldName !== "errors", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.errors()" instead?', fieldName));
|
|
10157
|
+
(0, import_outvariant2.invariant)(fieldName !== "extensions", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.extensions()" instead?', fieldName));
|
|
10158
|
+
}
|
|
10159
|
+
|
|
10143
10160
|
// src/utils/internal/tryCatch.ts
|
|
10144
10161
|
function tryCatch(fn, onException) {
|
|
10145
10162
|
try {
|
|
@@ -10155,7 +10172,8 @@ spurious results.`);
|
|
|
10155
10172
|
data,
|
|
10156
10173
|
extensions,
|
|
10157
10174
|
errors,
|
|
10158
|
-
cookie
|
|
10175
|
+
cookie,
|
|
10176
|
+
field
|
|
10159
10177
|
});
|
|
10160
10178
|
function isDocumentNode(value) {
|
|
10161
10179
|
if (value == null) {
|
|
@@ -10343,7 +10361,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
10343
10361
|
|
|
10344
10362
|
// src/utils/handleRequest.ts
|
|
10345
10363
|
async function handleRequest(request, handlers, options, emitter, handleRequestOptions) {
|
|
10346
|
-
var _a, _b, _c, _d;
|
|
10364
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10347
10365
|
emitter.emit("request:start", request);
|
|
10348
10366
|
if (request.headers.get("x-msw-bypass") === "true") {
|
|
10349
10367
|
emitter.emit("request:end", request);
|
|
@@ -10381,18 +10399,12 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
10381
10399
|
}
|
|
10382
10400
|
readResponseCookies(request, response2);
|
|
10383
10401
|
emitter.emit("request:match", request);
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
var _a3;
|
|
10391
|
-
(_a3 = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponseSent) == null ? void 0 : _a3.call(handleRequestOptions, transformedResponse, requiredLookupResult);
|
|
10392
|
-
emitter.emit("request:end", request);
|
|
10393
|
-
resolve(transformedResponse);
|
|
10394
|
-
}, (_c2 = response2.delay) != null ? _c2 : 0);
|
|
10395
|
-
});
|
|
10402
|
+
const requiredLookupResult = lookupResult;
|
|
10403
|
+
const transformedResponse = ((_e = handleRequestOptions == null ? void 0 : handleRequestOptions.transformResponse) == null ? void 0 : _e.call(handleRequestOptions, response2)) || response2;
|
|
10404
|
+
(_f = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponse) == null ? void 0 : _f.call(handleRequestOptions, transformedResponse, requiredLookupResult);
|
|
10405
|
+
(_g = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponseSent) == null ? void 0 : _g.call(handleRequestOptions, transformedResponse, requiredLookupResult);
|
|
10406
|
+
emitter.emit("request:end", request);
|
|
10407
|
+
return transformedResponse;
|
|
10396
10408
|
}
|
|
10397
10409
|
|
|
10398
10410
|
// src/utils/worker/createRequestListener.ts
|