msw 0.42.2 → 0.43.1
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 +10 -1
- package/lib/iife/index.js +74 -34
- package/lib/iife/index.js.map +1 -1
- package/lib/index.js +72 -32
- package/lib/index.js.map +1 -1
- package/lib/mockServiceWorker.js +162 -133
- package/lib/native/index.js +15 -15
- package/lib/native/index.mjs +15 -15
- package/lib/node/index.js +15 -15
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +15 -15
- package/lib/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -198,6 +198,15 @@ test('handles login exception', () => {
|
|
|
198
198
|
>
|
|
199
199
|
> **Learn more on our [GitHub Sponsors profile](https://github.com/sponsors/mswjs)**.
|
|
200
200
|
|
|
201
|
+
<br />
|
|
202
|
+
|
|
203
|
+
<a href="https://www.github.com/" target="_blank">
|
|
204
|
+
<picture>
|
|
205
|
+
<source media="(prefers-color-scheme: dark)" srcset="media/sponsors/github-light.svg" />
|
|
206
|
+
<img src="media/sponsors/github.svg" alt="GitHub" width="75" />
|
|
207
|
+
</picture>
|
|
208
|
+
</a>
|
|
209
|
+
|
|
201
210
|
### Silver Sponsors
|
|
202
211
|
|
|
203
212
|
> Become our _silver sponsor_ and get your profile image and link featured right here.
|
|
@@ -207,7 +216,7 @@ test('handles login exception', () => {
|
|
|
207
216
|
<br />
|
|
208
217
|
|
|
209
218
|
<a href="https://www.chromatic.com/" target="_blank">
|
|
210
|
-
<img src="media/sponsors/chromatic.svg
|
|
219
|
+
<img src="media/sponsors/chromatic.svg" alt="Chromatic" width="75" />
|
|
211
220
|
</a>
|
|
212
221
|
|
|
213
222
|
### Bronze Sponsors
|
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 invariant4 = 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 invariant4;
|
|
1461
1461
|
}
|
|
1462
1462
|
exports.createInvariantWith = createInvariantWith;
|
|
1463
1463
|
function polymorphicInvariant(ErrorClass) {
|
|
@@ -7080,7 +7080,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
7080
7080
|
var cookie = (name, value, options) => {
|
|
7081
7081
|
return (res) => {
|
|
7082
7082
|
const serializedCookie = cookieUtils.serialize(name, value, options);
|
|
7083
|
-
res.headers.
|
|
7083
|
+
res.headers.append("Set-Cookie", serializedCookie);
|
|
7084
7084
|
if (typeof document !== "undefined") {
|
|
7085
7085
|
document.cookie = serializedCookie;
|
|
7086
7086
|
}
|
|
@@ -7382,17 +7382,18 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
7382
7382
|
});
|
|
7383
7383
|
}
|
|
7384
7384
|
|
|
7385
|
-
// src/utils/
|
|
7386
|
-
|
|
7385
|
+
// src/setupWorker/start/utils/createMessageChannel.ts
|
|
7386
|
+
function createMessageChannel(event) {
|
|
7387
7387
|
const port = event.ports[0];
|
|
7388
7388
|
return {
|
|
7389
7389
|
send(message) {
|
|
7390
|
-
if (port) {
|
|
7391
|
-
|
|
7390
|
+
if (!port) {
|
|
7391
|
+
return;
|
|
7392
7392
|
}
|
|
7393
|
+
port.postMessage(message);
|
|
7393
7394
|
}
|
|
7394
7395
|
};
|
|
7395
|
-
}
|
|
7396
|
+
}
|
|
7396
7397
|
|
|
7397
7398
|
// src/utils/NetworkError.ts
|
|
7398
7399
|
var NetworkError = class extends Error {
|
|
@@ -10361,7 +10362,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
10361
10362
|
|
|
10362
10363
|
// src/utils/handleRequest.ts
|
|
10363
10364
|
async function handleRequest(request, handlers, options, emitter, handleRequestOptions) {
|
|
10364
|
-
var _a, _b, _c, _d;
|
|
10365
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10365
10366
|
emitter.emit("request:start", request);
|
|
10366
10367
|
if (request.headers.get("x-msw-bypass") === "true") {
|
|
10367
10368
|
emitter.emit("request:end", request);
|
|
@@ -10399,38 +10400,77 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
10399
10400
|
}
|
|
10400
10401
|
readResponseCookies(request, response2);
|
|
10401
10402
|
emitter.emit("request:match", request);
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
|
|
10407
|
-
|
|
10408
|
-
|
|
10409
|
-
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
|
|
10403
|
+
const requiredLookupResult = lookupResult;
|
|
10404
|
+
const transformedResponse = ((_e = handleRequestOptions == null ? void 0 : handleRequestOptions.transformResponse) == null ? void 0 : _e.call(handleRequestOptions, response2)) || response2;
|
|
10405
|
+
(_f = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponse) == null ? void 0 : _f.call(handleRequestOptions, transformedResponse, requiredLookupResult);
|
|
10406
|
+
(_g = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponseSent) == null ? void 0 : _g.call(handleRequestOptions, transformedResponse, requiredLookupResult);
|
|
10407
|
+
emitter.emit("request:end", request);
|
|
10408
|
+
return transformedResponse;
|
|
10409
|
+
}
|
|
10410
|
+
|
|
10411
|
+
// src/setupWorker/start/utils/streamResponse.ts
|
|
10412
|
+
var import_outvariant3 = __toESM(require_lib5());
|
|
10413
|
+
async function streamResponse(operationChannel, messageChannel, mockedResponse) {
|
|
10414
|
+
const response2 = new Response(mockedResponse.body, mockedResponse);
|
|
10415
|
+
delete mockedResponse.body;
|
|
10416
|
+
messageChannel.send({
|
|
10417
|
+
type: "MOCK_RESPONSE_START",
|
|
10418
|
+
payload: mockedResponse
|
|
10413
10419
|
});
|
|
10420
|
+
(0, import_outvariant3.invariant)(response2.body, "Failed to stream mocked response with no body");
|
|
10421
|
+
const reader = response2.body.getReader();
|
|
10422
|
+
while (true) {
|
|
10423
|
+
const { done, value } = await reader.read();
|
|
10424
|
+
if (!done) {
|
|
10425
|
+
operationChannel.postMessage({
|
|
10426
|
+
type: "MOCK_RESPONSE_CHUNK",
|
|
10427
|
+
payload: value
|
|
10428
|
+
});
|
|
10429
|
+
continue;
|
|
10430
|
+
}
|
|
10431
|
+
operationChannel.postMessage({
|
|
10432
|
+
type: "MOCK_RESPONSE_END"
|
|
10433
|
+
});
|
|
10434
|
+
operationChannel.close();
|
|
10435
|
+
reader.releaseLock();
|
|
10436
|
+
break;
|
|
10437
|
+
}
|
|
10414
10438
|
}
|
|
10415
10439
|
|
|
10416
|
-
// src/utils/
|
|
10440
|
+
// src/utils/internal/StrictBroadcastChannel.ts
|
|
10441
|
+
var ParentClass = typeof BroadcastChannel == "undefined" ? class UnsupportedEnvironment {
|
|
10442
|
+
constructor() {
|
|
10443
|
+
throw new Error("Cannot construct BroadcastChannel in a non-browser environment");
|
|
10444
|
+
}
|
|
10445
|
+
} : BroadcastChannel;
|
|
10446
|
+
var StrictBroadcastChannel = class extends ParentClass {
|
|
10447
|
+
postMessage(message) {
|
|
10448
|
+
return super.postMessage(message);
|
|
10449
|
+
}
|
|
10450
|
+
};
|
|
10451
|
+
|
|
10452
|
+
// src/setupWorker/start/createRequestListener.ts
|
|
10417
10453
|
var createRequestListener = (context, options) => {
|
|
10418
10454
|
return async (event, message) => {
|
|
10419
|
-
const
|
|
10455
|
+
const messageChannel = createMessageChannel(event);
|
|
10420
10456
|
try {
|
|
10421
10457
|
const request = parseWorkerRequest(message.payload);
|
|
10458
|
+
const operationChannel = new StrictBroadcastChannel(`msw-response-stream-${request.id}`);
|
|
10422
10459
|
await handleRequest(request, context.requestHandlers, options, context.emitter, {
|
|
10423
10460
|
transformResponse,
|
|
10424
10461
|
onPassthroughResponse() {
|
|
10425
|
-
return
|
|
10462
|
+
return messageChannel.send({
|
|
10426
10463
|
type: "MOCK_NOT_FOUND"
|
|
10427
10464
|
});
|
|
10428
10465
|
},
|
|
10429
10466
|
onMockedResponse(response2) {
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
10467
|
+
if (response2.body == null) {
|
|
10468
|
+
return messageChannel.send({
|
|
10469
|
+
type: "MOCK_RESPONSE",
|
|
10470
|
+
payload: response2
|
|
10471
|
+
});
|
|
10472
|
+
}
|
|
10473
|
+
streamResponse(operationChannel, messageChannel, response2);
|
|
10434
10474
|
},
|
|
10435
10475
|
onMockedResponseSent(response2, { handler, publicRequest, parsedRequest }) {
|
|
10436
10476
|
if (options.quiet) {
|
|
@@ -10441,7 +10481,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
10441
10481
|
});
|
|
10442
10482
|
} catch (error2) {
|
|
10443
10483
|
if (error2 instanceof NetworkError) {
|
|
10444
|
-
return
|
|
10484
|
+
return messageChannel.send({
|
|
10445
10485
|
type: "NETWORK_ERROR",
|
|
10446
10486
|
payload: {
|
|
10447
10487
|
name: error2.name,
|
|
@@ -10450,7 +10490,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
10450
10490
|
});
|
|
10451
10491
|
}
|
|
10452
10492
|
if (error2 instanceof Error) {
|
|
10453
|
-
|
|
10493
|
+
messageChannel.send({
|
|
10454
10494
|
type: "INTERNAL_ERROR",
|
|
10455
10495
|
payload: {
|
|
10456
10496
|
status: 500,
|
|
@@ -10479,8 +10519,8 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
10479
10519
|
async function requestIntegrityCheck(context, serviceWorker) {
|
|
10480
10520
|
context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
|
|
10481
10521
|
const { payload: actualChecksum } = await context.events.once("INTEGRITY_CHECK_RESPONSE");
|
|
10482
|
-
if (actualChecksum !== "
|
|
10483
|
-
throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"
|
|
10522
|
+
if (actualChecksum !== "c9450df6e4dc5e45740c3b0b640727a2") {
|
|
10523
|
+
throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"c9450df6e4dc5e45740c3b0b640727a2"}).`);
|
|
10484
10524
|
}
|
|
10485
10525
|
return serviceWorker;
|
|
10486
10526
|
}
|
|
@@ -10503,7 +10543,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
10503
10543
|
};
|
|
10504
10544
|
}
|
|
10505
10545
|
|
|
10506
|
-
// src/
|
|
10546
|
+
// src/setupWorker/start/createResponseListener.ts
|
|
10507
10547
|
function createResponseListener(context) {
|
|
10508
10548
|
return (_, message) => {
|
|
10509
10549
|
var _a;
|
|
@@ -10657,7 +10697,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
10657
10697
|
};
|
|
10658
10698
|
}
|
|
10659
10699
|
|
|
10660
|
-
// src/
|
|
10700
|
+
// src/setupWorker/start/createFallbackRequestListener.ts
|
|
10661
10701
|
var import_interceptors = __toESM(require_lib8());
|
|
10662
10702
|
var import_fetch3 = __toESM(require_fetch());
|
|
10663
10703
|
var import_XMLHttpRequest = __toESM(require_XMLHttpRequest());
|
|
@@ -10687,7 +10727,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
10687
10727
|
return mockedRequest;
|
|
10688
10728
|
}
|
|
10689
10729
|
|
|
10690
|
-
// src/
|
|
10730
|
+
// src/setupWorker/start/createFallbackRequestListener.ts
|
|
10691
10731
|
function createFallbackRequestListener(context, options) {
|
|
10692
10732
|
const interceptor = new import_interceptors.BatchInterceptor({
|
|
10693
10733
|
name: "fallback",
|