msw 2.3.0-ws.rc-6 → 2.3.0-ws.rc-7

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 (66) hide show
  1. package/README.md +3 -9
  2. package/lib/browser/index.js +160 -64
  3. package/lib/browser/index.js.map +1 -1
  4. package/lib/browser/index.mjs +160 -64
  5. package/lib/browser/index.mjs.map +1 -1
  6. package/lib/core/handlers/WebSocketHandler.js +1 -2
  7. package/lib/core/handlers/WebSocketHandler.js.map +1 -1
  8. package/lib/core/handlers/WebSocketHandler.mjs +1 -2
  9. package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
  10. package/lib/core/utils/internal/Disposable.d.mts +2 -2
  11. package/lib/core/utils/internal/Disposable.d.ts +2 -2
  12. package/lib/core/utils/internal/Disposable.js +5 -2
  13. package/lib/core/utils/internal/Disposable.js.map +1 -1
  14. package/lib/core/utils/internal/Disposable.mjs +5 -2
  15. package/lib/core/utils/internal/Disposable.mjs.map +1 -1
  16. package/lib/core/utils/internal/devUtils.d.mts +10 -1
  17. package/lib/core/utils/internal/devUtils.d.ts +10 -1
  18. package/lib/core/utils/internal/devUtils.js +7 -0
  19. package/lib/core/utils/internal/devUtils.js.map +1 -1
  20. package/lib/core/utils/internal/devUtils.mjs +7 -0
  21. package/lib/core/utils/internal/devUtils.mjs.map +1 -1
  22. package/lib/core/utils/matching/normalizePath.d.mts +1 -0
  23. package/lib/core/utils/matching/normalizePath.d.ts +1 -0
  24. package/lib/core/utils/matching/normalizePath.js.map +1 -1
  25. package/lib/core/utils/matching/normalizePath.mjs.map +1 -1
  26. package/lib/core/utils/request/onUnhandledRequest.js +3 -3
  27. package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
  28. package/lib/core/utils/request/onUnhandledRequest.mjs +4 -4
  29. package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
  30. package/lib/core/utils/url/cleanUrl.d.mts +2 -1
  31. package/lib/core/utils/url/cleanUrl.d.ts +2 -1
  32. package/lib/core/utils/url/cleanUrl.js +3 -0
  33. package/lib/core/utils/url/cleanUrl.js.map +1 -1
  34. package/lib/core/utils/url/cleanUrl.mjs +3 -0
  35. package/lib/core/utils/url/cleanUrl.mjs.map +1 -1
  36. package/lib/core/ws/WebSocketClientManager.js.map +1 -1
  37. package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
  38. package/lib/iife/index.js +204 -79
  39. package/lib/iife/index.js.map +1 -1
  40. package/lib/mockServiceWorker.js +1 -1
  41. package/lib/native/index.js +5 -0
  42. package/lib/native/index.js.map +1 -1
  43. package/lib/native/index.mjs +6 -1
  44. package/lib/native/index.mjs.map +1 -1
  45. package/lib/node/index.js +5 -0
  46. package/lib/node/index.js.map +1 -1
  47. package/lib/node/index.mjs +6 -1
  48. package/lib/node/index.mjs.map +1 -1
  49. package/package.json +17 -5
  50. package/src/browser/setupWorker/start/createStartHandler.ts +6 -0
  51. package/src/core/handlers/WebSocketHandler.ts +1 -2
  52. package/src/core/utils/internal/Disposable.ts +6 -3
  53. package/src/core/utils/internal/devUtils.test.ts +21 -0
  54. package/src/core/utils/internal/devUtils.ts +13 -0
  55. package/src/core/utils/matching/matchRequestUrl.test.ts +11 -0
  56. package/src/core/utils/matching/normalizePath.test.ts +7 -1
  57. package/src/core/utils/matching/normalizePath.ts +1 -0
  58. package/src/core/utils/request/onUnhandledRequest.test.ts +30 -4
  59. package/src/core/utils/request/onUnhandledRequest.ts +4 -4
  60. package/src/core/utils/url/cleanUrl.test.ts +8 -3
  61. package/src/core/utils/url/cleanUrl.ts +9 -1
  62. package/src/core/utils/url/getAbsoluteUrl.node.test.ts +3 -3
  63. package/src/core/utils/url/getAbsoluteUrl.test.ts +5 -5
  64. package/src/core/utils/url/isAbsoluteUrl.test.ts +7 -7
  65. package/src/core/ws/WebSocketClientManager.ts +1 -2
  66. package/src/node/SetupServerCommonApi.ts +7 -1
@@ -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
  })
@@ -43,9 +43,8 @@ export class WebSocketClientManager {
43
43
  ) {
44
44
  this.inMemoryClients = new Set()
45
45
 
46
+ // Purge in-memory clients when the worker stops.
46
47
  if (typeof localStorage !== 'undefined') {
47
- // When the worker clears the local storage key in "worker.stop()",
48
- // also clear the in-memory clients map.
49
48
  localStorage.removeItem = new Proxy(localStorage.removeItem, {
50
49
  apply: (target, thisArg, args) => {
51
50
  const [key] = args
@@ -16,7 +16,7 @@ import { handleRequest } from '~/core/utils/handleRequest'
16
16
  import type { RequestHandler } from '~/core/handlers/RequestHandler'
17
17
  import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
18
18
  import { mergeRight } from '~/core/utils/internal/mergeRight'
19
- import { devUtils } from '~/core/utils/internal/devUtils'
19
+ import { InternalError, devUtils } from '~/core/utils/internal/devUtils'
20
20
  import type { SetupServerCommon } from './glossary'
21
21
  import { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'
22
22
  import { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'
@@ -71,6 +71,12 @@ export class SetupServerCommonApi
71
71
  return
72
72
  })
73
73
 
74
+ this.interceptor.on('unhandledException', ({ error }) => {
75
+ if (error instanceof InternalError) {
76
+ throw error
77
+ }
78
+ })
79
+
74
80
  this.interceptor.on(
75
81
  'response',
76
82
  ({ response, isMockedResponse, request, requestId }) => {