diff --git a/package.json b/package.json index 7aff13ab9..9609f927e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c9a88936c..1948cf244 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,8 +18,8 @@ dependencies: specifier: ^3.0.0 version: 3.1.1 '@mswjs/interceptors': - specifier: ^0.29.0 - version: 0.29.0 + specifier: ^0.35.0 + version: 0.35.0 '@open-draft/until': specifier: ^2.1.0 version: 2.1.0 @@ -1419,15 +1419,15 @@ packages: - utf-8-validate dev: true - /@mswjs/interceptors@0.29.0: - resolution: {integrity: sha512-eppU9TxaRS2t5IcR00nuh+36zMHcK09pyhUvWJLO1ae5+U8KL7iatUGKlLUlbxXaq3BvDjlcF0Q8Xhzyosk/xA==} + /@mswjs/interceptors@0.35.0: + resolution: {integrity: sha512-f5cHyIvm4m4g1I5x9EH1etGx0puaU0OaX2szqGRVBVgUC6aMASlOI5hbpe7tJ9l4/VWjCUu5OMraCazLZGI24A==} engines: {node: '>=18'} dependencies: '@open-draft/deferred-promise': 2.2.0 '@open-draft/logger': 0.3.0 '@open-draft/until': 2.1.0 is-node-process: 1.2.0 - outvariant: 1.4.2 + outvariant: 1.4.3 strict-event-emitter: 0.5.1 dev: false @@ -1459,7 +1459,7 @@ packages: resolution: {integrity: sha512-X2g45fzhxH238HKO4xbSr7+wBS8Fvw6ixhTDuvLd5mqh6bJJCFAPwU9mPDxbcrRtfxv4u5IHCEH77BmxvXmmxQ==} dependencies: is-node-process: 1.2.0 - outvariant: 1.4.2 + outvariant: 1.4.3 dev: false /@open-draft/test-server@0.4.2: @@ -6284,6 +6284,10 @@ packages: /outvariant@1.4.2: resolution: {integrity: sha512-Ou3dJ6bA/UJ5GVHxah4LnqDwZRwAmWxrG3wtrHrbGnP4RnLCtA64A4F+ae7Y8ww660JaddSoArUR5HjipWSHAQ==} + /outvariant@1.4.3: + resolution: {integrity: sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA==} + dev: false + /p-limit@2.3.0: resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==} engines: {node: '>=6'} diff --git a/src/browser/setupWorker/start/createFallbackRequestListener.ts b/src/browser/setupWorker/start/createFallbackRequestListener.ts index e7376e955..a87e5da81 100644 --- a/src/browser/setupWorker/start/createFallbackRequestListener.ts +++ b/src/browser/setupWorker/start/createFallbackRequestListener.ts @@ -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) } }) diff --git a/src/node/SetupServerCommonApi.ts b/src/node/SetupServerCommonApi.ts index 85c534d31..97a738b56 100644 --- a/src/node/SetupServerCommonApi.ts +++ b/src/node/SetupServerCommonApi.ts @@ -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) {