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.js
CHANGED
|
@@ -122,6 +122,9 @@ function isNodeProcess() {
|
|
|
122
122
|
return false;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
// src/browser/setupWorker/start/createStartHandler.ts
|
|
126
|
+
var import_devUtils7 = require("../core/utils/internal/devUtils.js");
|
|
127
|
+
|
|
125
128
|
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
126
129
|
var until = async (promise) => {
|
|
127
130
|
try {
|
|
@@ -134,9 +137,6 @@ var until = async (promise) => {
|
|
|
134
137
|
}
|
|
135
138
|
};
|
|
136
139
|
|
|
137
|
-
// src/browser/setupWorker/start/createStartHandler.ts
|
|
138
|
-
var import_devUtils6 = require("../core/utils/internal/devUtils.js");
|
|
139
|
-
|
|
140
140
|
// src/browser/setupWorker/start/utils/getWorkerInstance.ts
|
|
141
141
|
var import_devUtils = require("../core/utils/internal/devUtils.js");
|
|
142
142
|
|
|
@@ -315,7 +315,7 @@ var createRequestListener = (context, options) => {
|
|
|
315
315
|
context.emitter,
|
|
316
316
|
{
|
|
317
317
|
onPassthroughResponse() {
|
|
318
|
-
messageChannel.postMessage("
|
|
318
|
+
messageChannel.postMessage("PASSTHROUGH");
|
|
319
319
|
},
|
|
320
320
|
async onMockedResponse(response, { handler, parsedResult }) {
|
|
321
321
|
const responseClone = response.clone();
|
|
@@ -379,18 +379,22 @@ This exception has been gracefully handled as a 500 response, however, it's stro
|
|
|
379
379
|
};
|
|
380
380
|
};
|
|
381
381
|
|
|
382
|
-
// src/browser/utils/
|
|
383
|
-
|
|
382
|
+
// src/browser/utils/checkWorkerIntegrity.ts
|
|
383
|
+
var import_devUtils5 = require("../core/utils/internal/devUtils.js");
|
|
384
|
+
async function checkWorkerIntegrity(context) {
|
|
384
385
|
context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
|
|
385
|
-
const { payload
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
386
|
+
const { payload } = await context.events.once("INTEGRITY_CHECK_RESPONSE");
|
|
387
|
+
if (payload.checksum !== "26357c79639bfa20d64c0efca2a87423") {
|
|
388
|
+
import_devUtils5.devUtils.warn(
|
|
389
|
+
`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.
|
|
390
|
+
|
|
391
|
+
It's recommended you update your worker script by running this command:
|
|
392
|
+
|
|
393
|
+
\u2022 npx msw init <PUBLIC_DIR>
|
|
394
|
+
|
|
395
|
+
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.`
|
|
391
396
|
);
|
|
392
397
|
}
|
|
393
|
-
return serviceWorker;
|
|
394
398
|
}
|
|
395
399
|
|
|
396
400
|
// node_modules/.pnpm/@mswjs+interceptors@0.25.16/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
|
|
@@ -1051,6 +1055,7 @@ function createResponseListener(context) {
|
|
|
1051
1055
|
const { requestId } = responseJson;
|
|
1052
1056
|
const request = context.requests.get(requestId);
|
|
1053
1057
|
context.requests.delete(requestId);
|
|
1058
|
+
console.log("RESPONSE LISTENER", responseJson, context.requests);
|
|
1054
1059
|
if (responseJson.type?.includes("opaque")) {
|
|
1055
1060
|
return;
|
|
1056
1061
|
}
|
|
@@ -1083,10 +1088,10 @@ function createResponseListener(context) {
|
|
|
1083
1088
|
}
|
|
1084
1089
|
|
|
1085
1090
|
// src/browser/setupWorker/start/utils/validateWorkerScope.ts
|
|
1086
|
-
var
|
|
1091
|
+
var import_devUtils6 = require("../core/utils/internal/devUtils.js");
|
|
1087
1092
|
function validateWorkerScope(registration, options) {
|
|
1088
1093
|
if (!options?.quiet && !location.href.startsWith(registration.scope)) {
|
|
1089
|
-
|
|
1094
|
+
import_devUtils6.devUtils.warn(
|
|
1090
1095
|
`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.
|
|
1091
1096
|
|
|
1092
1097
|
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
@@ -1112,14 +1117,14 @@ var createStartHandler = (context) => {
|
|
|
1112
1117
|
);
|
|
1113
1118
|
const [worker, registration] = instance;
|
|
1114
1119
|
if (!worker) {
|
|
1115
|
-
const missingWorkerMessage = customOptions?.findWorker ?
|
|
1120
|
+
const missingWorkerMessage = customOptions?.findWorker ? import_devUtils7.devUtils.formatMessage(
|
|
1116
1121
|
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
1117
1122
|
|
|
1118
1123
|
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
1119
1124
|
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
1120
1125
|
`,
|
|
1121
1126
|
options.serviceWorker.url
|
|
1122
|
-
) :
|
|
1127
|
+
) : import_devUtils7.devUtils.formatMessage(
|
|
1123
1128
|
`Failed to locate the Service Worker registration.
|
|
1124
1129
|
|
|
1125
1130
|
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.
|
|
@@ -1138,19 +1143,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
1138
1143
|
}
|
|
1139
1144
|
window.clearInterval(context.keepAliveInterval);
|
|
1140
1145
|
});
|
|
1141
|
-
|
|
1142
|
-
(
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
The mocking is still enabled, but it's highly recommended that you update your Service Worker by running:
|
|
1148
|
-
|
|
1149
|
-
$ npx msw init <PUBLIC_DIR>
|
|
1150
|
-
|
|
1151
|
-
This is necessary to ensure that the Service Worker is in sync with the library to guarantee its stability.
|
|
1152
|
-
If this message still persists after updating, please report an issue: https://github.com/open-draft/msw/issues `);
|
|
1153
|
-
}
|
|
1146
|
+
await checkWorkerIntegrity(context).catch((error2) => {
|
|
1147
|
+
import_devUtils7.devUtils.error(
|
|
1148
|
+
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues), including the original error below."
|
|
1149
|
+
);
|
|
1150
|
+
console.error(error2);
|
|
1151
|
+
});
|
|
1154
1152
|
context.keepAliveInterval = window.setInterval(
|
|
1155
1153
|
() => context.workerChannel.send("KEEPALIVE_REQUEST"),
|
|
1156
1154
|
5e3
|
|
@@ -1181,16 +1179,16 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
1181
1179
|
};
|
|
1182
1180
|
|
|
1183
1181
|
// src/browser/setupWorker/stop/createStop.ts
|
|
1184
|
-
var
|
|
1182
|
+
var import_devUtils9 = require("../core/utils/internal/devUtils.js");
|
|
1185
1183
|
|
|
1186
1184
|
// src/browser/setupWorker/stop/utils/printStopMessage.ts
|
|
1187
|
-
var
|
|
1185
|
+
var import_devUtils8 = require("../core/utils/internal/devUtils.js");
|
|
1188
1186
|
function printStopMessage(args = {}) {
|
|
1189
1187
|
if (args.quiet) {
|
|
1190
1188
|
return;
|
|
1191
1189
|
}
|
|
1192
1190
|
console.log(
|
|
1193
|
-
`%c${
|
|
1191
|
+
`%c${import_devUtils8.devUtils.formatMessage("Mocking disabled.")}`,
|
|
1194
1192
|
"color:orangered;font-weight:bold;"
|
|
1195
1193
|
);
|
|
1196
1194
|
}
|
|
@@ -1199,7 +1197,7 @@ function printStopMessage(args = {}) {
|
|
|
1199
1197
|
var createStop = (context) => {
|
|
1200
1198
|
return function stop() {
|
|
1201
1199
|
if (!context.isMockingEnabled) {
|
|
1202
|
-
|
|
1200
|
+
import_devUtils9.devUtils.warn(
|
|
1203
1201
|
'Found a redundant "worker.stop()" call. Note that stopping the worker while mocking already stopped has no effect. Consider removing this "worker.stop()" call.'
|
|
1204
1202
|
);
|
|
1205
1203
|
return;
|
|
@@ -2290,7 +2288,7 @@ function createFallbackStop(context) {
|
|
|
2290
2288
|
}
|
|
2291
2289
|
|
|
2292
2290
|
// src/browser/setupWorker/setupWorker.ts
|
|
2293
|
-
var
|
|
2291
|
+
var import_devUtils10 = require("../core/utils/internal/devUtils.js");
|
|
2294
2292
|
var import_SetupApi = require("../core/SetupApi.js");
|
|
2295
2293
|
var import_mergeRight2 = require("../core/utils/internal/mergeRight.js");
|
|
2296
2294
|
|
|
@@ -2318,7 +2316,7 @@ var SetupWorkerApi = class extends import_SetupApi.SetupApi {
|
|
|
2318
2316
|
super(...handlers);
|
|
2319
2317
|
invariant(
|
|
2320
2318
|
!isNodeProcess(),
|
|
2321
|
-
|
|
2319
|
+
import_devUtils10.devUtils.formatMessage(
|
|
2322
2320
|
"Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
|
|
2323
2321
|
)
|
|
2324
2322
|
);
|
|
@@ -2416,7 +2414,7 @@ var SetupWorkerApi = class extends import_SetupApi.SetupApi {
|
|
|
2416
2414
|
}
|
|
2417
2415
|
async start(options = {}) {
|
|
2418
2416
|
if (options.waitUntilReady === true) {
|
|
2419
|
-
|
|
2417
|
+
import_devUtils10.devUtils.warn(
|
|
2420
2418
|
'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.'
|
|
2421
2419
|
);
|
|
2422
2420
|
}
|