msw 2.3.0-ws.rc-5 → 2.3.0
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 +0 -0
- package/config/scripts/postinstall.js +0 -0
- package/lib/browser/index.d.mts +6 -7
- package/lib/browser/index.d.ts +6 -7
- package/lib/browser/index.js +156 -81
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +156 -81
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-DGyzNtRQ.d.ts → GraphQLHandler-COiPfZ8k.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-CzcXr7At.d.mts → GraphQLHandler-Dq_WRbKe.d.mts} +1 -1
- package/lib/core/{HttpResponse-BOzDwzB6.d.ts → HttpResponse-B07UKAkU.d.ts} +2 -2
- package/lib/core/{HttpResponse-CSyJ1cbO.d.mts → HttpResponse-C7niBMwb.d.mts} +2 -2
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +12 -15
- package/lib/core/SetupApi.d.ts +12 -15
- package/lib/core/SetupApi.js +1 -3
- package/lib/core/SetupApi.js.map +1 -1
- package/lib/core/SetupApi.mjs +1 -3
- package/lib/core/SetupApi.mjs.map +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 -5
- package/lib/core/index.d.ts +2 -5
- package/lib/core/index.js +1 -5
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -7
- package/lib/core/index.mjs.map +1 -1
- 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/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/executeHandlers.js +0 -4
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +0 -6
- package/lib/core/utils/executeHandlers.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -2
- package/lib/core/utils/handleRequest.d.ts +2 -2
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/Disposable.d.mts +2 -2
- package/lib/core/utils/internal/Disposable.d.ts +2 -2
- package/lib/core/utils/internal/Disposable.js +5 -2
- package/lib/core/utils/internal/Disposable.js.map +1 -1
- package/lib/core/utils/internal/Disposable.mjs +5 -2
- package/lib/core/utils/internal/Disposable.mjs.map +1 -1
- package/lib/core/utils/internal/devUtils.d.mts +10 -1
- package/lib/core/utils/internal/devUtils.d.ts +10 -1
- package/lib/core/utils/internal/devUtils.js +7 -0
- package/lib/core/utils/internal/devUtils.js.map +1 -1
- package/lib/core/utils/internal/devUtils.mjs +7 -0
- package/lib/core/utils/internal/devUtils.mjs.map +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/core/utils/logging/getTimestamp.d.mts +1 -4
- package/lib/core/utils/logging/getTimestamp.d.ts +1 -4
- package/lib/core/utils/logging/getTimestamp.js +2 -6
- package/lib/core/utils/logging/getTimestamp.js.map +1 -1
- package/lib/core/utils/logging/getTimestamp.mjs +2 -6
- package/lib/core/utils/logging/getTimestamp.mjs.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +1 -2
- package/lib/core/utils/matching/matchRequestUrl.d.ts +1 -2
- package/lib/core/utils/matching/matchRequestUrl.js +0 -4
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +0 -4
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.js +3 -3
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +4 -4
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/iife/index.js +177 -1063
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +5 -6
- package/lib/native/index.d.ts +5 -6
- package/lib/native/index.js +5 -13
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +6 -14
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +7 -8
- package/lib/node/index.d.ts +7 -8
- package/lib/node/index.js +5 -13
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +6 -14
- package/lib/node/index.mjs.map +1 -1
- package/package.json +36 -29
- package/src/browser/setupWorker/glossary.ts +10 -10
- package/src/browser/setupWorker/setupWorker.ts +3 -34
- package/src/core/SetupApi.ts +20 -28
- package/src/core/index.ts +1 -8
- package/src/core/utils/executeHandlers.ts +2 -6
- package/src/core/utils/handleRequest.ts +2 -1
- package/src/core/utils/internal/Disposable.ts +6 -3
- package/src/core/utils/internal/devUtils.test.ts +21 -0
- package/src/core/utils/internal/devUtils.ts +13 -0
- package/src/core/utils/logging/getTimestamp.test.ts +6 -20
- package/src/core/utils/logging/getTimestamp.ts +6 -11
- package/src/core/utils/matching/matchRequestUrl.test.ts +0 -44
- package/src/core/utils/matching/matchRequestUrl.ts +0 -4
- package/src/core/utils/request/onUnhandledRequest.test.ts +30 -4
- package/src/core/utils/request/onUnhandledRequest.ts +4 -4
- package/src/node/SetupServerApi.ts +7 -8
- package/src/node/SetupServerCommonApi.ts +8 -15
- package/src/node/glossary.ts +7 -5
- package/src/node/setupServer.ts +1 -2
- package/lib/core/handlers/WebSocketHandler.d.mts +0 -32
- package/lib/core/handlers/WebSocketHandler.d.ts +0 -32
- package/lib/core/handlers/WebSocketHandler.js +0 -62
- package/lib/core/handlers/WebSocketHandler.js.map +0 -1
- package/lib/core/handlers/WebSocketHandler.mjs +0 -44
- package/lib/core/handlers/WebSocketHandler.mjs.map +0 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +0 -64
- package/lib/core/ws/WebSocketClientManager.d.ts +0 -64
- package/lib/core/ws/WebSocketClientManager.js +0 -123
- package/lib/core/ws/WebSocketClientManager.js.map +0 -1
- package/lib/core/ws/WebSocketClientManager.mjs +0 -103
- package/lib/core/ws/WebSocketClientManager.mjs.map +0 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +0 -16
- package/lib/core/ws/handleWebSocketEvent.d.ts +0 -16
- package/lib/core/ws/handleWebSocketEvent.js +0 -56
- package/lib/core/ws/handleWebSocketEvent.js.map +0 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +0 -36
- package/lib/core/ws/handleWebSocketEvent.mjs.map +0 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +0 -34
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +0 -34
- package/lib/core/ws/utils/attachWebSocketLogger.js +0 -217
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +0 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +0 -197
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +0 -1
- package/lib/core/ws/utils/getMessageLength.d.mts +0 -11
- package/lib/core/ws/utils/getMessageLength.d.ts +0 -11
- package/lib/core/ws/utils/getMessageLength.js +0 -33
- package/lib/core/ws/utils/getMessageLength.js.map +0 -1
- package/lib/core/ws/utils/getMessageLength.mjs +0 -13
- package/lib/core/ws/utils/getMessageLength.mjs.map +0 -1
- package/lib/core/ws/utils/getPublicData.d.mts +0 -5
- package/lib/core/ws/utils/getPublicData.d.ts +0 -5
- package/lib/core/ws/utils/getPublicData.js +0 -36
- package/lib/core/ws/utils/getPublicData.js.map +0 -1
- package/lib/core/ws/utils/getPublicData.mjs +0 -16
- package/lib/core/ws/utils/getPublicData.mjs.map +0 -1
- package/lib/core/ws/utils/truncateMessage.d.mts +0 -3
- package/lib/core/ws/utils/truncateMessage.d.ts +0 -3
- package/lib/core/ws/utils/truncateMessage.js +0 -31
- package/lib/core/ws/utils/truncateMessage.js.map +0 -1
- package/lib/core/ws/utils/truncateMessage.mjs +0 -11
- package/lib/core/ws/utils/truncateMessage.mjs.map +0 -1
- package/lib/core/ws/webSocketInterceptor.d.mts +0 -5
- package/lib/core/ws/webSocketInterceptor.d.ts +0 -5
- package/lib/core/ws/webSocketInterceptor.js +0 -26
- package/lib/core/ws/webSocketInterceptor.js.map +0 -1
- package/lib/core/ws/webSocketInterceptor.mjs +0 -6
- package/lib/core/ws/webSocketInterceptor.mjs.map +0 -1
- package/lib/core/ws.d.mts +0 -49
- package/lib/core/ws.d.ts +0 -49
- package/lib/core/ws.js +0 -63
- package/lib/core/ws.js.map +0 -1
- package/lib/core/ws.mjs +0 -46
- package/lib/core/ws.mjs.map +0 -1
- package/src/core/handlers/WebSocketHandler.ts +0 -71
- package/src/core/ws/WebSocketClientManager.test.ts +0 -159
- package/src/core/ws/WebSocketClientManager.ts +0 -170
- package/src/core/ws/handleWebSocketEvent.ts +0 -56
- package/src/core/ws/utils/attachWebSocketLogger.ts +0 -269
- package/src/core/ws/utils/getMessageLength.test.ts +0 -16
- package/src/core/ws/utils/getMessageLength.ts +0 -19
- package/src/core/ws/utils/getPublicData.test.ts +0 -38
- package/src/core/ws/utils/getPublicData.ts +0 -17
- package/src/core/ws/utils/truncateMessage.test.ts +0 -12
- package/src/core/ws/utils/truncateMessage.ts +0 -9
- package/src/core/ws/webSocketInterceptor.ts +0 -3
- package/src/core/ws.test.ts +0 -23
- package/src/core/ws.ts +0 -122
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.3.0
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"main": "./lib/core/index.js",
|
|
6
6
|
"module": "./lib/core/index.mjs",
|
|
@@ -14,22 +14,34 @@
|
|
|
14
14
|
"default": "./lib/core/index.js"
|
|
15
15
|
},
|
|
16
16
|
"./browser": {
|
|
17
|
-
"node": null,
|
|
18
17
|
"types": "./lib/browser/index.d.ts",
|
|
18
|
+
"browser": {
|
|
19
|
+
"require": "./lib/browser/index.js",
|
|
20
|
+
"import": "./lib/browser/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"node": null,
|
|
19
23
|
"require": "./lib/browser/index.js",
|
|
20
24
|
"import": "./lib/browser/index.mjs",
|
|
21
25
|
"default": "./lib/browser/index.js"
|
|
22
26
|
},
|
|
23
27
|
"./node": {
|
|
24
|
-
"browser": null,
|
|
25
28
|
"types": "./lib/node/index.d.ts",
|
|
29
|
+
"node": {
|
|
30
|
+
"require": "./lib/node/index.js",
|
|
31
|
+
"import": "./lib/node/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"browser": null,
|
|
26
34
|
"require": "./lib/node/index.js",
|
|
27
35
|
"import": "./lib/node/index.mjs",
|
|
28
36
|
"default": "./lib/node/index.mjs"
|
|
29
37
|
},
|
|
30
38
|
"./native": {
|
|
31
|
-
"browser": null,
|
|
32
39
|
"types": "./lib/native/index.d.ts",
|
|
40
|
+
"react-native": {
|
|
41
|
+
"require": "./lib/native/index.js",
|
|
42
|
+
"import": "./lib/native/index.mjs"
|
|
43
|
+
},
|
|
44
|
+
"browser": null,
|
|
33
45
|
"require": "./lib/native/index.js",
|
|
34
46
|
"import": "./lib/native/index.mjs",
|
|
35
47
|
"default": "./lib/native/index.js"
|
|
@@ -55,26 +67,6 @@
|
|
|
55
67
|
"engines": {
|
|
56
68
|
"node": ">=18"
|
|
57
69
|
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"start": "tsup --watch",
|
|
60
|
-
"clean": "rimraf ./lib",
|
|
61
|
-
"lint": "eslint \"{cli,config,src,test}/**/*.ts\"",
|
|
62
|
-
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
|
|
63
|
-
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
|
|
64
|
-
"check:exports": "node \"./config/scripts/validate-esm.js\"",
|
|
65
|
-
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
|
|
66
|
-
"test:unit": "vitest",
|
|
67
|
-
"test:node": "vitest run --config=./test/node/vitest.config.ts",
|
|
68
|
-
"test:native": "vitest --config=./test/native/vitest.config.ts",
|
|
69
|
-
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
|
|
70
|
-
"test:modules:node": "vitest run --config=./test/modules/node/vitest.config.ts",
|
|
71
|
-
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
|
|
72
|
-
"test:ts": "vitest --typecheck --config=./test/typings/vitest.config.ts",
|
|
73
|
-
"prepare": "pnpm simple-git-hooks init",
|
|
74
|
-
"prepack": "pnpm build",
|
|
75
|
-
"release": "release publish",
|
|
76
|
-
"postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\""
|
|
77
|
-
},
|
|
78
70
|
"lint-staged": {
|
|
79
71
|
"**/*.ts": [
|
|
80
72
|
"eslint --fix"
|
|
@@ -125,7 +117,7 @@
|
|
|
125
117
|
"@bundled-es-modules/statuses": "^1.0.1",
|
|
126
118
|
"@inquirer/confirm": "^3.0.0",
|
|
127
119
|
"@mswjs/cookies": "^1.1.0",
|
|
128
|
-
"@mswjs/interceptors": "^0.
|
|
120
|
+
"@mswjs/interceptors": "^0.29.0",
|
|
129
121
|
"@open-draft/until": "^2.1.0",
|
|
130
122
|
"@types/cookie": "^0.6.0",
|
|
131
123
|
"@types/statuses": "^2.0.4",
|
|
@@ -142,7 +134,6 @@
|
|
|
142
134
|
"devDependencies": {
|
|
143
135
|
"@commitlint/cli": "^18.4.4",
|
|
144
136
|
"@commitlint/config-conventional": "^18.4.4",
|
|
145
|
-
"@fastify/websocket": "^8.3.1",
|
|
146
137
|
"@open-draft/test-server": "^0.4.2",
|
|
147
138
|
"@ossjs/release": "^0.8.1",
|
|
148
139
|
"@playwright/test": "^1.40.1",
|
|
@@ -152,7 +143,6 @@
|
|
|
152
143
|
"@types/glob": "^8.1.0",
|
|
153
144
|
"@types/json-bigint": "^1.0.4",
|
|
154
145
|
"@types/node": "18.x",
|
|
155
|
-
"@types/ws": "^8.5.10",
|
|
156
146
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
157
147
|
"@typescript-eslint/parser": "^7.2.0",
|
|
158
148
|
"@web/dev-server": "^0.1.38",
|
|
@@ -168,7 +158,6 @@
|
|
|
168
158
|
"eslint-config-prettier": "^9.1.0",
|
|
169
159
|
"eslint-plugin-prettier": "^5.1.3",
|
|
170
160
|
"express": "^4.18.2",
|
|
171
|
-
"fastify": "^4.26.0",
|
|
172
161
|
"fs-extra": "^11.2.0",
|
|
173
162
|
"fs-teardown": "^0.3.0",
|
|
174
163
|
"glob": "^10.3.10",
|
|
@@ -207,5 +196,23 @@
|
|
|
207
196
|
"pre-commit": "pnpm lint-staged",
|
|
208
197
|
"prepare-commit-msg": "grep -qE '^[^#]' .git/COMMIT_EDITMSG || (exec < /dev/tty && pnpm cz --hook || true)",
|
|
209
198
|
"commit-msg": "pnpm commitlint --edit $1"
|
|
199
|
+
},
|
|
200
|
+
"scripts": {
|
|
201
|
+
"start": "tsup --watch",
|
|
202
|
+
"clean": "rimraf ./lib",
|
|
203
|
+
"lint": "eslint \"{cli,config,src,test}/**/*.ts\"",
|
|
204
|
+
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
|
|
205
|
+
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
|
|
206
|
+
"check:exports": "node \"./config/scripts/validate-esm.js\"",
|
|
207
|
+
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
|
|
208
|
+
"test:unit": "vitest",
|
|
209
|
+
"test:node": "vitest run --config=./test/node/vitest.config.ts",
|
|
210
|
+
"test:native": "vitest --config=./test/native/vitest.config.ts",
|
|
211
|
+
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
|
|
212
|
+
"test:modules:node": "vitest --config=./test/modules/node/vitest.config.ts",
|
|
213
|
+
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
|
|
214
|
+
"test:ts": "vitest --typecheck --config=./test/typings/vitest.config.ts",
|
|
215
|
+
"release": "release publish",
|
|
216
|
+
"postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\""
|
|
210
217
|
}
|
|
211
|
-
}
|
|
218
|
+
}
|
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
SharedOptions,
|
|
6
6
|
} from '~/core/sharedOptions'
|
|
7
7
|
import { ServiceWorkerMessage } from './start/utils/createMessageChannel'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
RequestHandler,
|
|
10
|
+
RequestHandlerDefaultInfo,
|
|
11
|
+
} from '~/core/handlers/RequestHandler'
|
|
9
12
|
import type { HttpRequestEventMap, Interceptor } from '@mswjs/interceptors'
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
|
|
13
|
+
import { Path } from '~/core/utils/matching/matchRequestUrl'
|
|
14
|
+
import { RequiredDeep } from '~/core/typeUtils'
|
|
13
15
|
|
|
14
16
|
export type ResolvedPath = Path | URL
|
|
15
17
|
|
|
@@ -85,7 +87,7 @@ export interface SetupWorkerInternalContext {
|
|
|
85
87
|
startOptions: RequiredDeep<StartOptions>
|
|
86
88
|
worker: ServiceWorker | null
|
|
87
89
|
registration: ServiceWorkerRegistration | null
|
|
88
|
-
getRequestHandlers(): Array<RequestHandler
|
|
90
|
+
getRequestHandlers(): Array<RequestHandler>
|
|
89
91
|
requests: Map<string, Request>
|
|
90
92
|
emitter: Emitter<LifeCycleEventsMap>
|
|
91
93
|
keepAliveInterval?: number
|
|
@@ -209,7 +211,7 @@ export interface SetupWorker {
|
|
|
209
211
|
*
|
|
210
212
|
* @see {@link https://mswjs.io/docs/api/setup-worker/use `worker.use()` API reference}
|
|
211
213
|
*/
|
|
212
|
-
use: (...handlers:
|
|
214
|
+
use: (...handlers: RequestHandler[]) => void
|
|
213
215
|
|
|
214
216
|
/**
|
|
215
217
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
@@ -224,16 +226,14 @@ export interface SetupWorker {
|
|
|
224
226
|
*
|
|
225
227
|
* @see {@link https://mswjs.io/docs/api/setup-worker/reset-handlers `worker.resetHandlers()` API reference}
|
|
226
228
|
*/
|
|
227
|
-
resetHandlers: (
|
|
228
|
-
...nextHandlers: Array<RequestHandler | WebSocketHandler>
|
|
229
|
-
) => void
|
|
229
|
+
resetHandlers: (...nextHandlers: RequestHandler[]) => void
|
|
230
230
|
|
|
231
231
|
/**
|
|
232
232
|
* Returns a readonly list of currently active request handlers.
|
|
233
233
|
*
|
|
234
234
|
* @see {@link https://mswjs.io/docs/api/setup-worker/list-handlers `worker.listHandlers()` API reference}
|
|
235
235
|
*/
|
|
236
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
236
|
+
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>
|
|
237
237
|
|
|
238
238
|
/**
|
|
239
239
|
* Life-cycle events.
|
|
@@ -18,13 +18,9 @@ import { createFallbackStop } from './stop/createFallbackStop'
|
|
|
18
18
|
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
19
19
|
import { SetupApi } from '~/core/SetupApi'
|
|
20
20
|
import { mergeRight } from '~/core/utils/internal/mergeRight'
|
|
21
|
-
import
|
|
22
|
-
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
|
|
21
|
+
import { LifeCycleEventsMap } from '~/core/sharedOptions'
|
|
23
22
|
import { SetupWorker } from './glossary'
|
|
24
23
|
import { supportsReadableStreamTransfer } from '../utils/supportsReadableStreamTransfer'
|
|
25
|
-
import { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'
|
|
26
|
-
import { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'
|
|
27
|
-
import { attachWebSocketLogger } from '~/core/ws/utils/attachWebSocketLogger'
|
|
28
24
|
|
|
29
25
|
interface Listener {
|
|
30
26
|
target: EventTarget
|
|
@@ -41,7 +37,7 @@ export class SetupWorkerApi
|
|
|
41
37
|
private stopHandler: StopHandler = null as any
|
|
42
38
|
private listeners: Array<Listener>
|
|
43
39
|
|
|
44
|
-
constructor(...handlers: Array<RequestHandler
|
|
40
|
+
constructor(...handlers: Array<RequestHandler>) {
|
|
45
41
|
super(...handlers)
|
|
46
42
|
|
|
47
43
|
invariant(
|
|
@@ -180,31 +176,6 @@ export class SetupWorkerApi
|
|
|
180
176
|
options,
|
|
181
177
|
) as SetupWorkerInternalContext['startOptions']
|
|
182
178
|
|
|
183
|
-
// Enable WebSocket interception.
|
|
184
|
-
handleWebSocketEvent({
|
|
185
|
-
getHandlers: () => {
|
|
186
|
-
return this.handlersController.currentHandlers()
|
|
187
|
-
},
|
|
188
|
-
onMockedConnection: (connection) => {
|
|
189
|
-
if (!this.context.startOptions.quiet) {
|
|
190
|
-
// Attach the logger for mocked connections since
|
|
191
|
-
// those won't be visible in the browser's devtools.
|
|
192
|
-
attachWebSocketLogger(connection)
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
onPassthroughConnection() {
|
|
196
|
-
/**
|
|
197
|
-
* @fixme Call some "onUnhandledConnection".
|
|
198
|
-
*/
|
|
199
|
-
},
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
webSocketInterceptor.apply()
|
|
203
|
-
|
|
204
|
-
this.subscriptions.push(() => {
|
|
205
|
-
webSocketInterceptor.dispose()
|
|
206
|
-
})
|
|
207
|
-
|
|
208
179
|
return await this.startHandler(this.context.startOptions, options)
|
|
209
180
|
}
|
|
210
181
|
|
|
@@ -222,8 +193,6 @@ export class SetupWorkerApi
|
|
|
222
193
|
*
|
|
223
194
|
* @see {@link https://mswjs.io/docs/api/setup-worker `setupWorker()` API reference}
|
|
224
195
|
*/
|
|
225
|
-
export function setupWorker(
|
|
226
|
-
...handlers: Array<RequestHandler | WebSocketHandler>
|
|
227
|
-
): SetupWorker {
|
|
196
|
+
export function setupWorker(...handlers: Array<RequestHandler>): SetupWorker {
|
|
228
197
|
return new SetupWorkerApi(...handlers)
|
|
229
198
|
}
|
package/src/core/SetupApi.ts
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
import { invariant } from 'outvariant'
|
|
2
2
|
import { EventMap, Emitter } from 'strict-event-emitter'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
RequestHandler,
|
|
5
|
+
RequestHandlerDefaultInfo,
|
|
6
|
+
} from './handlers/RequestHandler'
|
|
4
7
|
import { LifeCycleEventEmitter } from './sharedOptions'
|
|
5
8
|
import { devUtils } from './utils/internal/devUtils'
|
|
6
9
|
import { pipeEvents } from './utils/internal/pipeEvents'
|
|
7
10
|
import { toReadonlyArray } from './utils/internal/toReadonlyArray'
|
|
8
11
|
import { Disposable } from './utils/internal/Disposable'
|
|
9
|
-
import type { WebSocketHandler } from './handlers/WebSocketHandler'
|
|
10
12
|
|
|
11
13
|
export abstract class HandlersController {
|
|
12
|
-
abstract prepend(
|
|
13
|
-
|
|
14
|
-
):
|
|
15
|
-
abstract reset(nextHandles: Array<RequestHandler | WebSocketHandler>): void
|
|
16
|
-
abstract currentHandlers(): Array<RequestHandler | WebSocketHandler>
|
|
14
|
+
abstract prepend(runtimeHandlers: Array<RequestHandler>): void
|
|
15
|
+
abstract reset(nextHandles: Array<RequestHandler>): void
|
|
16
|
+
abstract currentHandlers(): Array<RequestHandler>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export class InMemoryHandlersController implements HandlersController {
|
|
20
|
-
private handlers: Array<RequestHandler
|
|
20
|
+
private handlers: Array<RequestHandler>
|
|
21
21
|
|
|
22
|
-
constructor(
|
|
23
|
-
private initialHandlers: Array<RequestHandler | WebSocketHandler>,
|
|
24
|
-
) {
|
|
22
|
+
constructor(private initialHandlers: Array<RequestHandler>) {
|
|
25
23
|
this.handlers = [...initialHandlers]
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
public prepend(
|
|
29
|
-
runtimeHandles: Array<RequestHandler | WebSocketHandler>,
|
|
30
|
-
): void {
|
|
26
|
+
public prepend(runtimeHandles: Array<RequestHandler>): void {
|
|
31
27
|
this.handlers.unshift(...runtimeHandles)
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
public reset(nextHandlers: Array<RequestHandler
|
|
30
|
+
public reset(nextHandlers: Array<RequestHandler>): void {
|
|
35
31
|
this.handlers =
|
|
36
32
|
nextHandlers.length > 0 ? [...nextHandlers] : [...this.initialHandlers]
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
public currentHandlers(): Array<RequestHandler
|
|
35
|
+
public currentHandlers(): Array<RequestHandler> {
|
|
40
36
|
return this.handlers
|
|
41
37
|
}
|
|
42
38
|
}
|
|
@@ -51,7 +47,7 @@ export abstract class SetupApi<EventsMap extends EventMap> extends Disposable {
|
|
|
51
47
|
|
|
52
48
|
public readonly events: LifeCycleEventEmitter<EventsMap>
|
|
53
49
|
|
|
54
|
-
constructor(...initialHandlers: Array<RequestHandler
|
|
50
|
+
constructor(...initialHandlers: Array<RequestHandler>) {
|
|
55
51
|
super()
|
|
56
52
|
|
|
57
53
|
invariant(
|
|
@@ -75,14 +71,12 @@ export abstract class SetupApi<EventsMap extends EventMap> extends Disposable {
|
|
|
75
71
|
})
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
private validateHandlers(handlers: ReadonlyArray<
|
|
74
|
+
private validateHandlers(handlers: ReadonlyArray<RequestHandler>): boolean {
|
|
79
75
|
// Guard against incorrect call signature of the setup API.
|
|
80
76
|
return handlers.every((handler) => !Array.isArray(handler))
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
public use(
|
|
84
|
-
...runtimeHandlers: Array<RequestHandler | WebSocketHandler>
|
|
85
|
-
): void {
|
|
79
|
+
public use(...runtimeHandlers: Array<RequestHandler>): void {
|
|
86
80
|
invariant(
|
|
87
81
|
this.validateHandlers(runtimeHandlers),
|
|
88
82
|
devUtils.formatMessage(
|
|
@@ -95,19 +89,17 @@ export abstract class SetupApi<EventsMap extends EventMap> extends Disposable {
|
|
|
95
89
|
|
|
96
90
|
public restoreHandlers(): void {
|
|
97
91
|
this.handlersController.currentHandlers().forEach((handler) => {
|
|
98
|
-
|
|
99
|
-
handler.isUsed = false
|
|
100
|
-
}
|
|
92
|
+
handler.isUsed = false
|
|
101
93
|
})
|
|
102
94
|
}
|
|
103
95
|
|
|
104
|
-
public resetHandlers(
|
|
105
|
-
...nextHandlers: Array<RequestHandler | WebSocketHandler>
|
|
106
|
-
): void {
|
|
96
|
+
public resetHandlers(...nextHandlers: Array<RequestHandler>): void {
|
|
107
97
|
this.handlersController.reset(nextHandlers)
|
|
108
98
|
}
|
|
109
99
|
|
|
110
|
-
public listHandlers(): ReadonlyArray<
|
|
100
|
+
public listHandlers(): ReadonlyArray<
|
|
101
|
+
RequestHandler<RequestHandlerDefaultInfo, any, any>
|
|
102
|
+
> {
|
|
111
103
|
return toReadonlyArray(this.handlersController.currentHandlers())
|
|
112
104
|
}
|
|
113
105
|
|
package/src/core/index.ts
CHANGED
|
@@ -2,20 +2,13 @@ import { checkGlobals } from './utils/internal/checkGlobals'
|
|
|
2
2
|
|
|
3
3
|
export { SetupApi } from './SetupApi'
|
|
4
4
|
|
|
5
|
-
/*
|
|
5
|
+
/* Request handlers */
|
|
6
6
|
export { RequestHandler } from './handlers/RequestHandler'
|
|
7
7
|
export { http } from './http'
|
|
8
8
|
export { HttpHandler, HttpMethods } from './handlers/HttpHandler'
|
|
9
9
|
export { graphql } from './graphql'
|
|
10
10
|
export { GraphQLHandler } from './handlers/GraphQLHandler'
|
|
11
11
|
|
|
12
|
-
/* WebSocket handler */
|
|
13
|
-
export { ws, type WebSocketLink } from './ws'
|
|
14
|
-
export {
|
|
15
|
-
WebSocketHandler,
|
|
16
|
-
type WebSocketHandlerEventMap,
|
|
17
|
-
} from './handlers/WebSocketHandler'
|
|
18
|
-
|
|
19
12
|
/* Utils */
|
|
20
13
|
export { matchRequestUrl } from './utils/matching/matchRequestUrl'
|
|
21
14
|
export * from './utils/handleRequest'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RequestHandler,
|
|
3
|
-
|
|
3
|
+
RequestHandlerExecutionResult,
|
|
4
4
|
} from '../handlers/RequestHandler'
|
|
5
5
|
|
|
6
6
|
export interface HandlersExecutionResult {
|
|
@@ -18,7 +18,7 @@ export interface ResponseResolutionContext {
|
|
|
18
18
|
* Returns the execution result object containing any matching request
|
|
19
19
|
* handler and any mocked response it returned.
|
|
20
20
|
*/
|
|
21
|
-
export const executeHandlers = async <Handlers extends Array<
|
|
21
|
+
export const executeHandlers = async <Handlers extends Array<RequestHandler>>({
|
|
22
22
|
request,
|
|
23
23
|
requestId,
|
|
24
24
|
handlers,
|
|
@@ -33,10 +33,6 @@ export const executeHandlers = async <Handlers extends Array<unknown>>({
|
|
|
33
33
|
let result: RequestHandlerExecutionResult<any> | null = null
|
|
34
34
|
|
|
35
35
|
for (const handler of handlers) {
|
|
36
|
-
if (!(handler instanceof RequestHandler)) {
|
|
37
|
-
continue
|
|
38
|
-
}
|
|
39
|
-
|
|
40
36
|
result = await handler.run({ request, requestId, resolutionContext })
|
|
41
37
|
|
|
42
38
|
// If the handler produces some result for this request,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { until } from '@open-draft/until'
|
|
2
2
|
import { Emitter } from 'strict-event-emitter'
|
|
3
|
+
import { RequestHandler } from '../handlers/RequestHandler'
|
|
3
4
|
import { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'
|
|
4
5
|
import { RequiredDeep } from '../typeUtils'
|
|
5
6
|
import { HandlersExecutionResult, executeHandlers } from './executeHandlers'
|
|
@@ -44,7 +45,7 @@ export interface HandleRequestOptions {
|
|
|
44
45
|
export async function handleRequest(
|
|
45
46
|
request: Request,
|
|
46
47
|
requestId: string,
|
|
47
|
-
handlers: Array<
|
|
48
|
+
handlers: Array<RequestHandler>,
|
|
48
49
|
options: RequiredDeep<SharedOptions>,
|
|
49
50
|
emitter: Emitter<LifeCycleEventsMap>,
|
|
50
51
|
handleRequestOptions?: HandleRequestOptions,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
export type DisposableSubscription = () =>
|
|
1
|
+
export type DisposableSubscription = () => void
|
|
2
2
|
|
|
3
3
|
export class Disposable {
|
|
4
4
|
protected subscriptions: Array<DisposableSubscription> = []
|
|
5
5
|
|
|
6
|
-
public
|
|
7
|
-
|
|
6
|
+
public dispose() {
|
|
7
|
+
let subscription: DisposableSubscription | undefined
|
|
8
|
+
while ((subscription = this.subscriptions.shift())) {
|
|
9
|
+
subscription()
|
|
10
|
+
}
|
|
8
11
|
}
|
|
9
12
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InternalError } from './devUtils'
|
|
2
|
+
|
|
3
|
+
describe(InternalError, () => {
|
|
4
|
+
it('creates an InternalError instance', () => {
|
|
5
|
+
const error = new InternalError('Message')
|
|
6
|
+
|
|
7
|
+
expect(error.name).toBe('InternalError')
|
|
8
|
+
expect(error.message).toBe('Message')
|
|
9
|
+
expect(error.toString()).toBe('InternalError: Message')
|
|
10
|
+
expect(error.stack).toMatch(/\w+/)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('passes the identity check', () => {
|
|
14
|
+
const error = new InternalError('Message')
|
|
15
|
+
expect(error instanceof InternalError).toBe(true)
|
|
16
|
+
expect(error instanceof Error).toBe(true)
|
|
17
|
+
|
|
18
|
+
const extraneousError = new Error('Message')
|
|
19
|
+
expect(extraneousError).not.toBeInstanceOf(InternalError)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
@@ -29,3 +29,16 @@ export const devUtils = {
|
|
|
29
29
|
warn,
|
|
30
30
|
error,
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Internal error instance.
|
|
35
|
+
* Used to differentiate the library errors that must be forwarded
|
|
36
|
+
* to the user from the unhandled exceptions. Use this if you don't
|
|
37
|
+
* wish for the error to be coerced to a 500 fallback response.
|
|
38
|
+
*/
|
|
39
|
+
export class InternalError extends Error {
|
|
40
|
+
constructor(message: string) {
|
|
41
|
+
super(message)
|
|
42
|
+
this.name = 'InternalError'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,32 +1,18 @@
|
|
|
1
1
|
import { getTimestamp } from './getTimestamp'
|
|
2
2
|
|
|
3
3
|
beforeAll(() => {
|
|
4
|
-
|
|
4
|
+
// Stub native `Date` prototype methods used in the tested module,
|
|
5
|
+
// to always produce a predictable value for testing purposes.
|
|
6
|
+
vi.spyOn(global.Date.prototype, 'getHours').mockImplementation(() => 12)
|
|
7
|
+
vi.spyOn(global.Date.prototype, 'getMinutes').mockImplementation(() => 4)
|
|
8
|
+
vi.spyOn(global.Date.prototype, 'getSeconds').mockImplementation(() => 8)
|
|
5
9
|
})
|
|
6
10
|
|
|
7
11
|
afterAll(() => {
|
|
8
|
-
vi.
|
|
12
|
+
vi.restoreAllMocks()
|
|
9
13
|
})
|
|
10
14
|
|
|
11
15
|
test('returns a timestamp string of the invocation time', () => {
|
|
12
|
-
vi.setSystemTime(new Date('2024-01-01 12:4:8'))
|
|
13
16
|
const timestamp = getTimestamp()
|
|
14
17
|
expect(timestamp).toBe('12:04:08')
|
|
15
18
|
})
|
|
16
|
-
|
|
17
|
-
test('returns a timestamp with milliseconds', () => {
|
|
18
|
-
vi.setSystemTime(new Date('2024-01-01 12:4:8'))
|
|
19
|
-
expect(getTimestamp({ milliseconds: true })).toBe('12:04:08.000')
|
|
20
|
-
|
|
21
|
-
vi.setSystemTime(new Date('2024-01-01 12:4:8.000'))
|
|
22
|
-
expect(getTimestamp({ milliseconds: true })).toBe('12:04:08.000')
|
|
23
|
-
|
|
24
|
-
vi.setSystemTime(new Date('2024-01-01 12:4:8.4'))
|
|
25
|
-
expect(getTimestamp({ milliseconds: true })).toBe('12:04:08.400')
|
|
26
|
-
|
|
27
|
-
vi.setSystemTime(new Date('2024-01-01 12:4:8.123'))
|
|
28
|
-
expect(getTimestamp({ milliseconds: true })).toBe('12:04:08.123')
|
|
29
|
-
|
|
30
|
-
vi.setSystemTime(new Date('2024-01-01 12:00:00'))
|
|
31
|
-
expect(getTimestamp({ milliseconds: true })).toBe('12:00:00.000')
|
|
32
|
-
})
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
interface GetTimestampOptions {
|
|
2
|
-
milliseconds?: boolean
|
|
3
|
-
}
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* Returns a timestamp string in a "HH:MM:SS" format.
|
|
7
3
|
*/
|
|
8
|
-
export function getTimestamp(
|
|
4
|
+
export function getTimestamp(): string {
|
|
9
5
|
const now = new Date()
|
|
10
|
-
const timestamp = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`
|
|
11
|
-
|
|
12
|
-
if (options?.milliseconds) {
|
|
13
|
-
return `${timestamp}.${now.getMilliseconds().toString().padStart(3, '0')}`
|
|
14
|
-
}
|
|
15
6
|
|
|
16
|
-
return
|
|
7
|
+
return [now.getHours(), now.getMinutes(), now.getSeconds()]
|
|
8
|
+
.map(String)
|
|
9
|
+
.map((chunk) => chunk.slice(0, 2))
|
|
10
|
+
.map((chunk) => chunk.padStart(2, '0'))
|
|
11
|
+
.join(':')
|
|
17
12
|
}
|
|
@@ -61,50 +61,6 @@ describe('matchRequestUrl', () => {
|
|
|
61
61
|
expect(match).toHaveProperty('matches', false)
|
|
62
62
|
expect(match).toHaveProperty('params', {})
|
|
63
63
|
})
|
|
64
|
-
|
|
65
|
-
test('returns true for matching WebSocket URL', () => {
|
|
66
|
-
expect(
|
|
67
|
-
matchRequestUrl(new URL('ws://test.mswjs.io'), 'ws://test.mswjs.io'),
|
|
68
|
-
).toEqual({
|
|
69
|
-
matches: true,
|
|
70
|
-
params: {},
|
|
71
|
-
})
|
|
72
|
-
expect(
|
|
73
|
-
matchRequestUrl(new URL('wss://test.mswjs.io'), 'wss://test.mswjs.io'),
|
|
74
|
-
).toEqual({
|
|
75
|
-
matches: true,
|
|
76
|
-
params: {},
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test('returns false for non-matching WebSocket URL', () => {
|
|
81
|
-
expect(
|
|
82
|
-
matchRequestUrl(new URL('ws://test.mswjs.io'), 'ws://foo.mswjs.io'),
|
|
83
|
-
).toEqual({
|
|
84
|
-
matches: false,
|
|
85
|
-
params: {},
|
|
86
|
-
})
|
|
87
|
-
expect(
|
|
88
|
-
matchRequestUrl(new URL('wss://test.mswjs.io'), 'wss://completely.diff'),
|
|
89
|
-
).toEqual({
|
|
90
|
-
matches: false,
|
|
91
|
-
params: {},
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test('returns path parameters when matched a WebSocket URL', () => {
|
|
96
|
-
expect(
|
|
97
|
-
matchRequestUrl(
|
|
98
|
-
new URL('wss://test.mswjs.io'),
|
|
99
|
-
'wss://:service.mswjs.io',
|
|
100
|
-
),
|
|
101
|
-
).toEqual({
|
|
102
|
-
matches: true,
|
|
103
|
-
params: {
|
|
104
|
-
service: 'test',
|
|
105
|
-
},
|
|
106
|
-
})
|
|
107
|
-
})
|
|
108
64
|
})
|
|
109
65
|
|
|
110
66
|
describe('coercePath', () => {
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
} from './onUnhandledRequest'
|
|
8
8
|
|
|
9
9
|
const fixtures = {
|
|
10
|
-
warningWithoutSuggestions: `\
|
|
10
|
+
warningWithoutSuggestions: (url = `/api`) => `\
|
|
11
11
|
[MSW] Warning: intercepted a request without a matching request handler:
|
|
12
12
|
|
|
13
|
-
• GET
|
|
13
|
+
• GET ${url}
|
|
14
14
|
|
|
15
15
|
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
16
16
|
Read more: https://mswjs.io/docs/getting-started/mocks`,
|
|
@@ -46,7 +46,9 @@ test('supports the "bypass" request strategy', async () => {
|
|
|
46
46
|
test('supports the "warn" request strategy', async () => {
|
|
47
47
|
await onUnhandledRequest(new Request(new URL('http://localhost/api')), 'warn')
|
|
48
48
|
|
|
49
|
-
expect(console.warn).toHaveBeenCalledWith(
|
|
49
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
50
|
+
fixtures.warningWithoutSuggestions(),
|
|
51
|
+
)
|
|
50
52
|
})
|
|
51
53
|
|
|
52
54
|
test('supports the "error" request strategy', async () => {
|
|
@@ -103,7 +105,9 @@ test('supports calling default strategies from the custom callback function', as
|
|
|
103
105
|
test('does not print any suggestions given no handlers to suggest', async () => {
|
|
104
106
|
await onUnhandledRequest(new Request(new URL('http://localhost/api')), 'warn')
|
|
105
107
|
|
|
106
|
-
expect(console.warn).toHaveBeenCalledWith(
|
|
108
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
109
|
+
fixtures.warningWithoutSuggestions(),
|
|
110
|
+
)
|
|
107
111
|
})
|
|
108
112
|
|
|
109
113
|
test('throws an exception given unknown request strategy', async () => {
|
|
@@ -117,3 +121,25 @@ test('throws an exception given unknown request strategy', async () => {
|
|
|
117
121
|
'[MSW] Failed to react to an unhandled request: unknown strategy "invalid-strategy". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.',
|
|
118
122
|
)
|
|
119
123
|
})
|
|
124
|
+
|
|
125
|
+
test('prints with a relative URL and search params', async () => {
|
|
126
|
+
await onUnhandledRequest(
|
|
127
|
+
new Request(new URL('http://localhost/api?foo=boo')),
|
|
128
|
+
'warn',
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
132
|
+
fixtures.warningWithoutSuggestions(`/api?foo=boo`),
|
|
133
|
+
)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('prints with an absolute URL and search params', async () => {
|
|
137
|
+
await onUnhandledRequest(
|
|
138
|
+
new Request(new URL('https://mswjs.io/api?foo=boo')),
|
|
139
|
+
'warn',
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
143
|
+
fixtures.warningWithoutSuggestions(`https://mswjs.io/api?foo=boo`),
|
|
144
|
+
)
|
|
145
|
+
})
|