msw 2.3.0-ws.rc-6 → 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 -83
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +156 -83
- 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 -1103
- 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/browser/setupWorker/stop/createStop.ts +0 -4
- 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 -58
- package/lib/core/ws/WebSocketClientManager.d.ts +0 -58
- package/lib/core/ws/WebSocketClientManager.js +0 -162
- package/lib/core/ws/WebSocketClientManager.js.map +0 -1
- package/lib/core/ws/WebSocketClientManager.mjs +0 -142
- 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 -65
- package/lib/core/ws.js.map +0 -1
- package/lib/core/ws.mjs +0 -48
- package/lib/core/ws.mjs.map +0 -1
- package/src/core/handlers/WebSocketHandler.ts +0 -71
- package/src/core/ws/WebSocketClientManager.test.ts +0 -157
- package/src/core/ws/WebSocketClientManager.ts +0 -234
- 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 -124
|
@@ -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
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toPublicUrl } from './toPublicUrl'
|
|
2
|
-
import { devUtils } from '../internal/devUtils'
|
|
2
|
+
import { InternalError, devUtils } from '../internal/devUtils'
|
|
3
3
|
|
|
4
4
|
export interface UnhandledRequestPrint {
|
|
5
5
|
warning(): void
|
|
@@ -22,7 +22,7 @@ export async function onUnhandledRequest(
|
|
|
22
22
|
strategy: UnhandledRequestStrategy = 'warn',
|
|
23
23
|
): Promise<void> {
|
|
24
24
|
const url = new URL(request.url)
|
|
25
|
-
const publicUrl = toPublicUrl(url)
|
|
25
|
+
const publicUrl = toPublicUrl(url) + url.search
|
|
26
26
|
|
|
27
27
|
const unhandledRequestMessage = `intercepted a request without a matching request handler:\n\n \u2022 ${request.method} ${publicUrl}\n\nIf you still wish to intercept this unhandled request, please create a request handler for it.\nRead more: https://mswjs.io/docs/getting-started/mocks`
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ export async function onUnhandledRequest(
|
|
|
33
33
|
devUtils.error('Error: %s', unhandledRequestMessage)
|
|
34
34
|
|
|
35
35
|
// Throw an exception to halt request processing and not perform the original request.
|
|
36
|
-
throw new
|
|
36
|
+
throw new InternalError(
|
|
37
37
|
devUtils.formatMessage(
|
|
38
38
|
'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.',
|
|
39
39
|
),
|
|
@@ -49,7 +49,7 @@ export async function onUnhandledRequest(
|
|
|
49
49
|
break
|
|
50
50
|
|
|
51
51
|
default:
|
|
52
|
-
throw new
|
|
52
|
+
throw new InternalError(
|
|
53
53
|
devUtils.formatMessage(
|
|
54
54
|
'Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.',
|
|
55
55
|
strategy,
|
|
@@ -4,15 +4,14 @@ import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'
|
|
|
4
4
|
import { FetchInterceptor } from '@mswjs/interceptors/fetch'
|
|
5
5
|
import { HandlersController } from '~/core/SetupApi'
|
|
6
6
|
import type { RequestHandler } from '~/core/handlers/RequestHandler'
|
|
7
|
-
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
|
|
8
7
|
import type { SetupServer } from './glossary'
|
|
9
8
|
import { SetupServerCommonApi } from './SetupServerCommonApi'
|
|
10
9
|
|
|
11
10
|
const store = new AsyncLocalStorage<RequestHandlersContext>()
|
|
12
11
|
|
|
13
12
|
type RequestHandlersContext = {
|
|
14
|
-
initialHandlers: Array<RequestHandler
|
|
15
|
-
handlers: Array<RequestHandler
|
|
13
|
+
initialHandlers: Array<RequestHandler>
|
|
14
|
+
handlers: Array<RequestHandler>
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -23,7 +22,7 @@ type RequestHandlersContext = {
|
|
|
23
22
|
class AsyncHandlersController implements HandlersController {
|
|
24
23
|
private rootContext: RequestHandlersContext
|
|
25
24
|
|
|
26
|
-
constructor(initialHandlers: Array<RequestHandler
|
|
25
|
+
constructor(initialHandlers: Array<RequestHandler>) {
|
|
27
26
|
this.rootContext = { initialHandlers, handlers: [] }
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -31,18 +30,18 @@ class AsyncHandlersController implements HandlersController {
|
|
|
31
30
|
return store.getStore() || this.rootContext
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
public prepend(runtimeHandlers: Array<RequestHandler
|
|
33
|
+
public prepend(runtimeHandlers: Array<RequestHandler>) {
|
|
35
34
|
this.context.handlers.unshift(...runtimeHandlers)
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
public reset(nextHandlers: Array<RequestHandler
|
|
37
|
+
public reset(nextHandlers: Array<RequestHandler>) {
|
|
39
38
|
const context = this.context
|
|
40
39
|
context.handlers = []
|
|
41
40
|
context.initialHandlers =
|
|
42
41
|
nextHandlers.length > 0 ? nextHandlers : context.initialHandlers
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
public currentHandlers(): Array<RequestHandler
|
|
44
|
+
public currentHandlers(): Array<RequestHandler> {
|
|
46
45
|
const { initialHandlers, handlers } = this.context
|
|
47
46
|
return handlers.concat(initialHandlers)
|
|
48
47
|
}
|
|
@@ -52,7 +51,7 @@ export class SetupServerApi
|
|
|
52
51
|
extends SetupServerCommonApi
|
|
53
52
|
implements SetupServer
|
|
54
53
|
{
|
|
55
|
-
constructor(handlers: Array<RequestHandler
|
|
54
|
+
constructor(handlers: Array<RequestHandler>) {
|
|
56
55
|
super(
|
|
57
56
|
[ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],
|
|
58
57
|
handlers,
|
|
@@ -14,12 +14,9 @@ import type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'
|
|
|
14
14
|
import { SetupApi } from '~/core/SetupApi'
|
|
15
15
|
import { handleRequest } from '~/core/utils/handleRequest'
|
|
16
16
|
import type { RequestHandler } from '~/core/handlers/RequestHandler'
|
|
17
|
-
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
|
|
18
17
|
import { mergeRight } from '~/core/utils/internal/mergeRight'
|
|
19
|
-
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
18
|
+
import { InternalError, devUtils } from '~/core/utils/internal/devUtils'
|
|
20
19
|
import type { SetupServerCommon } from './glossary'
|
|
21
|
-
import { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'
|
|
22
|
-
import { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'
|
|
23
20
|
|
|
24
21
|
export const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {
|
|
25
22
|
onUnhandledRequest: 'warn',
|
|
@@ -37,7 +34,7 @@ export class SetupServerCommonApi
|
|
|
37
34
|
|
|
38
35
|
constructor(
|
|
39
36
|
interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,
|
|
40
|
-
handlers: Array<RequestHandler
|
|
37
|
+
handlers: Array<RequestHandler>,
|
|
41
38
|
) {
|
|
42
39
|
super(...handlers)
|
|
43
40
|
|
|
@@ -71,6 +68,12 @@ export class SetupServerCommonApi
|
|
|
71
68
|
return
|
|
72
69
|
})
|
|
73
70
|
|
|
71
|
+
this.interceptor.on('unhandledException', ({ error }) => {
|
|
72
|
+
if (error instanceof InternalError) {
|
|
73
|
+
throw error
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
74
77
|
this.interceptor.on(
|
|
75
78
|
'response',
|
|
76
79
|
({ response, isMockedResponse, request, requestId }) => {
|
|
@@ -84,14 +87,6 @@ export class SetupServerCommonApi
|
|
|
84
87
|
)
|
|
85
88
|
},
|
|
86
89
|
)
|
|
87
|
-
|
|
88
|
-
handleWebSocketEvent({
|
|
89
|
-
getHandlers: () => {
|
|
90
|
-
return this.handlersController.currentHandlers()
|
|
91
|
-
},
|
|
92
|
-
onMockedConnection: () => {},
|
|
93
|
-
onPassthroughConnection: () => {},
|
|
94
|
-
})
|
|
95
90
|
}
|
|
96
91
|
|
|
97
92
|
public listen(options: Partial<SharedOptions> = {}): void {
|
|
@@ -102,11 +97,9 @@ export class SetupServerCommonApi
|
|
|
102
97
|
|
|
103
98
|
// Apply the interceptor when starting the server.
|
|
104
99
|
this.interceptor.apply()
|
|
105
|
-
webSocketInterceptor.apply()
|
|
106
100
|
|
|
107
101
|
this.subscriptions.push(() => {
|
|
108
102
|
this.interceptor.dispose()
|
|
109
|
-
webSocketInterceptor.dispose()
|
|
110
103
|
})
|
|
111
104
|
|
|
112
105
|
// Assert that the interceptor has been applied successfully.
|
package/src/node/glossary.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PartialDeep } from 'type-fest'
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
RequestHandler,
|
|
4
|
+
RequestHandlerDefaultInfo,
|
|
5
|
+
} from '~/core/handlers/RequestHandler'
|
|
4
6
|
import type {
|
|
5
7
|
LifeCycleEventEmitter,
|
|
6
8
|
LifeCycleEventsMap,
|
|
@@ -27,7 +29,7 @@ export interface SetupServerCommon {
|
|
|
27
29
|
*
|
|
28
30
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
29
31
|
*/
|
|
30
|
-
use(...handlers: Array<RequestHandler
|
|
32
|
+
use(...handlers: Array<RequestHandler>): void
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
@@ -41,14 +43,14 @@ export interface SetupServerCommon {
|
|
|
41
43
|
*
|
|
42
44
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
43
45
|
*/
|
|
44
|
-
resetHandlers(...nextHandlers: Array<RequestHandler
|
|
46
|
+
resetHandlers(...nextHandlers: Array<RequestHandler>): void
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
49
|
* Returns a readonly list of currently active request handlers.
|
|
48
50
|
*
|
|
49
51
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
50
52
|
*/
|
|
51
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
53
|
+
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* Life-cycle events.
|
package/src/node/setupServer.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { RequestHandler } from '~/core/handlers/RequestHandler'
|
|
2
|
-
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
|
|
3
2
|
import { SetupServerApi } from './SetupServerApi'
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -9,7 +8,7 @@ import { SetupServerApi } from './SetupServerApi'
|
|
|
9
8
|
* @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}
|
|
10
9
|
*/
|
|
11
10
|
export const setupServer = (
|
|
12
|
-
...handlers: Array<RequestHandler
|
|
11
|
+
...handlers: Array<RequestHandler>
|
|
13
12
|
): SetupServerApi => {
|
|
14
13
|
return new SetupServerApi(handlers)
|
|
15
14
|
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
3
|
-
import { PathParams, Path, Match } from '../utils/matching/matchRequestUrl.mjs';
|
|
4
|
-
|
|
5
|
-
type WebSocketHandlerParsedResult = {
|
|
6
|
-
match: Match;
|
|
7
|
-
};
|
|
8
|
-
type WebSocketHandlerEventMap = {
|
|
9
|
-
connection: [args: WebSocketHandlerConnection];
|
|
10
|
-
};
|
|
11
|
-
interface WebSocketHandlerConnection extends WebSocketConnectionData {
|
|
12
|
-
params: PathParams;
|
|
13
|
-
}
|
|
14
|
-
declare const kEmitter: unique symbol;
|
|
15
|
-
declare const kDispatchEvent: unique symbol;
|
|
16
|
-
declare const kSender: unique symbol;
|
|
17
|
-
declare class WebSocketHandler {
|
|
18
|
-
private readonly url;
|
|
19
|
-
callFrame?: string;
|
|
20
|
-
protected [kEmitter]: Emitter<WebSocketHandlerEventMap>;
|
|
21
|
-
constructor(url: Path);
|
|
22
|
-
parse(args: {
|
|
23
|
-
event: MessageEvent<WebSocketConnectionData>;
|
|
24
|
-
}): WebSocketHandlerParsedResult;
|
|
25
|
-
predicate(args: {
|
|
26
|
-
event: MessageEvent<WebSocketConnectionData>;
|
|
27
|
-
parsedResult: WebSocketHandlerParsedResult;
|
|
28
|
-
}): boolean;
|
|
29
|
-
[kDispatchEvent](event: MessageEvent<WebSocketConnectionData>): Promise<void>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { WebSocketHandler, type WebSocketHandlerEventMap, kDispatchEvent, kEmitter, kSender };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
3
|
-
import { PathParams, Path, Match } from '../utils/matching/matchRequestUrl.js';
|
|
4
|
-
|
|
5
|
-
type WebSocketHandlerParsedResult = {
|
|
6
|
-
match: Match;
|
|
7
|
-
};
|
|
8
|
-
type WebSocketHandlerEventMap = {
|
|
9
|
-
connection: [args: WebSocketHandlerConnection];
|
|
10
|
-
};
|
|
11
|
-
interface WebSocketHandlerConnection extends WebSocketConnectionData {
|
|
12
|
-
params: PathParams;
|
|
13
|
-
}
|
|
14
|
-
declare const kEmitter: unique symbol;
|
|
15
|
-
declare const kDispatchEvent: unique symbol;
|
|
16
|
-
declare const kSender: unique symbol;
|
|
17
|
-
declare class WebSocketHandler {
|
|
18
|
-
private readonly url;
|
|
19
|
-
callFrame?: string;
|
|
20
|
-
protected [kEmitter]: Emitter<WebSocketHandlerEventMap>;
|
|
21
|
-
constructor(url: Path);
|
|
22
|
-
parse(args: {
|
|
23
|
-
event: MessageEvent<WebSocketConnectionData>;
|
|
24
|
-
}): WebSocketHandlerParsedResult;
|
|
25
|
-
predicate(args: {
|
|
26
|
-
event: MessageEvent<WebSocketConnectionData>;
|
|
27
|
-
parsedResult: WebSocketHandlerParsedResult;
|
|
28
|
-
}): boolean;
|
|
29
|
-
[kDispatchEvent](event: MessageEvent<WebSocketConnectionData>): Promise<void>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { WebSocketHandler, type WebSocketHandlerEventMap, kDispatchEvent, kEmitter, kSender };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var WebSocketHandler_exports = {};
|
|
20
|
-
__export(WebSocketHandler_exports, {
|
|
21
|
-
WebSocketHandler: () => WebSocketHandler,
|
|
22
|
-
kDispatchEvent: () => kDispatchEvent,
|
|
23
|
-
kEmitter: () => kEmitter,
|
|
24
|
-
kSender: () => kSender
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(WebSocketHandler_exports);
|
|
27
|
-
var import_strict_event_emitter = require("strict-event-emitter");
|
|
28
|
-
var import_matchRequestUrl = require("../utils/matching/matchRequestUrl.js");
|
|
29
|
-
var import_getCallFrame = require("../utils/internal/getCallFrame.js");
|
|
30
|
-
const kEmitter = Symbol("kEmitter");
|
|
31
|
-
const kDispatchEvent = Symbol("kDispatchEvent");
|
|
32
|
-
const kSender = Symbol("kSender");
|
|
33
|
-
class WebSocketHandler {
|
|
34
|
-
constructor(url) {
|
|
35
|
-
this.url = url;
|
|
36
|
-
this[kEmitter] = new import_strict_event_emitter.Emitter();
|
|
37
|
-
this.callFrame = (0, import_getCallFrame.getCallFrame)(new Error());
|
|
38
|
-
}
|
|
39
|
-
callFrame;
|
|
40
|
-
[kEmitter];
|
|
41
|
-
parse(args) {
|
|
42
|
-
const connection = args.event.data;
|
|
43
|
-
const match = (0, import_matchRequestUrl.matchRequestUrl)(connection.client.url, this.url);
|
|
44
|
-
return {
|
|
45
|
-
match
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
predicate(args) {
|
|
49
|
-
return args.parsedResult.match.matches;
|
|
50
|
-
}
|
|
51
|
-
async [kDispatchEvent](event) {
|
|
52
|
-
const parsedResult = this.parse({ event });
|
|
53
|
-
const connection = event.data;
|
|
54
|
-
const resolvedConnection = {
|
|
55
|
-
client: connection.client,
|
|
56
|
-
server: connection.server,
|
|
57
|
-
params: parsedResult.match.params || {}
|
|
58
|
-
};
|
|
59
|
-
this[kEmitter].emit("connection", resolvedConnection);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=WebSocketHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/handlers/WebSocketHandler.ts"],"sourcesContent":["import { Emitter } from 'strict-event-emitter'\nimport type { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'\nimport {\n type Match,\n type Path,\n type PathParams,\n matchRequestUrl,\n} from '../utils/matching/matchRequestUrl'\nimport { getCallFrame } from '../utils/internal/getCallFrame'\n\ntype WebSocketHandlerParsedResult = {\n match: Match\n}\n\nexport type WebSocketHandlerEventMap = {\n connection: [args: WebSocketHandlerConnection]\n}\n\ninterface WebSocketHandlerConnection extends WebSocketConnectionData {\n params: PathParams\n}\n\nexport const kEmitter = Symbol('kEmitter')\nexport const kDispatchEvent = Symbol('kDispatchEvent')\nexport const kSender = Symbol('kSender')\n\nexport class WebSocketHandler {\n public callFrame?: string\n\n protected [kEmitter]: Emitter<WebSocketHandlerEventMap>\n\n constructor(private readonly url: Path) {\n this[kEmitter] = new Emitter()\n this.callFrame = getCallFrame(new Error())\n }\n\n public parse(args: {\n event: MessageEvent<WebSocketConnectionData>\n }): WebSocketHandlerParsedResult {\n const connection = args.event.data\n const match = matchRequestUrl(connection.client.url, this.url)\n\n return {\n match,\n }\n }\n\n public predicate(args: {\n event: MessageEvent<WebSocketConnectionData>\n parsedResult: WebSocketHandlerParsedResult\n }): boolean {\n return args.parsedResult.match.matches\n }\n\n async [kDispatchEvent](\n event: MessageEvent<WebSocketConnectionData>,\n ): Promise<void> {\n const parsedResult = this.parse({ event })\n const connection = event.data\n\n const resolvedConnection: WebSocketHandlerConnection = {\n client: connection.client,\n server: connection.server,\n params: parsedResult.match.params || {},\n }\n\n // Emit the connection event on the handler.\n // This is what the developer adds listeners for.\n this[kEmitter].emit('connection', resolvedConnection)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAwB;AAExB,6BAKO;AACP,0BAA6B;AActB,MAAM,WAAW,OAAO,UAAU;AAClC,MAAM,iBAAiB,OAAO,gBAAgB;AAC9C,MAAM,UAAU,OAAO,SAAS;AAEhC,MAAM,iBAAiB;AAAA,EAK5B,YAA6B,KAAW;AAAX;AAC3B,SAAK,QAAQ,IAAI,IAAI,oCAAQ;AAC7B,SAAK,gBAAY,kCAAa,IAAI,MAAM,CAAC;AAAA,EAC3C;AAAA,EAPO;AAAA,EAEP,CAAW,QAAQ;AAAA,EAOZ,MAAM,MAEoB;AAC/B,UAAM,aAAa,KAAK,MAAM;AAC9B,UAAM,YAAQ,wCAAgB,WAAW,OAAO,KAAK,KAAK,GAAG;AAE7D,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEO,UAAU,MAGL;AACV,WAAO,KAAK,aAAa,MAAM;AAAA,EACjC;AAAA,EAEA,OAAO,cAAc,EACnB,OACe;AACf,UAAM,eAAe,KAAK,MAAM,EAAE,MAAM,CAAC;AACzC,UAAM,aAAa,MAAM;AAEzB,UAAM,qBAAiD;AAAA,MACrD,QAAQ,WAAW;AAAA,MACnB,QAAQ,WAAW;AAAA,MACnB,QAAQ,aAAa,MAAM,UAAU,CAAC;AAAA,IACxC;AAIA,SAAK,QAAQ,EAAE,KAAK,cAAc,kBAAkB;AAAA,EACtD;AACF;","names":[]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Emitter } from "strict-event-emitter";
|
|
2
|
-
import {
|
|
3
|
-
matchRequestUrl
|
|
4
|
-
} from '../utils/matching/matchRequestUrl.mjs';
|
|
5
|
-
import { getCallFrame } from '../utils/internal/getCallFrame.mjs';
|
|
6
|
-
const kEmitter = Symbol("kEmitter");
|
|
7
|
-
const kDispatchEvent = Symbol("kDispatchEvent");
|
|
8
|
-
const kSender = Symbol("kSender");
|
|
9
|
-
class WebSocketHandler {
|
|
10
|
-
constructor(url) {
|
|
11
|
-
this.url = url;
|
|
12
|
-
this[kEmitter] = new Emitter();
|
|
13
|
-
this.callFrame = getCallFrame(new Error());
|
|
14
|
-
}
|
|
15
|
-
callFrame;
|
|
16
|
-
[kEmitter];
|
|
17
|
-
parse(args) {
|
|
18
|
-
const connection = args.event.data;
|
|
19
|
-
const match = matchRequestUrl(connection.client.url, this.url);
|
|
20
|
-
return {
|
|
21
|
-
match
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
predicate(args) {
|
|
25
|
-
return args.parsedResult.match.matches;
|
|
26
|
-
}
|
|
27
|
-
async [kDispatchEvent](event) {
|
|
28
|
-
const parsedResult = this.parse({ event });
|
|
29
|
-
const connection = event.data;
|
|
30
|
-
const resolvedConnection = {
|
|
31
|
-
client: connection.client,
|
|
32
|
-
server: connection.server,
|
|
33
|
-
params: parsedResult.match.params || {}
|
|
34
|
-
};
|
|
35
|
-
this[kEmitter].emit("connection", resolvedConnection);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export {
|
|
39
|
-
WebSocketHandler,
|
|
40
|
-
kDispatchEvent,
|
|
41
|
-
kEmitter,
|
|
42
|
-
kSender
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=WebSocketHandler.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/handlers/WebSocketHandler.ts"],"sourcesContent":["import { Emitter } from 'strict-event-emitter'\nimport type { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'\nimport {\n type Match,\n type Path,\n type PathParams,\n matchRequestUrl,\n} from '../utils/matching/matchRequestUrl'\nimport { getCallFrame } from '../utils/internal/getCallFrame'\n\ntype WebSocketHandlerParsedResult = {\n match: Match\n}\n\nexport type WebSocketHandlerEventMap = {\n connection: [args: WebSocketHandlerConnection]\n}\n\ninterface WebSocketHandlerConnection extends WebSocketConnectionData {\n params: PathParams\n}\n\nexport const kEmitter = Symbol('kEmitter')\nexport const kDispatchEvent = Symbol('kDispatchEvent')\nexport const kSender = Symbol('kSender')\n\nexport class WebSocketHandler {\n public callFrame?: string\n\n protected [kEmitter]: Emitter<WebSocketHandlerEventMap>\n\n constructor(private readonly url: Path) {\n this[kEmitter] = new Emitter()\n this.callFrame = getCallFrame(new Error())\n }\n\n public parse(args: {\n event: MessageEvent<WebSocketConnectionData>\n }): WebSocketHandlerParsedResult {\n const connection = args.event.data\n const match = matchRequestUrl(connection.client.url, this.url)\n\n return {\n match,\n }\n }\n\n public predicate(args: {\n event: MessageEvent<WebSocketConnectionData>\n parsedResult: WebSocketHandlerParsedResult\n }): boolean {\n return args.parsedResult.match.matches\n }\n\n async [kDispatchEvent](\n event: MessageEvent<WebSocketConnectionData>,\n ): Promise<void> {\n const parsedResult = this.parse({ event })\n const connection = event.data\n\n const resolvedConnection: WebSocketHandlerConnection = {\n client: connection.client,\n server: connection.server,\n params: parsedResult.match.params || {},\n }\n\n // Emit the connection event on the handler.\n // This is what the developer adds listeners for.\n this[kEmitter].emit('connection', resolvedConnection)\n }\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAExB;AAAA,EAIE;AAAA,OACK;AACP,SAAS,oBAAoB;AActB,MAAM,WAAW,OAAO,UAAU;AAClC,MAAM,iBAAiB,OAAO,gBAAgB;AAC9C,MAAM,UAAU,OAAO,SAAS;AAEhC,MAAM,iBAAiB;AAAA,EAK5B,YAA6B,KAAW;AAAX;AAC3B,SAAK,QAAQ,IAAI,IAAI,QAAQ;AAC7B,SAAK,YAAY,aAAa,IAAI,MAAM,CAAC;AAAA,EAC3C;AAAA,EAPO;AAAA,EAEP,CAAW,QAAQ;AAAA,EAOZ,MAAM,MAEoB;AAC/B,UAAM,aAAa,KAAK,MAAM;AAC9B,UAAM,QAAQ,gBAAgB,WAAW,OAAO,KAAK,KAAK,GAAG;AAE7D,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEO,UAAU,MAGL;AACV,WAAO,KAAK,aAAa,MAAM;AAAA,EACjC;AAAA,EAEA,OAAO,cAAc,EACnB,OACe;AACf,UAAM,eAAe,KAAK,MAAM,EAAE,MAAM,CAAC;AACzC,UAAM,aAAa,MAAM;AAEzB,UAAM,qBAAiD;AAAA,MACrD,QAAQ,WAAW;AAAA,MACnB,QAAQ,WAAW;AAAA,MACnB,QAAQ,aAAa,MAAM,UAAU,CAAC;AAAA,IACxC;AAIA,SAAK,QAAQ,EAAE,KAAK,cAAc,kBAAkB;AAAA,EACtD;AACF;","names":[]}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { WebSocketData, WebSocketClientConnectionProtocol, WebSocketClientConnection } from '@mswjs/interceptors/WebSocket';
|
|
2
|
-
import { Path } from '../utils/matching/matchRequestUrl.mjs';
|
|
3
|
-
|
|
4
|
-
declare const MSW_WEBSOCKET_CLIENTS_KEY = "msw:ws:clients";
|
|
5
|
-
type WebSocketBroadcastChannelMessage = {
|
|
6
|
-
type: 'extraneous:send';
|
|
7
|
-
payload: {
|
|
8
|
-
clientId: string;
|
|
9
|
-
data: WebSocketData;
|
|
10
|
-
};
|
|
11
|
-
} | {
|
|
12
|
-
type: 'extraneous:close';
|
|
13
|
-
payload: {
|
|
14
|
-
clientId: string;
|
|
15
|
-
code?: number;
|
|
16
|
-
reason?: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* A manager responsible for accumulating WebSocket client
|
|
21
|
-
* connections across different browser runtimes.
|
|
22
|
-
*/
|
|
23
|
-
declare class WebSocketClientManager {
|
|
24
|
-
private channel;
|
|
25
|
-
private url;
|
|
26
|
-
private inMemoryClients;
|
|
27
|
-
constructor(channel: BroadcastChannel, url: Path);
|
|
28
|
-
/**
|
|
29
|
-
* All active WebSocket client connections.
|
|
30
|
-
*/
|
|
31
|
-
get clients(): Set<WebSocketClientConnectionProtocol>;
|
|
32
|
-
private getSerializedClients;
|
|
33
|
-
private addClient;
|
|
34
|
-
/**
|
|
35
|
-
* Adds the given `WebSocket` client connection to the set
|
|
36
|
-
* of all connections. The given connection is always the complete
|
|
37
|
-
* connection object because `addConnection()` is called only
|
|
38
|
-
* for the opened connections in the same runtime.
|
|
39
|
-
*/
|
|
40
|
-
addConnection(client: WebSocketClientConnection): void;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* A wrapper class to operate with WebSocket client connections
|
|
44
|
-
* from other runtimes. This class maintains 1-1 public API
|
|
45
|
-
* compatibility to the `WebSocketClientConnection` but relies
|
|
46
|
-
* on the given `BroadcastChannel` to communicate instructions
|
|
47
|
-
* with the client connections from other runtimes.
|
|
48
|
-
*/
|
|
49
|
-
declare class WebSocketRemoteClientConnection implements WebSocketClientConnectionProtocol {
|
|
50
|
-
readonly id: string;
|
|
51
|
-
readonly url: URL;
|
|
52
|
-
private channel;
|
|
53
|
-
constructor(id: string, url: URL, channel: BroadcastChannel);
|
|
54
|
-
send(data: WebSocketData): void;
|
|
55
|
-
close(code?: number | undefined, reason?: string | undefined): void;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { MSW_WEBSOCKET_CLIENTS_KEY, type WebSocketBroadcastChannelMessage, WebSocketClientManager, WebSocketRemoteClientConnection };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { WebSocketData, WebSocketClientConnectionProtocol, WebSocketClientConnection } from '@mswjs/interceptors/WebSocket';
|
|
2
|
-
import { Path } from '../utils/matching/matchRequestUrl.js';
|
|
3
|
-
|
|
4
|
-
declare const MSW_WEBSOCKET_CLIENTS_KEY = "msw:ws:clients";
|
|
5
|
-
type WebSocketBroadcastChannelMessage = {
|
|
6
|
-
type: 'extraneous:send';
|
|
7
|
-
payload: {
|
|
8
|
-
clientId: string;
|
|
9
|
-
data: WebSocketData;
|
|
10
|
-
};
|
|
11
|
-
} | {
|
|
12
|
-
type: 'extraneous:close';
|
|
13
|
-
payload: {
|
|
14
|
-
clientId: string;
|
|
15
|
-
code?: number;
|
|
16
|
-
reason?: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* A manager responsible for accumulating WebSocket client
|
|
21
|
-
* connections across different browser runtimes.
|
|
22
|
-
*/
|
|
23
|
-
declare class WebSocketClientManager {
|
|
24
|
-
private channel;
|
|
25
|
-
private url;
|
|
26
|
-
private inMemoryClients;
|
|
27
|
-
constructor(channel: BroadcastChannel, url: Path);
|
|
28
|
-
/**
|
|
29
|
-
* All active WebSocket client connections.
|
|
30
|
-
*/
|
|
31
|
-
get clients(): Set<WebSocketClientConnectionProtocol>;
|
|
32
|
-
private getSerializedClients;
|
|
33
|
-
private addClient;
|
|
34
|
-
/**
|
|
35
|
-
* Adds the given `WebSocket` client connection to the set
|
|
36
|
-
* of all connections. The given connection is always the complete
|
|
37
|
-
* connection object because `addConnection()` is called only
|
|
38
|
-
* for the opened connections in the same runtime.
|
|
39
|
-
*/
|
|
40
|
-
addConnection(client: WebSocketClientConnection): void;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* A wrapper class to operate with WebSocket client connections
|
|
44
|
-
* from other runtimes. This class maintains 1-1 public API
|
|
45
|
-
* compatibility to the `WebSocketClientConnection` but relies
|
|
46
|
-
* on the given `BroadcastChannel` to communicate instructions
|
|
47
|
-
* with the client connections from other runtimes.
|
|
48
|
-
*/
|
|
49
|
-
declare class WebSocketRemoteClientConnection implements WebSocketClientConnectionProtocol {
|
|
50
|
-
readonly id: string;
|
|
51
|
-
readonly url: URL;
|
|
52
|
-
private channel;
|
|
53
|
-
constructor(id: string, url: URL, channel: BroadcastChannel);
|
|
54
|
-
send(data: WebSocketData): void;
|
|
55
|
-
close(code?: number | undefined, reason?: string | undefined): void;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { MSW_WEBSOCKET_CLIENTS_KEY, type WebSocketBroadcastChannelMessage, WebSocketClientManager, WebSocketRemoteClientConnection };
|