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.
- package/README.md +3 -9
- package/lib/browser/index.js +160 -64
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +160 -64
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.js +1 -2
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +1 -2
- package/lib/core/handlers/WebSocketHandler.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/matching/normalizePath.d.mts +1 -0
- package/lib/core/utils/matching/normalizePath.d.ts +1 -0
- package/lib/core/utils/matching/normalizePath.js.map +1 -1
- package/lib/core/utils/matching/normalizePath.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/core/utils/url/cleanUrl.d.mts +2 -1
- package/lib/core/utils/url/cleanUrl.d.ts +2 -1
- package/lib/core/utils/url/cleanUrl.js +3 -0
- package/lib/core/utils/url/cleanUrl.js.map +1 -1
- package/lib/core/utils/url/cleanUrl.mjs +3 -0
- package/lib/core/utils/url/cleanUrl.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.js.map +1 -1
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
- package/lib/iife/index.js +204 -79
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +5 -0
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +6 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +5 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +6 -1
- package/lib/node/index.mjs.map +1 -1
- package/package.json +17 -5
- package/src/browser/setupWorker/start/createStartHandler.ts +6 -0
- package/src/core/handlers/WebSocketHandler.ts +1 -2
- 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/matching/matchRequestUrl.test.ts +11 -0
- package/src/core/utils/matching/normalizePath.test.ts +7 -1
- package/src/core/utils/matching/normalizePath.ts +1 -0
- package/src/core/utils/request/onUnhandledRequest.test.ts +30 -4
- package/src/core/utils/request/onUnhandledRequest.ts +4 -4
- package/src/core/utils/url/cleanUrl.test.ts +8 -3
- package/src/core/utils/url/cleanUrl.ts +9 -1
- package/src/core/utils/url/getAbsoluteUrl.node.test.ts +3 -3
- package/src/core/utils/url/getAbsoluteUrl.test.ts +5 -5
- package/src/core/utils/url/isAbsoluteUrl.test.ts +7 -7
- package/src/core/ws/WebSocketClientManager.ts +1 -2
- package/src/node/SetupServerCommonApi.ts +7 -1
|
@@ -3,27 +3,27 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { getAbsoluteUrl } from './getAbsoluteUrl'
|
|
5
5
|
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6
|
+
it('returns true for the "http" scheme', () => {
|
|
7
7
|
expect(isAbsoluteUrl('http://www.domain.com')).toEqual(true)
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
it('returns true for the "https" scheme', () => {
|
|
11
11
|
expect(isAbsoluteUrl('https://www.domain.com')).toEqual(true)
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
it('returns true for the "ws" scheme', () => {
|
|
15
15
|
expect(isAbsoluteUrl('ws://www.domain.com')).toEqual(true)
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
it('returns true for the "ftp" scheme', () => {
|
|
19
19
|
expect(isAbsoluteUrl('ftp://www.domain.com')).toEqual(true)
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
it('returns true for the custom scheme', () => {
|
|
23
23
|
expect(isAbsoluteUrl('web+my://www.example.com')).toEqual(true)
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
it('returns false for the relative URL', () => {
|
|
27
27
|
expect(isAbsoluteUrl('/test')).toEqual(false)
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
|
|
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 }) => {
|