msw 2.2.3 → 2.2.5
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/cli/init.js +1 -1
- package/lib/browser/index.js +33 -36
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +33 -36
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-AenIUdwE.d.mts → GraphQLHandler-BumTfgY4.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-jOzqbxSK.d.ts → GraphQLHandler-DqVT0Gbq.d.ts} +1 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +2 -2
- package/lib/core/index.d.ts +2 -2
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.js +4 -1
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +4 -1
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/iife/index.js +21 -23
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +7 -3
- package/package.json +6 -9
- package/src/browser/setupWorker/glossary.ts +4 -1
- package/src/browser/setupWorker/start/createStartHandler.ts +9 -19
- package/src/browser/utils/checkWorkerIntegrity.ts +34 -0
- package/src/core/utils/HttpResponse/decorators.ts +8 -4
- package/src/mockServiceWorker.js +6 -2
- package/src/browser/utils/requestIntegrityCheck.ts +0 -23
- /package/lib/core/{HttpResponse-wcp03c7-.d.mts → HttpResponse-C94XLD-W.d.mts} +0 -0
- /package/lib/core/{HttpResponse-_514VQ9z.d.ts → HttpResponse-jHZ0p2dL.d.ts} +0 -0
package/cli/init.js
CHANGED
|
@@ -2,7 +2,7 @@ const fs = require('fs')
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const chalk = require('chalk')
|
|
4
4
|
const { until } = require('@open-draft/until')
|
|
5
|
-
const confirm = require('@inquirer/confirm')
|
|
5
|
+
const confirm = require('@inquirer/confirm').default
|
|
6
6
|
const invariant = require('./invariant')
|
|
7
7
|
const { SERVICE_WORKER_BUILD_PATH } = require('../config/constants')
|
|
8
8
|
|
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
|
|
|
@@ -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 !== "5db7e6e8385dc04e017ac4823e0e9b29") {
|
|
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
|
|
@@ -1083,10 +1087,10 @@ function createResponseListener(context) {
|
|
|
1083
1087
|
}
|
|
1084
1088
|
|
|
1085
1089
|
// src/browser/setupWorker/start/utils/validateWorkerScope.ts
|
|
1086
|
-
var
|
|
1090
|
+
var import_devUtils6 = require("../core/utils/internal/devUtils.js");
|
|
1087
1091
|
function validateWorkerScope(registration, options) {
|
|
1088
1092
|
if (!options?.quiet && !location.href.startsWith(registration.scope)) {
|
|
1089
|
-
|
|
1093
|
+
import_devUtils6.devUtils.warn(
|
|
1090
1094
|
`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
1095
|
|
|
1092
1096
|
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
@@ -1112,14 +1116,14 @@ var createStartHandler = (context) => {
|
|
|
1112
1116
|
);
|
|
1113
1117
|
const [worker, registration] = instance;
|
|
1114
1118
|
if (!worker) {
|
|
1115
|
-
const missingWorkerMessage = customOptions?.findWorker ?
|
|
1119
|
+
const missingWorkerMessage = customOptions?.findWorker ? import_devUtils7.devUtils.formatMessage(
|
|
1116
1120
|
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
1117
1121
|
|
|
1118
1122
|
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
1119
1123
|
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
1120
1124
|
`,
|
|
1121
1125
|
options.serviceWorker.url
|
|
1122
|
-
) :
|
|
1126
|
+
) : import_devUtils7.devUtils.formatMessage(
|
|
1123
1127
|
`Failed to locate the Service Worker registration.
|
|
1124
1128
|
|
|
1125
1129
|
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 +1142,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
1138
1142
|
}
|
|
1139
1143
|
window.clearInterval(context.keepAliveInterval);
|
|
1140
1144
|
});
|
|
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
|
-
}
|
|
1145
|
+
await checkWorkerIntegrity(context).catch((error2) => {
|
|
1146
|
+
import_devUtils7.devUtils.error(
|
|
1147
|
+
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues), including the original error below."
|
|
1148
|
+
);
|
|
1149
|
+
console.error(error2);
|
|
1150
|
+
});
|
|
1154
1151
|
context.keepAliveInterval = window.setInterval(
|
|
1155
1152
|
() => context.workerChannel.send("KEEPALIVE_REQUEST"),
|
|
1156
1153
|
5e3
|
|
@@ -1181,16 +1178,16 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
1181
1178
|
};
|
|
1182
1179
|
|
|
1183
1180
|
// src/browser/setupWorker/stop/createStop.ts
|
|
1184
|
-
var
|
|
1181
|
+
var import_devUtils9 = require("../core/utils/internal/devUtils.js");
|
|
1185
1182
|
|
|
1186
1183
|
// src/browser/setupWorker/stop/utils/printStopMessage.ts
|
|
1187
|
-
var
|
|
1184
|
+
var import_devUtils8 = require("../core/utils/internal/devUtils.js");
|
|
1188
1185
|
function printStopMessage(args = {}) {
|
|
1189
1186
|
if (args.quiet) {
|
|
1190
1187
|
return;
|
|
1191
1188
|
}
|
|
1192
1189
|
console.log(
|
|
1193
|
-
`%c${
|
|
1190
|
+
`%c${import_devUtils8.devUtils.formatMessage("Mocking disabled.")}`,
|
|
1194
1191
|
"color:orangered;font-weight:bold;"
|
|
1195
1192
|
);
|
|
1196
1193
|
}
|
|
@@ -1199,7 +1196,7 @@ function printStopMessage(args = {}) {
|
|
|
1199
1196
|
var createStop = (context) => {
|
|
1200
1197
|
return function stop() {
|
|
1201
1198
|
if (!context.isMockingEnabled) {
|
|
1202
|
-
|
|
1199
|
+
import_devUtils9.devUtils.warn(
|
|
1203
1200
|
'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
1201
|
);
|
|
1205
1202
|
return;
|
|
@@ -2290,7 +2287,7 @@ function createFallbackStop(context) {
|
|
|
2290
2287
|
}
|
|
2291
2288
|
|
|
2292
2289
|
// src/browser/setupWorker/setupWorker.ts
|
|
2293
|
-
var
|
|
2290
|
+
var import_devUtils10 = require("../core/utils/internal/devUtils.js");
|
|
2294
2291
|
var import_SetupApi = require("../core/SetupApi.js");
|
|
2295
2292
|
var import_mergeRight2 = require("../core/utils/internal/mergeRight.js");
|
|
2296
2293
|
|
|
@@ -2318,7 +2315,7 @@ var SetupWorkerApi = class extends import_SetupApi.SetupApi {
|
|
|
2318
2315
|
super(...handlers);
|
|
2319
2316
|
invariant(
|
|
2320
2317
|
!isNodeProcess(),
|
|
2321
|
-
|
|
2318
|
+
import_devUtils10.devUtils.formatMessage(
|
|
2322
2319
|
"Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
|
|
2323
2320
|
)
|
|
2324
2321
|
);
|
|
@@ -2416,7 +2413,7 @@ var SetupWorkerApi = class extends import_SetupApi.SetupApi {
|
|
|
2416
2413
|
}
|
|
2417
2414
|
async start(options = {}) {
|
|
2418
2415
|
if (options.waitUntilReady === true) {
|
|
2419
|
-
|
|
2416
|
+
import_devUtils10.devUtils.warn(
|
|
2420
2417
|
'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
2418
|
);
|
|
2422
2419
|
}
|