Skip to content

Commit

Permalink
fix(fetch): follow mocked redirect responses (#2268)
Browse files Browse the repository at this point in the history
kettanaito authored Sep 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8a46465 commit f5785bf
Showing 4 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -137,7 +137,7 @@
"@bundled-es-modules/statuses": "^1.0.1",
"@bundled-es-modules/tough-cookie": "^0.1.6",
"@inquirer/confirm": "^3.0.0",
"@mswjs/interceptors": "^0.29.0",
"@mswjs/interceptors": "^0.35.0",
"@open-draft/until": "^2.1.0",
"@types/cookie": "^0.6.0",
"@types/statuses": "^2.0.4",
16 changes: 10 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ export function createFallbackRequestListener(
interceptors: [new FetchInterceptor(), new XMLHttpRequestInterceptor()],
})

interceptor.on('request', async ({ request, requestId }) => {
interceptor.on('request', async ({ request, requestId, controller }) => {
const requestCloneForLogs = request.clone()

const response = await handleRequest(
@@ -43,7 +43,7 @@ export function createFallbackRequestListener(
)

if (response) {
request.respondWith(response)
controller.respondWith(response)
}
})

31 changes: 17 additions & 14 deletions src/node/SetupServerCommonApi.ts
Original file line number Diff line number Diff line change
@@ -52,21 +52,24 @@ export class SetupServerCommonApi
* Subscribe to all requests that are using the interceptor object
*/
private init(): void {
this.interceptor.on('request', async ({ request, requestId }) => {
const response = await handleRequest(
request,
requestId,
this.handlersController.currentHandlers(),
this.resolvedOptions,
this.emitter,
)

if (response) {
request.respondWith(response)
}
this.interceptor.on(
'request',
async ({ request, requestId, controller }) => {
const response = await handleRequest(
request,
requestId,
this.handlersController.currentHandlers(),
this.resolvedOptions,
this.emitter,
)

return
})
if (response) {
controller.respondWith(response)
}

return
},
)

this.interceptor.on('unhandledException', ({ error }) => {
if (error instanceof InternalError) {

0 comments on commit f5785bf

Please sign in to comment.