msw 2.2.4 → 2.2.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/browser/index.js +35 -37
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +35 -37
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/bypass.js +6 -1
- package/lib/core/bypass.js.map +1 -1
- package/lib/core/bypass.mjs +6 -1
- package/lib/core/bypass.mjs.map +1 -1
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/iife/index.js +26 -24
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +8 -11
- package/package.json +2 -5
- package/src/browser/setupWorker/glossary.ts +4 -1
- package/src/browser/setupWorker/start/createRequestListener.ts +1 -1
- package/src/browser/setupWorker/start/createResponseListener.ts +2 -0
- package/src/browser/setupWorker/start/createStartHandler.ts +9 -19
- package/src/browser/setupWorker/start/utils/createMessageChannel.ts +1 -1
- package/src/browser/utils/checkWorkerIntegrity.ts +34 -0
- package/src/core/bypass.test.ts +22 -0
- package/src/core/bypass.ts +9 -1
- package/src/core/utils/handleRequest.ts +1 -1
- package/src/mockServiceWorker.js +7 -10
- package/src/browser/utils/requestIntegrityCheck.ts +0 -23
package/lib/browser/index.mjs
CHANGED
|
@@ -95,6 +95,9 @@ function isNodeProcess() {
|
|
|
95
95
|
return false;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
// src/browser/setupWorker/start/createStartHandler.ts
|
|
99
|
+
import { devUtils as devUtils7 } from '../core/utils/internal/devUtils.mjs';
|
|
100
|
+
|
|
98
101
|
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
99
102
|
var until = async (promise) => {
|
|
100
103
|
try {
|
|
@@ -107,9 +110,6 @@ var until = async (promise) => {
|
|
|
107
110
|
}
|
|
108
111
|
};
|
|
109
112
|
|
|
110
|
-
// src/browser/setupWorker/start/createStartHandler.ts
|
|
111
|
-
import { devUtils as devUtils6 } from '../core/utils/internal/devUtils.mjs';
|
|
112
|
-
|
|
113
113
|
// src/browser/setupWorker/start/utils/getWorkerInstance.ts
|
|
114
114
|
import { devUtils } from '../core/utils/internal/devUtils.mjs';
|
|
115
115
|
|
|
@@ -288,7 +288,7 @@ var createRequestListener = (context, options) => {
|
|
|
288
288
|
context.emitter,
|
|
289
289
|
{
|
|
290
290
|
onPassthroughResponse() {
|
|
291
|
-
messageChannel.postMessage("
|
|
291
|
+
messageChannel.postMessage("PASSTHROUGH");
|
|
292
292
|
},
|
|
293
293
|
async onMockedResponse(response, { handler, parsedResult }) {
|
|
294
294
|
const responseClone = response.clone();
|
|
@@ -352,18 +352,22 @@ This exception has been gracefully handled as a 500 response, however, it's stro
|
|
|
352
352
|
};
|
|
353
353
|
};
|
|
354
354
|
|
|
355
|
-
// src/browser/utils/
|
|
356
|
-
|
|
355
|
+
// src/browser/utils/checkWorkerIntegrity.ts
|
|
356
|
+
import { devUtils as devUtils5 } from '../core/utils/internal/devUtils.mjs';
|
|
357
|
+
async function checkWorkerIntegrity(context) {
|
|
357
358
|
context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
|
|
358
|
-
const { payload
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
359
|
+
const { payload } = await context.events.once("INTEGRITY_CHECK_RESPONSE");
|
|
360
|
+
if (payload.checksum !== "26357c79639bfa20d64c0efca2a87423") {
|
|
361
|
+
devUtils5.warn(
|
|
362
|
+
`The currently registered Service Worker has been generated by a different version of MSW (${payload.packageVersion}) and may not be fully compatible with the installed version.
|
|
363
|
+
|
|
364
|
+
It's recommended you update your worker script by running this command:
|
|
365
|
+
|
|
366
|
+
\u2022 npx msw init <PUBLIC_DIR>
|
|
367
|
+
|
|
368
|
+
You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`
|
|
364
369
|
);
|
|
365
370
|
}
|
|
366
|
-
return serviceWorker;
|
|
367
371
|
}
|
|
368
372
|
|
|
369
373
|
// node_modules/.pnpm/@mswjs+interceptors@0.25.16/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
|
|
@@ -1024,6 +1028,7 @@ function createResponseListener(context) {
|
|
|
1024
1028
|
const { requestId } = responseJson;
|
|
1025
1029
|
const request = context.requests.get(requestId);
|
|
1026
1030
|
context.requests.delete(requestId);
|
|
1031
|
+
console.log("RESPONSE LISTENER", responseJson, context.requests);
|
|
1027
1032
|
if (responseJson.type?.includes("opaque")) {
|
|
1028
1033
|
return;
|
|
1029
1034
|
}
|
|
@@ -1056,10 +1061,10 @@ function createResponseListener(context) {
|
|
|
1056
1061
|
}
|
|
1057
1062
|
|
|
1058
1063
|
// src/browser/setupWorker/start/utils/validateWorkerScope.ts
|
|
1059
|
-
import { devUtils as
|
|
1064
|
+
import { devUtils as devUtils6 } from '../core/utils/internal/devUtils.mjs';
|
|
1060
1065
|
function validateWorkerScope(registration, options) {
|
|
1061
1066
|
if (!options?.quiet && !location.href.startsWith(registration.scope)) {
|
|
1062
|
-
|
|
1067
|
+
devUtils6.warn(
|
|
1063
1068
|
`Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
|
|
1064
1069
|
|
|
1065
1070
|
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
@@ -1085,14 +1090,14 @@ var createStartHandler = (context) => {
|
|
|
1085
1090
|
);
|
|
1086
1091
|
const [worker, registration] = instance;
|
|
1087
1092
|
if (!worker) {
|
|
1088
|
-
const missingWorkerMessage = customOptions?.findWorker ?
|
|
1093
|
+
const missingWorkerMessage = customOptions?.findWorker ? devUtils7.formatMessage(
|
|
1089
1094
|
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
1090
1095
|
|
|
1091
1096
|
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
1092
1097
|
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
1093
1098
|
`,
|
|
1094
1099
|
options.serviceWorker.url
|
|
1095
|
-
) :
|
|
1100
|
+
) : devUtils7.formatMessage(
|
|
1096
1101
|
`Failed to locate the Service Worker registration.
|
|
1097
1102
|
|
|
1098
1103
|
This most likely means that the worker script URL "%s" cannot resolve against the actual public hostname (%s). This may happen if your application runs behind a proxy, or has a dynamic hostname.
|
|
@@ -1111,19 +1116,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
1111
1116
|
}
|
|
1112
1117
|
window.clearInterval(context.keepAliveInterval);
|
|
1113
1118
|
});
|
|
1114
|
-
|
|
1115
|
-
(
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
The mocking is still enabled, but it's highly recommended that you update your Service Worker by running:
|
|
1121
|
-
|
|
1122
|
-
$ npx msw init <PUBLIC_DIR>
|
|
1123
|
-
|
|
1124
|
-
This is necessary to ensure that the Service Worker is in sync with the library to guarantee its stability.
|
|
1125
|
-
If this message still persists after updating, please report an issue: https://github.com/open-draft/msw/issues `);
|
|
1126
|
-
}
|
|
1119
|
+
await checkWorkerIntegrity(context).catch((error2) => {
|
|
1120
|
+
devUtils7.error(
|
|
1121
|
+
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues), including the original error below."
|
|
1122
|
+
);
|
|
1123
|
+
console.error(error2);
|
|
1124
|
+
});
|
|
1127
1125
|
context.keepAliveInterval = window.setInterval(
|
|
1128
1126
|
() => context.workerChannel.send("KEEPALIVE_REQUEST"),
|
|
1129
1127
|
5e3
|
|
@@ -1154,16 +1152,16 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
1154
1152
|
};
|
|
1155
1153
|
|
|
1156
1154
|
// src/browser/setupWorker/stop/createStop.ts
|
|
1157
|
-
import { devUtils as
|
|
1155
|
+
import { devUtils as devUtils9 } from '../core/utils/internal/devUtils.mjs';
|
|
1158
1156
|
|
|
1159
1157
|
// src/browser/setupWorker/stop/utils/printStopMessage.ts
|
|
1160
|
-
import { devUtils as
|
|
1158
|
+
import { devUtils as devUtils8 } from '../core/utils/internal/devUtils.mjs';
|
|
1161
1159
|
function printStopMessage(args = {}) {
|
|
1162
1160
|
if (args.quiet) {
|
|
1163
1161
|
return;
|
|
1164
1162
|
}
|
|
1165
1163
|
console.log(
|
|
1166
|
-
`%c${
|
|
1164
|
+
`%c${devUtils8.formatMessage("Mocking disabled.")}`,
|
|
1167
1165
|
"color:orangered;font-weight:bold;"
|
|
1168
1166
|
);
|
|
1169
1167
|
}
|
|
@@ -1172,7 +1170,7 @@ function printStopMessage(args = {}) {
|
|
|
1172
1170
|
var createStop = (context) => {
|
|
1173
1171
|
return function stop() {
|
|
1174
1172
|
if (!context.isMockingEnabled) {
|
|
1175
|
-
|
|
1173
|
+
devUtils9.warn(
|
|
1176
1174
|
'Found a redundant "worker.stop()" call. Note that stopping the worker while mocking already stopped has no effect. Consider removing this "worker.stop()" call.'
|
|
1177
1175
|
);
|
|
1178
1176
|
return;
|
|
@@ -2263,7 +2261,7 @@ function createFallbackStop(context) {
|
|
|
2263
2261
|
}
|
|
2264
2262
|
|
|
2265
2263
|
// src/browser/setupWorker/setupWorker.ts
|
|
2266
|
-
import { devUtils as
|
|
2264
|
+
import { devUtils as devUtils10 } from '../core/utils/internal/devUtils.mjs';
|
|
2267
2265
|
import { SetupApi } from '../core/SetupApi.mjs';
|
|
2268
2266
|
import { mergeRight as mergeRight2 } from '../core/utils/internal/mergeRight.mjs';
|
|
2269
2267
|
|
|
@@ -2291,7 +2289,7 @@ var SetupWorkerApi = class extends SetupApi {
|
|
|
2291
2289
|
super(...handlers);
|
|
2292
2290
|
invariant(
|
|
2293
2291
|
!isNodeProcess(),
|
|
2294
|
-
|
|
2292
|
+
devUtils10.formatMessage(
|
|
2295
2293
|
"Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
|
|
2296
2294
|
)
|
|
2297
2295
|
);
|
|
@@ -2389,7 +2387,7 @@ var SetupWorkerApi = class extends SetupApi {
|
|
|
2389
2387
|
}
|
|
2390
2388
|
async start(options = {}) {
|
|
2391
2389
|
if (options.waitUntilReady === true) {
|
|
2392
|
-
|
|
2390
|
+
devUtils10.warn(
|
|
2393
2391
|
'The "waitUntilReady" option has been deprecated. Please remove it from this "worker.start()" call. Follow the recommended Browser integration (https://mswjs.io/docs/integrations/browser) to eliminate any race conditions between the Service Worker registration and any requests made by your application on initial render.'
|
|
2394
2392
|
);
|
|
2395
2393
|
}
|