Skip to content

Commit

Permalink
fix(fetch): follow mocked redirect responses (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito authored Sep 8, 2024
1 parent 8a46465 commit f5785bf
Show file tree
Hide file tree
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
Expand Up @@ -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",
Expand Down
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
Expand Up @@ -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(
Expand All @@ -43,7 +43,7 @@ export function createFallbackRequestListener(
)

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

Expand Down
31 changes: 17 additions & 14 deletions src/node/SetupServerCommonApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f5785bf

Please sign in to comment.