@mswjs/interceptors 0.17.6 → 0.18.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.
- package/README.md +49 -47
- package/lib/Interceptor.js +4 -4
- package/lib/Interceptor.js.map +1 -1
- package/lib/RemoteHttpInterceptor.d.ts +15 -0
- package/lib/RemoteHttpInterceptor.js +86 -56
- package/lib/RemoteHttpInterceptor.js.map +1 -1
- package/lib/glossary.d.ts +3 -14
- package/lib/glossary.js.map +1 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/lib/interceptors/ClientRequest/NodeClientRequest.d.ts +13 -5
- package/lib/interceptors/ClientRequest/NodeClientRequest.js +179 -166
- package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +1 -1
- package/lib/interceptors/ClientRequest/http.get.js +9 -5
- package/lib/interceptors/ClientRequest/http.get.js.map +1 -1
- package/lib/interceptors/ClientRequest/http.request.js +10 -6
- package/lib/interceptors/ClientRequest/http.request.js.map +1 -1
- package/lib/interceptors/ClientRequest/index.d.ts +2 -5
- package/lib/interceptors/ClientRequest/index.js +2 -13
- package/lib/interceptors/ClientRequest/index.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +9 -5
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/createRequest.d.ts +6 -0
- package/lib/interceptors/ClientRequest/utils/createRequest.js +52 -0
- package/lib/interceptors/ClientRequest/utils/createRequest.js.map +1 -0
- package/lib/interceptors/ClientRequest/utils/createResponse.d.ts +8 -0
- package/lib/interceptors/ClientRequest/utils/createResponse.js +24 -0
- package/lib/interceptors/ClientRequest/utils/createResponse.js.map +1 -0
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js +1 -1
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js +8 -8
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.d.ts +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.d.ts +6 -10
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js +203 -143
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/index.d.ts +2 -2
- package/lib/interceptors/XMLHttpRequest/index.js +2 -2
- package/lib/interceptors/XMLHttpRequest/index.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.d.ts +4 -0
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js +14 -0
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js.map +1 -0
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.d.ts +2 -0
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.js +14 -0
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.js.map +1 -0
- package/lib/interceptors/fetch/index.js +24 -81
- package/lib/interceptors/fetch/index.js.map +1 -1
- package/lib/utils/AsyncEventEmitter.js +12 -8
- package/lib/utils/AsyncEventEmitter.js.map +1 -1
- package/lib/utils/RequestWithCredentials.d.ts +2 -0
- package/lib/utils/RequestWithCredentials.js +20 -0
- package/lib/utils/RequestWithCredentials.js.map +1 -0
- package/lib/utils/bufferUtils.d.ts +7 -2
- package/lib/utils/bufferUtils.js +10 -6
- package/lib/utils/bufferUtils.js.map +1 -1
- package/lib/utils/parseJson.d.ts +1 -1
- package/lib/utils/toInteractiveRequest.d.ts +7 -0
- package/lib/utils/toInteractiveRequest.js +20 -0
- package/lib/utils/toInteractiveRequest.js.map +1 -0
- package/package.json +3 -2
- package/src/RemoteHttpInterceptor.ts +84 -34
- package/src/glossary.ts +5 -18
- package/src/index.ts +0 -2
- package/src/interceptors/ClientRequest/NodeClientRequest.test.ts +17 -23
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +177 -153
- package/src/interceptors/ClientRequest/index.test.ts +5 -3
- package/src/interceptors/ClientRequest/index.ts +2 -26
- package/src/interceptors/ClientRequest/utils/createRequest.test.ts +61 -0
- package/src/interceptors/ClientRequest/utils/createRequest.ts +32 -0
- package/src/interceptors/ClientRequest/utils/createResponse.test.ts +24 -0
- package/src/interceptors/ClientRequest/utils/createResponse.ts +22 -0
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.ts +1 -1
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts +234 -174
- package/src/interceptors/XMLHttpRequest/index.ts +3 -2
- package/src/interceptors/XMLHttpRequest/utils/concatArrayBuffer.ts +12 -0
- package/src/interceptors/XMLHttpRequest/utils/concateArrayBuffer.test.ts +14 -0
- package/src/interceptors/XMLHttpRequest/utils/createResponse.ts +13 -0
- package/src/interceptors/fetch/index.ts +30 -69
- package/src/utils/RequestWithCredentials.test.ts +20 -0
- package/src/utils/RequestWithCredentials.ts +24 -0
- package/src/utils/bufferUtils.ts +10 -5
- package/src/utils/parseJson.ts +1 -1
- package/src/utils/toInteractiveRequest.ts +29 -0
- package/lib/InteractiveIsomorphicRequest.d.ts +0 -7
- package/lib/InteractiveIsomorphicRequest.js +0 -37
- package/lib/InteractiveIsomorphicRequest.js.map +0 -1
- package/lib/IsomorphicRequest.d.ts +0 -24
- package/lib/IsomorphicRequest.js +0 -107
- package/lib/IsomorphicRequest.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/bodyBufferToString.d.ts +0 -2
- package/lib/interceptors/ClientRequest/utils/bodyBufferToString.js +0 -11
- package/lib/interceptors/ClientRequest/utils/bodyBufferToString.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/concatChunkToBuffer.d.ts +0 -2
- package/lib/interceptors/ClientRequest/utils/concatChunkToBuffer.js +0 -11
- package/lib/interceptors/ClientRequest/utils/concatChunkToBuffer.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/utils/bufferFrom.d.ts +0 -5
- package/lib/interceptors/XMLHttpRequest/utils/bufferFrom.js +0 -20
- package/lib/interceptors/XMLHttpRequest/utils/bufferFrom.js.map +0 -1
- package/lib/utils/toIsoResponse.d.ts +0 -5
- package/lib/utils/toIsoResponse.js +0 -18
- package/lib/utils/toIsoResponse.js.map +0 -1
- package/src/InteractiveIsomorphicRequest.ts +0 -24
- package/src/IsomorphicRequest.test.ts +0 -106
- package/src/IsomorphicRequest.ts +0 -86
- package/src/interceptors/ClientRequest/utils/bodyBufferToString.test.ts +0 -16
- package/src/interceptors/ClientRequest/utils/bodyBufferToString.ts +0 -7
- package/src/interceptors/ClientRequest/utils/concatChunkToBuffer.test.ts +0 -13
- package/src/interceptors/ClientRequest/utils/concatChunkToBuffer.ts +0 -10
- package/src/interceptors/XMLHttpRequest/utils/bufferFrom.test.ts +0 -11
- package/src/interceptors/XMLHttpRequest/utils/bufferFrom.ts +0 -16
- package/src/utils/toIsoResponse.test.ts +0 -39
- package/src/utils/toIsoResponse.ts +0 -14
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Headers } from 'headers-polyfill'
|
|
2
|
-
import { IsomorphicRequest } from './IsomorphicRequest'
|
|
3
|
-
import { encodeBuffer } from './utils/bufferUtils'
|
|
4
|
-
|
|
5
|
-
const url = new URL('http://dummy')
|
|
6
|
-
const body = encodeBuffer(JSON.stringify({ hello: 'world' }))
|
|
7
|
-
|
|
8
|
-
it('reads request body as json', async () => {
|
|
9
|
-
const request = new IsomorphicRequest(url, { body })
|
|
10
|
-
|
|
11
|
-
expect(request.bodyUsed).toBe(false)
|
|
12
|
-
expect(await request.json()).toEqual({ hello: 'world' })
|
|
13
|
-
expect(request.bodyUsed).toBe(true)
|
|
14
|
-
expect(() => request.json()).rejects.toThrow(
|
|
15
|
-
'Failed to execute "json" on "IsomorphicRequest": body buffer already read'
|
|
16
|
-
)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('reads request body as text', async () => {
|
|
20
|
-
const request = new IsomorphicRequest(url, { body })
|
|
21
|
-
|
|
22
|
-
expect(request.bodyUsed).toBe(false)
|
|
23
|
-
expect(await request.text()).toEqual(JSON.stringify({ hello: 'world' }))
|
|
24
|
-
expect(request.bodyUsed).toBe(true)
|
|
25
|
-
expect(() => request.text()).rejects.toThrow(
|
|
26
|
-
'Failed to execute "text" on "IsomorphicRequest": body buffer already read'
|
|
27
|
-
)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('reads request body as array buffer', async () => {
|
|
31
|
-
const request = new IsomorphicRequest(url, { body })
|
|
32
|
-
|
|
33
|
-
expect(request.bodyUsed).toBe(false)
|
|
34
|
-
expect(await request.arrayBuffer()).toEqual(encodeBuffer(`{"hello":"world"}`))
|
|
35
|
-
expect(request.bodyUsed).toBe(true)
|
|
36
|
-
expect(() => request.arrayBuffer()).rejects.toThrow(
|
|
37
|
-
'Failed to execute "arrayBuffer" on "IsomorphicRequest": body buffer already read'
|
|
38
|
-
)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('returns default method', () => {
|
|
42
|
-
const request = new IsomorphicRequest(url, { body })
|
|
43
|
-
expect(request.method).toEqual('GET')
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('returns given method', () => {
|
|
47
|
-
const request = new IsomorphicRequest(url, { body, method: 'POST' })
|
|
48
|
-
expect(request.method).toEqual('POST')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('returns given credentials', () => {
|
|
52
|
-
const request = new IsomorphicRequest(url, { body, credentials: 'include' })
|
|
53
|
-
expect(request.credentials).toEqual('include')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('returns default credentials', () => {
|
|
57
|
-
const request = new IsomorphicRequest(url, { body })
|
|
58
|
-
expect(request.credentials).toEqual('same-origin')
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('returns empty headers if not provided', () => {
|
|
62
|
-
const request = new IsomorphicRequest(url, { body })
|
|
63
|
-
expect(request.headers).toEqual(new Headers())
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('returns given headers', () => {
|
|
67
|
-
const request = new IsomorphicRequest(url, {
|
|
68
|
-
body,
|
|
69
|
-
headers: { 'Content-Type': 'application/json' },
|
|
70
|
-
})
|
|
71
|
-
expect(request.headers).toEqual(
|
|
72
|
-
new Headers({ 'Content-Type': 'application/json' })
|
|
73
|
-
)
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('returns a copy of isomorphic request instance', () => {
|
|
77
|
-
const request = new IsomorphicRequest(url, {
|
|
78
|
-
body,
|
|
79
|
-
headers: { foo: 'bar' },
|
|
80
|
-
})
|
|
81
|
-
const derivedRequest = new IsomorphicRequest(request)
|
|
82
|
-
|
|
83
|
-
expect(request.id).toBe(derivedRequest.id)
|
|
84
|
-
expect(request.url.href).toBe(derivedRequest.url.href)
|
|
85
|
-
expect(request['_body']).toEqual(derivedRequest['_body'])
|
|
86
|
-
expect(request.headers).toEqual(derivedRequest.headers)
|
|
87
|
-
expect(request.method).toBe(derivedRequest.method)
|
|
88
|
-
expect(request.credentials).toBe(derivedRequest.credentials)
|
|
89
|
-
expect(request.bodyUsed).toBe(false)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('clones current isomorphic request instance', () => {
|
|
93
|
-
const request = new IsomorphicRequest(url, {
|
|
94
|
-
body,
|
|
95
|
-
headers: { foo: 'bar' },
|
|
96
|
-
})
|
|
97
|
-
const clonedRequest = request.clone()
|
|
98
|
-
|
|
99
|
-
expect(clonedRequest.id).toBe(request.id)
|
|
100
|
-
expect(clonedRequest.method).toBe(request.method)
|
|
101
|
-
expect(clonedRequest.url.href).toBe(request.url.href)
|
|
102
|
-
expect(clonedRequest.headers).toEqual(request.headers)
|
|
103
|
-
expect(clonedRequest.credentials).toBe(request.credentials)
|
|
104
|
-
expect(clonedRequest['_body']).toEqual(request['_body'])
|
|
105
|
-
expect(clonedRequest.bodyUsed).toBe(false)
|
|
106
|
-
})
|
package/src/IsomorphicRequest.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Headers } from 'headers-polyfill'
|
|
2
|
-
import { invariant } from 'outvariant'
|
|
3
|
-
import { decodeBuffer } from './utils/bufferUtils'
|
|
4
|
-
import { uuidv4 } from './utils/uuid'
|
|
5
|
-
|
|
6
|
-
export interface RequestInit {
|
|
7
|
-
method?: string
|
|
8
|
-
headers?: Record<string, string | string[]> | Headers
|
|
9
|
-
credentials?: RequestCredentials
|
|
10
|
-
body?: ArrayBuffer
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class IsomorphicRequest {
|
|
14
|
-
public id: string
|
|
15
|
-
public readonly url: URL
|
|
16
|
-
public readonly method: string
|
|
17
|
-
public readonly headers: Headers
|
|
18
|
-
public readonly credentials: RequestCredentials
|
|
19
|
-
|
|
20
|
-
private readonly _body: ArrayBuffer
|
|
21
|
-
private _bodyUsed: boolean
|
|
22
|
-
|
|
23
|
-
constructor(url: URL)
|
|
24
|
-
constructor(url: URL, init: RequestInit)
|
|
25
|
-
constructor(request: IsomorphicRequest)
|
|
26
|
-
constructor(input: IsomorphicRequest | URL, init: RequestInit = {}) {
|
|
27
|
-
const defaultBody = new ArrayBuffer(0)
|
|
28
|
-
this._bodyUsed = false
|
|
29
|
-
|
|
30
|
-
if (input instanceof IsomorphicRequest) {
|
|
31
|
-
this.id = input.id
|
|
32
|
-
this.url = input.url
|
|
33
|
-
this.method = input.method
|
|
34
|
-
this.headers = input.headers
|
|
35
|
-
this.credentials = input.credentials
|
|
36
|
-
this._body = input._body || defaultBody
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
this.id = uuidv4()
|
|
41
|
-
this.url = input
|
|
42
|
-
this.method = init.method || 'GET'
|
|
43
|
-
this.headers = new Headers(init.headers)
|
|
44
|
-
this.credentials = init.credentials || 'same-origin'
|
|
45
|
-
this._body = init.body || defaultBody
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public get bodyUsed(): boolean {
|
|
49
|
-
return this._bodyUsed
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public async text(): Promise<string> {
|
|
53
|
-
invariant(
|
|
54
|
-
!this.bodyUsed,
|
|
55
|
-
'Failed to execute "text" on "IsomorphicRequest": body buffer already read'
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
this._bodyUsed = true
|
|
59
|
-
return decodeBuffer(this._body)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public async json<T = any>(): Promise<T> {
|
|
63
|
-
invariant(
|
|
64
|
-
!this.bodyUsed,
|
|
65
|
-
'Failed to execute "json" on "IsomorphicRequest": body buffer already read'
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
this._bodyUsed = true
|
|
69
|
-
const text = decodeBuffer(this._body)
|
|
70
|
-
return JSON.parse(text)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public async arrayBuffer(): Promise<ArrayBuffer> {
|
|
74
|
-
invariant(
|
|
75
|
-
!this.bodyUsed,
|
|
76
|
-
'Failed to execute "arrayBuffer" on "IsomorphicRequest": body buffer already read'
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
this._bodyUsed = true
|
|
80
|
-
return this._body
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public clone(): IsomorphicRequest {
|
|
84
|
-
return new IsomorphicRequest(this)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { bodyBufferToString } from './bodyBufferToString'
|
|
2
|
-
|
|
3
|
-
test('given a utf8 buffer returns utf8 string', () => {
|
|
4
|
-
const utfBuffer = Buffer.from('one')
|
|
5
|
-
expect(bodyBufferToString(utfBuffer)).toEqual('one')
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
test('given a hex buffer returns a hex buffer', () => {
|
|
9
|
-
const hexBuffer = Buffer.from('7468697320697320612074c3a97374', 'hex')
|
|
10
|
-
expect(bodyBufferToString(hexBuffer)).toEqual('this is a tést')
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('given a non-utf buffer returns a hex buffer', () => {
|
|
14
|
-
const anyBuffer = Buffer.from('tést', 'latin1')
|
|
15
|
-
expect(bodyBufferToString(anyBuffer)).toEqual('74e97374')
|
|
16
|
-
})
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export function bodyBufferToString(buffer: Buffer): string {
|
|
2
|
-
const utfEncodedBuffer = buffer.toString('utf8')
|
|
3
|
-
const bufferCopy = Buffer.from(utfEncodedBuffer)
|
|
4
|
-
const isUtf8 = bufferCopy.equals(buffer)
|
|
5
|
-
|
|
6
|
-
return isUtf8 ? utfEncodedBuffer : buffer.toString('hex')
|
|
7
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { concatChunkToBuffer } from './concatChunkToBuffer'
|
|
2
|
-
|
|
3
|
-
test('returns a concatenation result of two buffers', () => {
|
|
4
|
-
const nextBuffers = concatChunkToBuffer(Buffer.from('two'), [
|
|
5
|
-
Buffer.from('one'),
|
|
6
|
-
])
|
|
7
|
-
expect(nextBuffers.map((buffer) => buffer.toString())).toEqual(['one', 'two'])
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
test('concatencates a given string to the buffer', () => {
|
|
11
|
-
const nextBuffers = concatChunkToBuffer('two', [Buffer.from('one')])
|
|
12
|
-
expect(nextBuffers.map((buffer) => buffer.toString())).toEqual(['one', 'two'])
|
|
13
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment node
|
|
3
|
-
*/
|
|
4
|
-
import { bufferFrom } from './bufferFrom'
|
|
5
|
-
|
|
6
|
-
test('returns the same Uint8Array instance as Buffer.from', () => {
|
|
7
|
-
const init = 'hello world'
|
|
8
|
-
const buffer = bufferFrom(init)
|
|
9
|
-
const rawBuffer = Buffer.from(init)
|
|
10
|
-
expect(Buffer.compare(buffer, rawBuffer)).toBe(0)
|
|
11
|
-
})
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert a given string into a `Uint8Array`.
|
|
3
|
-
* We don't use `TextEncoder` because it's unavailable in some environments.
|
|
4
|
-
*/
|
|
5
|
-
export function bufferFrom(init: string): Uint8Array {
|
|
6
|
-
const encodedString = encodeURIComponent(init)
|
|
7
|
-
const binaryString = encodedString.replace(/%([0-9A-F]{2})/g, (_, char) => {
|
|
8
|
-
return String.fromCharCode(('0x' + char) as any)
|
|
9
|
-
})
|
|
10
|
-
const buffer = new Uint8Array(binaryString.length)
|
|
11
|
-
Array.prototype.forEach.call(binaryString, (char, index) => {
|
|
12
|
-
buffer[index] = char.charCodeAt(0)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
return buffer
|
|
16
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Headers } from 'headers-polyfill'
|
|
2
|
-
import { toIsoResponse } from './toIsoResponse'
|
|
3
|
-
|
|
4
|
-
test('returns a well-formed empty response', () => {
|
|
5
|
-
expect(toIsoResponse({})).toEqual({
|
|
6
|
-
status: 200,
|
|
7
|
-
statusText: 'OK',
|
|
8
|
-
headers: new Headers(),
|
|
9
|
-
})
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
test('uses fallback values for the missing response properties', () => {
|
|
13
|
-
expect(toIsoResponse({ status: 301, body: 'text-body' })).toEqual({
|
|
14
|
-
status: 301,
|
|
15
|
-
statusText: 'OK',
|
|
16
|
-
headers: new Headers(),
|
|
17
|
-
body: 'text-body',
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
test('returns a full response as-is, converting the headers', () => {
|
|
22
|
-
expect(
|
|
23
|
-
toIsoResponse({
|
|
24
|
-
status: 301,
|
|
25
|
-
statusText: 'Custom Status',
|
|
26
|
-
headers: {
|
|
27
|
-
'X-Allowed': 'yes',
|
|
28
|
-
},
|
|
29
|
-
body: 'text-body',
|
|
30
|
-
})
|
|
31
|
-
).toEqual({
|
|
32
|
-
status: 301,
|
|
33
|
-
statusText: 'Custom Status',
|
|
34
|
-
headers: new Headers({
|
|
35
|
-
'X-Allowed': 'yes',
|
|
36
|
-
}),
|
|
37
|
-
body: 'text-body',
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { objectToHeaders } from 'headers-polyfill'
|
|
2
|
-
import { IsomorphicResponse, MockedResponse } from '../glossary'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Converts a given mocked response object into an isomorphic response.
|
|
6
|
-
*/
|
|
7
|
-
export function toIsoResponse(response: MockedResponse): IsomorphicResponse {
|
|
8
|
-
return {
|
|
9
|
-
status: response.status ?? 200,
|
|
10
|
-
statusText: response.statusText || 'OK',
|
|
11
|
-
headers: objectToHeaders(response.headers || {}),
|
|
12
|
-
body: response.body,
|
|
13
|
-
}
|
|
14
|
-
}
|