Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: print response log only when response arrives (#1392)
- Loading branch information
1 parent
ed05a73
commit 638fad9
Showing
11 changed files
with
110 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { flattenHeadersObject, headersToObject } from 'headers-polyfill' | ||
import type { SerializedResponse } from '../../setupWorker/glossary' | ||
|
||
export function serializeResponse(source: Response): SerializedResponse<any> { | ||
return { | ||
status: source.status, | ||
statusText: source.statusText, | ||
headers: flattenHeadersObject(headersToObject(source.headers)), | ||
body: source.body, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { encodeBuffer, IsomorphicResponse } from '@mswjs/interceptors' | ||
|
||
const noop = () => { | ||
throw new Error('Not implemented') | ||
} | ||
|
||
export function createResponseFromIsomorphicResponse( | ||
response: IsomorphicResponse, | ||
): Response { | ||
return { | ||
...response, | ||
ok: response.status >= 200 && response.status < 300, | ||
url: '', | ||
type: 'default', | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: response.headers, | ||
body: new ReadableStream(), | ||
redirected: response.headers.get('Location') != null, | ||
async text() { | ||
return response.body || '' | ||
}, | ||
async json() { | ||
return JSON.parse(response.body || '') | ||
}, | ||
async arrayBuffer() { | ||
return encodeBuffer(response.body || '') | ||
}, | ||
bodyUsed: false, | ||
formData: noop, | ||
blob: noop, | ||
clone: noop, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters