msw 2.3.0 → 2.3.2
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/core/{GraphQLHandler-Dq_WRbKe.d.mts → GraphQLHandler-BylXHeRG.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-COiPfZ8k.d.ts → GraphQLHandler-CFApN2Xu.d.ts} +1 -1
- package/lib/core/{HttpResponse-C7niBMwb.d.mts → HttpResponse-CKzTV_na.d.mts} +2 -2
- package/lib/core/{HttpResponse-B07UKAkU.d.ts → HttpResponse-DzcQloxl.d.ts} +2 -2
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +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 -2
- package/lib/core/index.d.ts +2 -2
- 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/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +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/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/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/iife/index.js +3 -0
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +6 -6
- 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/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/lib/mockServiceWorker.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const PACKAGE_VERSION = '2.3.
|
|
11
|
+
const PACKAGE_VERSION = '2.3.2'
|
|
12
12
|
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
|
|
13
13
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
14
14
|
const activeClientIds = new Set()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"main": "./lib/core/index.js",
|
|
6
6
|
"module": "./lib/core/index.mjs",
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
"simple-git-hooks": "^2.9.0",
|
|
172
172
|
"ts-node": "^10.9.2",
|
|
173
173
|
"tsup": "^8.0.1",
|
|
174
|
-
"typescript": "^5.
|
|
174
|
+
"typescript": "^5.5.2",
|
|
175
175
|
"undici": "^5.20.0",
|
|
176
176
|
"url-loader": "^4.1.1",
|
|
177
177
|
"vitest": "^1.2.2",
|
|
@@ -206,12 +206,12 @@
|
|
|
206
206
|
"check:exports": "node \"./config/scripts/validate-esm.js\"",
|
|
207
207
|
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
|
|
208
208
|
"test:unit": "vitest",
|
|
209
|
-
"test:node": "vitest run --config=./test/node/vitest.config.
|
|
210
|
-
"test:native": "vitest --config=./test/native/vitest.config.
|
|
209
|
+
"test:node": "vitest run --config=./test/node/vitest.config.mts",
|
|
210
|
+
"test:native": "vitest --config=./test/native/vitest.config.mts",
|
|
211
211
|
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
|
|
212
|
-
"test:modules:node": "vitest --config=./test/modules/node/vitest.config.
|
|
212
|
+
"test:modules:node": "vitest --config=./test/modules/node/vitest.config.mts",
|
|
213
213
|
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
|
|
214
|
-
"test:ts": "vitest --typecheck --config=./test/typings/vitest.config.
|
|
214
|
+
"test:ts": "vitest --typecheck --config=./test/typings/vitest.config.mts",
|
|
215
215
|
"release": "release publish",
|
|
216
216
|
"postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\""
|
|
217
217
|
}
|
|
@@ -61,6 +61,17 @@ describe('matchRequestUrl', () => {
|
|
|
61
61
|
expect(match).toHaveProperty('matches', false)
|
|
62
62
|
expect(match).toHaveProperty('params', {})
|
|
63
63
|
})
|
|
64
|
+
|
|
65
|
+
test('returns true when matching optional path parameters', () => {
|
|
66
|
+
const match = matchRequestUrl(
|
|
67
|
+
new URL('https://test.mswjs.io/user'),
|
|
68
|
+
'https://test.mswjs.io/user/:userId?',
|
|
69
|
+
)
|
|
70
|
+
expect(match).toHaveProperty('matches', true)
|
|
71
|
+
expect(match).toHaveProperty('params', {
|
|
72
|
+
userId: undefined,
|
|
73
|
+
})
|
|
74
|
+
})
|
|
64
75
|
})
|
|
65
76
|
|
|
66
77
|
describe('coercePath', () => {
|
|
@@ -43,8 +43,14 @@ test('returns a path pattern string as-is', () => {
|
|
|
43
43
|
expect(normalizePath('*/resource/*')).toEqual('*/resource/*')
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
test('
|
|
46
|
+
test('removes query parameters and hashes from a path pattern string', () => {
|
|
47
47
|
expect(normalizePath(':api/user?query=123#some')).toEqual(
|
|
48
48
|
'http://localhost/:api/user',
|
|
49
49
|
)
|
|
50
50
|
})
|
|
51
|
+
|
|
52
|
+
test('preserves optional path parameters', () => {
|
|
53
|
+
expect(normalizePath('/user/:userId?')).toEqual(
|
|
54
|
+
'http://localhost/user/:userId?',
|
|
55
|
+
)
|
|
56
|
+
})
|
|
@@ -8,6 +8,7 @@ import { getAbsoluteUrl } from '../url/getAbsoluteUrl'
|
|
|
8
8
|
* - Removes query parameters and hashes.
|
|
9
9
|
* - Rebases relative URLs against the "baseUrl" or the current location.
|
|
10
10
|
* - Preserves relative URLs in Node.js, unless specified otherwise.
|
|
11
|
+
* - Preserves optional path parameters.
|
|
11
12
|
*/
|
|
12
13
|
export function normalizePath(path: Path, baseUrl?: string): Path {
|
|
13
14
|
// RegExp paths do not need normalization.
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { cleanUrl } from './cleanUrl'
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
6
|
+
it('returns a given relative URL as-is', () => {
|
|
7
7
|
expect(getAbsoluteUrl('/reviews')).toBe('/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
|
+
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
|
-
|
|
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
|
})
|