msw 2.7.3 → 2.7.4

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.
@@ -8,7 +8,7 @@
8
8
  * - Please do NOT serve this file on production.
9
9
  */
10
10
 
11
- const PACKAGE_VERSION = '2.7.3'
11
+ const PACKAGE_VERSION = '2.7.4'
12
12
  const INTEGRITY_CHECKSUM = '00729d72e3b82faf54ca8b9621dbb96f'
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.7.3",
3
+ "version": "2.7.4",
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",
@@ -1,6 +1,4 @@
1
- /**
2
- * @vitest-environment jsdom
3
- */
1
+ // @vitest-environment jsdom
4
2
  import { getAbsoluteWorkerUrl } from './getAbsoluteWorkerUrl'
5
3
 
6
4
  const rawLocation = window.location
@@ -72,6 +72,7 @@ export type GraphQLResponseBody<BodyType extends DefaultBodyType> =
72
72
  | {
73
73
  data?: BodyType | null
74
74
  errors?: readonly Partial<GraphQLError>[] | null
75
+ extensions?: Record<string, any>
75
76
  }
76
77
  | null
77
78
  | undefined
@@ -1,29 +1,47 @@
1
- /**
2
- * @vitest-environment jsdom
3
- */
1
+ // @vitest-environment jsdom
4
2
  import { getAbsoluteUrl } from './getAbsoluteUrl'
5
3
 
6
- it('rebases a relative URL against the current "baseURI" (default)', () => {
7
- expect(getAbsoluteUrl('/reviews')).toEqual('http://localhost/reviews')
4
+ const rawLocation = window.location
5
+
6
+ afterAll(() => {
7
+ Object.defineProperty(window, 'location', {
8
+ value: rawLocation,
9
+ })
10
+ })
11
+
12
+ it('resolves a relative URL against the current location (default)', () => {
13
+ expect(getAbsoluteUrl('/reviews')).toBe('http://localhost/reviews')
14
+ })
15
+
16
+ it('supports relative URLs starting with search parameters', () => {
17
+ Object.defineProperty(window, 'location', {
18
+ value: {
19
+ href: 'http://localhost/nested',
20
+ },
21
+ })
22
+
23
+ expect(getAbsoluteUrl('?resourceId=abc-123')).toBe(
24
+ 'http://localhost/nested?resourceId=abc-123',
25
+ )
8
26
  })
9
27
 
10
- it('rebases a relative URL against a custom base URL', () => {
11
- expect(getAbsoluteUrl('/user', 'https://api.github.com')).toEqual(
28
+ it('resolves a relative URL against a custom base URL', () => {
29
+ expect(getAbsoluteUrl('/user', 'https://api.github.com')).toBe(
12
30
  'https://api.github.com/user',
13
31
  )
14
32
  })
15
33
 
16
34
  it('returns a given absolute URL as-is', () => {
17
- expect(getAbsoluteUrl('https://api.mswjs.io/users')).toEqual(
35
+ expect(getAbsoluteUrl('https://api.mswjs.io/users')).toBe(
18
36
  'https://api.mswjs.io/users',
19
37
  )
20
38
  })
21
39
 
22
40
  it('returns an absolute URL given a relative path without a leading slash', () => {
23
- expect(getAbsoluteUrl('users')).toEqual('http://localhost/users')
41
+ expect(getAbsoluteUrl('users')).toBe('http://localhost/users')
24
42
  })
25
43
 
26
44
  it('returns a path with a pattern as-is', () => {
27
- expect(getAbsoluteUrl(':api/user')).toEqual('http://localhost/:api/user')
28
- expect(getAbsoluteUrl('*/resource/*')).toEqual('*/resource/*')
45
+ expect(getAbsoluteUrl(':api/user')).toBe('http://localhost/:api/user')
46
+ expect(getAbsoluteUrl('*/resource/*')).toBe('*/resource/*')
29
47
  })
@@ -16,8 +16,7 @@ export function getAbsoluteUrl(path: string, baseUrl?: string): string {
16
16
 
17
17
  // Resolve a relative request URL against a given custom "baseUrl"
18
18
  // or the document baseURI (in the case of browser/browser-like environments).
19
- const origin =
20
- baseUrl || (typeof document !== 'undefined' && document.baseURI)
19
+ const origin = baseUrl || (typeof location !== 'undefined' && location.href)
21
20
 
22
21
  return origin
23
22
  ? // Encode and decode the path to preserve escaped characters.