msw 2.3.0-ws.rc-6 → 2.3.1

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.
Files changed (208) hide show
  1. package/README.md +3 -9
  2. package/cli/init.js +0 -0
  3. package/config/scripts/postinstall.js +0 -0
  4. package/lib/browser/index.d.mts +6 -7
  5. package/lib/browser/index.d.ts +6 -7
  6. package/lib/browser/index.js +156 -83
  7. package/lib/browser/index.js.map +1 -1
  8. package/lib/browser/index.mjs +156 -83
  9. package/lib/browser/index.mjs.map +1 -1
  10. package/lib/core/{GraphQLHandler-DGyzNtRQ.d.ts → GraphQLHandler-COiPfZ8k.d.ts} +1 -1
  11. package/lib/core/{GraphQLHandler-CzcXr7At.d.mts → GraphQLHandler-Dq_WRbKe.d.mts} +1 -1
  12. package/lib/core/{HttpResponse-BOzDwzB6.d.ts → HttpResponse-B07UKAkU.d.ts} +2 -2
  13. package/lib/core/{HttpResponse-CSyJ1cbO.d.mts → HttpResponse-C7niBMwb.d.mts} +2 -2
  14. package/lib/core/HttpResponse.d.mts +1 -1
  15. package/lib/core/HttpResponse.d.ts +1 -1
  16. package/lib/core/SetupApi.d.mts +12 -15
  17. package/lib/core/SetupApi.d.ts +12 -15
  18. package/lib/core/SetupApi.js +1 -3
  19. package/lib/core/SetupApi.js.map +1 -1
  20. package/lib/core/SetupApi.mjs +1 -3
  21. package/lib/core/SetupApi.mjs.map +1 -1
  22. package/lib/core/getResponse.d.mts +1 -1
  23. package/lib/core/getResponse.d.ts +1 -1
  24. package/lib/core/graphql.d.mts +2 -2
  25. package/lib/core/graphql.d.ts +2 -2
  26. package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
  27. package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
  28. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  29. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  30. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  31. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  32. package/lib/core/http.d.mts +1 -1
  33. package/lib/core/http.d.ts +1 -1
  34. package/lib/core/index.d.mts +2 -5
  35. package/lib/core/index.d.ts +2 -5
  36. package/lib/core/index.js +1 -5
  37. package/lib/core/index.js.map +1 -1
  38. package/lib/core/index.mjs +1 -7
  39. package/lib/core/index.mjs.map +1 -1
  40. package/lib/core/passthrough.d.mts +1 -1
  41. package/lib/core/passthrough.d.ts +1 -1
  42. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  43. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  44. package/lib/core/utils/executeHandlers.d.mts +1 -1
  45. package/lib/core/utils/executeHandlers.d.ts +1 -1
  46. package/lib/core/utils/executeHandlers.js +0 -4
  47. package/lib/core/utils/executeHandlers.js.map +1 -1
  48. package/lib/core/utils/executeHandlers.mjs +0 -6
  49. package/lib/core/utils/executeHandlers.mjs.map +1 -1
  50. package/lib/core/utils/handleRequest.d.mts +2 -2
  51. package/lib/core/utils/handleRequest.d.ts +2 -2
  52. package/lib/core/utils/handleRequest.js.map +1 -1
  53. package/lib/core/utils/handleRequest.mjs.map +1 -1
  54. package/lib/core/utils/internal/Disposable.d.mts +2 -2
  55. package/lib/core/utils/internal/Disposable.d.ts +2 -2
  56. package/lib/core/utils/internal/Disposable.js +5 -2
  57. package/lib/core/utils/internal/Disposable.js.map +1 -1
  58. package/lib/core/utils/internal/Disposable.mjs +5 -2
  59. package/lib/core/utils/internal/Disposable.mjs.map +1 -1
  60. package/lib/core/utils/internal/devUtils.d.mts +10 -1
  61. package/lib/core/utils/internal/devUtils.d.ts +10 -1
  62. package/lib/core/utils/internal/devUtils.js +7 -0
  63. package/lib/core/utils/internal/devUtils.js.map +1 -1
  64. package/lib/core/utils/internal/devUtils.mjs +7 -0
  65. package/lib/core/utils/internal/devUtils.mjs.map +1 -1
  66. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
  67. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
  68. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  69. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  70. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  71. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  72. package/lib/core/utils/logging/getTimestamp.d.mts +1 -4
  73. package/lib/core/utils/logging/getTimestamp.d.ts +1 -4
  74. package/lib/core/utils/logging/getTimestamp.js +2 -6
  75. package/lib/core/utils/logging/getTimestamp.js.map +1 -1
  76. package/lib/core/utils/logging/getTimestamp.mjs +2 -6
  77. package/lib/core/utils/logging/getTimestamp.mjs.map +1 -1
  78. package/lib/core/utils/matching/matchRequestUrl.d.mts +1 -2
  79. package/lib/core/utils/matching/matchRequestUrl.d.ts +1 -2
  80. package/lib/core/utils/matching/matchRequestUrl.js +0 -4
  81. package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
  82. package/lib/core/utils/matching/matchRequestUrl.mjs +0 -4
  83. package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
  84. package/lib/core/utils/matching/normalizePath.d.mts +1 -0
  85. package/lib/core/utils/matching/normalizePath.d.ts +1 -0
  86. package/lib/core/utils/matching/normalizePath.js.map +1 -1
  87. package/lib/core/utils/matching/normalizePath.mjs.map +1 -1
  88. package/lib/core/utils/request/onUnhandledRequest.js +3 -3
  89. package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
  90. package/lib/core/utils/request/onUnhandledRequest.mjs +4 -4
  91. package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
  92. package/lib/core/utils/url/cleanUrl.d.mts +2 -1
  93. package/lib/core/utils/url/cleanUrl.d.ts +2 -1
  94. package/lib/core/utils/url/cleanUrl.js +3 -0
  95. package/lib/core/utils/url/cleanUrl.js.map +1 -1
  96. package/lib/core/utils/url/cleanUrl.mjs +3 -0
  97. package/lib/core/utils/url/cleanUrl.mjs.map +1 -1
  98. package/lib/iife/index.js +180 -1103
  99. package/lib/iife/index.js.map +1 -1
  100. package/lib/mockServiceWorker.js +1 -1
  101. package/lib/native/index.d.mts +5 -6
  102. package/lib/native/index.d.ts +5 -6
  103. package/lib/native/index.js +5 -13
  104. package/lib/native/index.js.map +1 -1
  105. package/lib/native/index.mjs +6 -14
  106. package/lib/native/index.mjs.map +1 -1
  107. package/lib/node/index.d.mts +7 -8
  108. package/lib/node/index.d.ts +7 -8
  109. package/lib/node/index.js +5 -13
  110. package/lib/node/index.js.map +1 -1
  111. package/lib/node/index.mjs +6 -14
  112. package/lib/node/index.mjs.map +1 -1
  113. package/package.json +36 -29
  114. package/src/browser/setupWorker/glossary.ts +10 -10
  115. package/src/browser/setupWorker/setupWorker.ts +3 -34
  116. package/src/browser/setupWorker/stop/createStop.ts +0 -4
  117. package/src/core/SetupApi.ts +20 -28
  118. package/src/core/index.ts +1 -8
  119. package/src/core/utils/executeHandlers.ts +2 -6
  120. package/src/core/utils/handleRequest.ts +2 -1
  121. package/src/core/utils/internal/Disposable.ts +6 -3
  122. package/src/core/utils/internal/devUtils.test.ts +21 -0
  123. package/src/core/utils/internal/devUtils.ts +13 -0
  124. package/src/core/utils/logging/getTimestamp.test.ts +6 -20
  125. package/src/core/utils/logging/getTimestamp.ts +6 -11
  126. package/src/core/utils/matching/matchRequestUrl.test.ts +8 -41
  127. package/src/core/utils/matching/matchRequestUrl.ts +0 -4
  128. package/src/core/utils/matching/normalizePath.test.ts +7 -1
  129. package/src/core/utils/matching/normalizePath.ts +1 -0
  130. package/src/core/utils/request/onUnhandledRequest.test.ts +30 -4
  131. package/src/core/utils/request/onUnhandledRequest.ts +4 -4
  132. package/src/core/utils/url/cleanUrl.test.ts +8 -3
  133. package/src/core/utils/url/cleanUrl.ts +9 -1
  134. package/src/core/utils/url/getAbsoluteUrl.node.test.ts +3 -3
  135. package/src/core/utils/url/getAbsoluteUrl.test.ts +5 -5
  136. package/src/core/utils/url/isAbsoluteUrl.test.ts +7 -7
  137. package/src/node/SetupServerApi.ts +7 -8
  138. package/src/node/SetupServerCommonApi.ts +8 -15
  139. package/src/node/glossary.ts +7 -5
  140. package/src/node/setupServer.ts +1 -2
  141. package/lib/core/handlers/WebSocketHandler.d.mts +0 -32
  142. package/lib/core/handlers/WebSocketHandler.d.ts +0 -32
  143. package/lib/core/handlers/WebSocketHandler.js +0 -62
  144. package/lib/core/handlers/WebSocketHandler.js.map +0 -1
  145. package/lib/core/handlers/WebSocketHandler.mjs +0 -44
  146. package/lib/core/handlers/WebSocketHandler.mjs.map +0 -1
  147. package/lib/core/ws/WebSocketClientManager.d.mts +0 -58
  148. package/lib/core/ws/WebSocketClientManager.d.ts +0 -58
  149. package/lib/core/ws/WebSocketClientManager.js +0 -162
  150. package/lib/core/ws/WebSocketClientManager.js.map +0 -1
  151. package/lib/core/ws/WebSocketClientManager.mjs +0 -142
  152. package/lib/core/ws/WebSocketClientManager.mjs.map +0 -1
  153. package/lib/core/ws/handleWebSocketEvent.d.mts +0 -16
  154. package/lib/core/ws/handleWebSocketEvent.d.ts +0 -16
  155. package/lib/core/ws/handleWebSocketEvent.js +0 -56
  156. package/lib/core/ws/handleWebSocketEvent.js.map +0 -1
  157. package/lib/core/ws/handleWebSocketEvent.mjs +0 -36
  158. package/lib/core/ws/handleWebSocketEvent.mjs.map +0 -1
  159. package/lib/core/ws/utils/attachWebSocketLogger.d.mts +0 -34
  160. package/lib/core/ws/utils/attachWebSocketLogger.d.ts +0 -34
  161. package/lib/core/ws/utils/attachWebSocketLogger.js +0 -217
  162. package/lib/core/ws/utils/attachWebSocketLogger.js.map +0 -1
  163. package/lib/core/ws/utils/attachWebSocketLogger.mjs +0 -197
  164. package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +0 -1
  165. package/lib/core/ws/utils/getMessageLength.d.mts +0 -11
  166. package/lib/core/ws/utils/getMessageLength.d.ts +0 -11
  167. package/lib/core/ws/utils/getMessageLength.js +0 -33
  168. package/lib/core/ws/utils/getMessageLength.js.map +0 -1
  169. package/lib/core/ws/utils/getMessageLength.mjs +0 -13
  170. package/lib/core/ws/utils/getMessageLength.mjs.map +0 -1
  171. package/lib/core/ws/utils/getPublicData.d.mts +0 -5
  172. package/lib/core/ws/utils/getPublicData.d.ts +0 -5
  173. package/lib/core/ws/utils/getPublicData.js +0 -36
  174. package/lib/core/ws/utils/getPublicData.js.map +0 -1
  175. package/lib/core/ws/utils/getPublicData.mjs +0 -16
  176. package/lib/core/ws/utils/getPublicData.mjs.map +0 -1
  177. package/lib/core/ws/utils/truncateMessage.d.mts +0 -3
  178. package/lib/core/ws/utils/truncateMessage.d.ts +0 -3
  179. package/lib/core/ws/utils/truncateMessage.js +0 -31
  180. package/lib/core/ws/utils/truncateMessage.js.map +0 -1
  181. package/lib/core/ws/utils/truncateMessage.mjs +0 -11
  182. package/lib/core/ws/utils/truncateMessage.mjs.map +0 -1
  183. package/lib/core/ws/webSocketInterceptor.d.mts +0 -5
  184. package/lib/core/ws/webSocketInterceptor.d.ts +0 -5
  185. package/lib/core/ws/webSocketInterceptor.js +0 -26
  186. package/lib/core/ws/webSocketInterceptor.js.map +0 -1
  187. package/lib/core/ws/webSocketInterceptor.mjs +0 -6
  188. package/lib/core/ws/webSocketInterceptor.mjs.map +0 -1
  189. package/lib/core/ws.d.mts +0 -49
  190. package/lib/core/ws.d.ts +0 -49
  191. package/lib/core/ws.js +0 -65
  192. package/lib/core/ws.js.map +0 -1
  193. package/lib/core/ws.mjs +0 -48
  194. package/lib/core/ws.mjs.map +0 -1
  195. package/src/core/handlers/WebSocketHandler.ts +0 -71
  196. package/src/core/ws/WebSocketClientManager.test.ts +0 -157
  197. package/src/core/ws/WebSocketClientManager.ts +0 -234
  198. package/src/core/ws/handleWebSocketEvent.ts +0 -56
  199. package/src/core/ws/utils/attachWebSocketLogger.ts +0 -269
  200. package/src/core/ws/utils/getMessageLength.test.ts +0 -16
  201. package/src/core/ws/utils/getMessageLength.ts +0 -19
  202. package/src/core/ws/utils/getPublicData.test.ts +0 -38
  203. package/src/core/ws/utils/getPublicData.ts +0 -17
  204. package/src/core/ws/utils/truncateMessage.test.ts +0 -12
  205. package/src/core/ws/utils/truncateMessage.ts +0 -9
  206. package/src/core/ws/webSocketInterceptor.ts +0 -3
  207. package/src/core/ws.test.ts +0 -23
  208. 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 /api
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(fixtures.warningWithoutSuggestions)
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(fixtures.warningWithoutSuggestions)
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 Error(
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 Error(
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,
@@ -1,17 +1,22 @@
1
1
  import { cleanUrl } from './cleanUrl'
2
2
 
3
- test('removes query parameters from a URL string', () => {
3
+ it('removes query parameters from a URL string', () => {
4
4
  expect(cleanUrl('/user?id=123')).toEqual('/user')
5
5
  expect(cleanUrl('/user?id=123&id=456')).toEqual('/user')
6
6
  expect(cleanUrl('/user?id=123&role=admin')).toEqual('/user')
7
7
  })
8
8
 
9
- test('removes hashes from a URL string', () => {
9
+ it('removes hashes from a URL string', () => {
10
10
  expect(cleanUrl('/user#hash')).toEqual('/user')
11
11
  expect(cleanUrl('/user#hash-with-dashes')).toEqual('/user')
12
12
  })
13
13
 
14
- test('removes both query parameters and hashes from a URL string', () => {
14
+ it('removes both query parameters and hashes from a URL string', () => {
15
15
  expect(cleanUrl('/user?id=123#some')).toEqual('/user')
16
16
  expect(cleanUrl('/user?id=123&role=admin#some')).toEqual('/user')
17
17
  })
18
+
19
+ it('preserves optional path parameters', () => {
20
+ expect(cleanUrl('/user/:id?')).toEqual('/user/:id?')
21
+ expect(cleanUrl('/user/:id?/:messageId?')).toEqual('/user/:id?/:messageId?')
22
+ })
@@ -5,8 +5,16 @@ export function getSearchParams(path: string) {
5
5
  }
6
6
 
7
7
  /**
8
- * Removes query parameters and hashes from a given URL string.
8
+ * Removes search parameters and the fragment
9
+ * from a given URL string.
9
10
  */
10
11
  export function cleanUrl(path: string): string {
12
+ // If the path ends with an optional path parameter,
13
+ // return it as-is.
14
+ if (path.endsWith('?')) {
15
+ return path
16
+ }
17
+
18
+ // Otherwise, remove the search and fragment from it.
11
19
  return path.replace(REDUNDANT_CHARACTERS_EXP, '')
12
20
  }
@@ -3,16 +3,16 @@
3
3
  */
4
4
  import { getAbsoluteUrl } from './getAbsoluteUrl'
5
5
 
6
- test('returns a given relative URL as-is', () => {
6
+ it('returns a given relative URL as-is', () => {
7
7
  expect(getAbsoluteUrl('/reviews')).toBe('/reviews')
8
8
  })
9
9
 
10
- test('rebases a relative URL against a custom base URL', () => {
10
+ it('rebases a relative URL against a custom base URL', () => {
11
11
  expect(getAbsoluteUrl('/user', 'https://api.github.com')).toEqual(
12
12
  'https://api.github.com/user',
13
13
  )
14
14
  })
15
- test('returns a given absolute URL as-is', () => {
15
+ it('returns a given absolute URL as-is', () => {
16
16
  expect(getAbsoluteUrl('https://api.mswjs.io/users')).toBe(
17
17
  'https://api.mswjs.io/users',
18
18
  )
@@ -3,27 +3,27 @@
3
3
  */
4
4
  import { getAbsoluteUrl } from './getAbsoluteUrl'
5
5
 
6
- test('rebases a relative URL against the current "baseURI" (default)', () => {
6
+ it('rebases a relative URL against the current "baseURI" (default)', () => {
7
7
  expect(getAbsoluteUrl('/reviews')).toEqual('http://localhost/reviews')
8
8
  })
9
9
 
10
- test('rebases a relative URL against a custom base URL', () => {
10
+ it('rebases a relative URL against a custom base URL', () => {
11
11
  expect(getAbsoluteUrl('/user', 'https://api.github.com')).toEqual(
12
12
  'https://api.github.com/user',
13
13
  )
14
14
  })
15
15
 
16
- test('returns a given absolute URL as-is', () => {
16
+ it('returns a given absolute URL as-is', () => {
17
17
  expect(getAbsoluteUrl('https://api.mswjs.io/users')).toEqual(
18
18
  'https://api.mswjs.io/users',
19
19
  )
20
20
  })
21
21
 
22
- test('returns an absolute URL given a relative path without a leading slash', () => {
22
+ it('returns an absolute URL given a relative path without a leading slash', () => {
23
23
  expect(getAbsoluteUrl('users')).toEqual('http://localhost/users')
24
24
  })
25
25
 
26
- test('returns a path with a pattern as-is', () => {
26
+ it('returns a path with a pattern as-is', () => {
27
27
  expect(getAbsoluteUrl(':api/user')).toEqual('http://localhost/:api/user')
28
28
  expect(getAbsoluteUrl('*/resource/*')).toEqual('*/resource/*')
29
29
  })
@@ -3,30 +3,30 @@
3
3
  */
4
4
  import { isAbsoluteUrl } from './isAbsoluteUrl'
5
5
 
6
- test('returns true for the "http" scheme', () => {
6
+ it('returns true for the "http" scheme', () => {
7
7
  expect(isAbsoluteUrl('http://www.domain.com')).toEqual(true)
8
8
  })
9
9
 
10
- test('returns true for the "https" scheme', () => {
10
+ it('returns true for the "https" scheme', () => {
11
11
  expect(isAbsoluteUrl('https://www.domain.com')).toEqual(true)
12
12
  })
13
13
 
14
- test('returns true for the "ws" scheme', () => {
14
+ it('returns true for the "ws" scheme', () => {
15
15
  expect(isAbsoluteUrl('ws://www.domain.com')).toEqual(true)
16
16
  })
17
17
 
18
- test('returns true for the "ftp" scheme', () => {
18
+ it('returns true for the "ftp" scheme', () => {
19
19
  expect(isAbsoluteUrl('ftp://www.domain.com')).toEqual(true)
20
20
  })
21
21
 
22
- test('returns true for the custom scheme', () => {
22
+ it('returns true for the custom scheme', () => {
23
23
  expect(isAbsoluteUrl('web+my://www.example.com')).toEqual(true)
24
24
  })
25
25
 
26
- test('returns false for the relative URL', () => {
26
+ it('returns false for the relative URL', () => {
27
27
  expect(isAbsoluteUrl('/test')).toEqual(false)
28
28
  })
29
29
 
30
- test('returns false for the relative URL without a leading slash', () => {
30
+ it('returns false for the relative URL without a leading slash', () => {
31
31
  expect(isAbsoluteUrl('test')).toEqual(false)
32
32
  })
@@ -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 | WebSocketHandler>
15
- handlers: Array<RequestHandler | WebSocketHandler>
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 | WebSocketHandler>) {
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 | WebSocketHandler>) {
33
+ public prepend(runtimeHandlers: Array<RequestHandler>) {
35
34
  this.context.handlers.unshift(...runtimeHandlers)
36
35
  }
37
36
 
38
- public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>) {
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 | WebSocketHandler> {
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 | WebSocketHandler>) {
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 | WebSocketHandler>,
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.
@@ -1,6 +1,8 @@
1
1
  import type { PartialDeep } from 'type-fest'
2
- import type { RequestHandler } from '~/core/handlers/RequestHandler'
3
- import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
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 | WebSocketHandler>): void
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 | WebSocketHandler>): void
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 | WebSocketHandler>
53
+ listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>
52
54
 
53
55
  /**
54
56
  * Life-cycle events.
@@ -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 | WebSocketHandler>
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 };