diff --git a/packages/driver/cypress/e2e/commands/net_stubbing.cy.ts b/packages/driver/cypress/e2e/commands/net_stubbing.cy.ts index 7b63accba1bb..9fc262eaef28 100644 --- a/packages/driver/cypress/e2e/commands/net_stubbing.cy.ts +++ b/packages/driver/cypress/e2e/commands/net_stubbing.cy.ts @@ -1748,9 +1748,12 @@ describe('network stubbing', { retries: 15 }, function () { delay: 5000, }).as('create') - cy.wrap(fetch('/post-only', { - method: 'POST', // *GET, POST, PUT, DELETE, etc. - })) + cy.then(() => { + // @ts-disable:no-floating-promises + fetch('/post-only', { + method: 'POST', // *GET, POST, PUT, DELETE, etc. + }) + }) cy.wait('@create', { timeout: 500 }) }) diff --git a/packages/driver/src/cy/net-stubbing/events/before-request.ts b/packages/driver/src/cy/net-stubbing/events/before-request.ts index 11fd13279dd8..8c0cc584e3d6 100644 --- a/packages/driver/src/cy/net-stubbing/events/before-request.ts +++ b/packages/driver/src/cy/net-stubbing/events/before-request.ts @@ -34,7 +34,7 @@ export const onBeforeRequest: HandlerFn = (Cypre req.responseTimeout = Cypress.config('responseTimeout') const reqClone = _.cloneDeep(req) - const subscribe = async (eventName, handler) => { + const subscribe = (eventName, handler) => { const subscription: Subscription = { id: _.uniqueId('Subscription'), routeId, @@ -49,7 +49,8 @@ export const onBeforeRequest: HandlerFn = (Cypre debug('created request subscription %o', { eventName, request, subscription, handler }) - await emitNetEvent('subscribe', { requestId, subscription } as NetEvent.ToServer.Subscribe) + // tslint:disable-next-line:no-floating-promises + emitNetEvent('subscribe', { requestId, subscription } as NetEvent.ToServer.Subscribe) } const getCanonicalInterception = (): Interception => { @@ -165,8 +166,8 @@ export const onBeforeRequest: HandlerFn = (Cypre queryObj = createQueryObject() queryProxy = createQueryProxy(queryObj) }, - // @ts-expect-error: TODO: fix this - async on (eventName, handler) { + // tslint:disable-next-line:no-floating-promises + on (eventName, handler) { if (!validEvents.includes(eventName)) { $errUtils.throwErrByPath('net_stubbing.request_handling.unknown_event', { args: { @@ -180,11 +181,12 @@ export const onBeforeRequest: HandlerFn = (Cypre $errUtils.throwErrByPath('net_stubbing.request_handling.event_needs_handler') } - await subscribe(eventName, handler) + // tslint:disable-next-line:no-floating-promises + subscribe(eventName, handler) return userReq }, - async continue (responseHandler?) { + continue (responseHandler?) { if (resolved) { return $errUtils.throwErrByPath('net_stubbing.request_handling.completion_called_after_resolved', { args: { cmd: 'continue' } }) } @@ -204,7 +206,8 @@ export const onBeforeRequest: HandlerFn = (Cypre } // allow `req` to be sent outgoing, then pass the response body to `responseHandler` - await subscribe('response:callback', responseHandler) + // tslint:disable-next-line:no-floating-promises + subscribe('response:callback', responseHandler) return finish(true) }, diff --git a/packages/driver/src/cy/net-stubbing/events/index.ts b/packages/driver/src/cy/net-stubbing/events/index.ts index 0724d2d49fd1..3ac313906256 100644 --- a/packages/driver/src/cy/net-stubbing/events/index.ts +++ b/packages/driver/src/cy/net-stubbing/events/index.ts @@ -55,8 +55,9 @@ export function registerEvents (Cypress: Cypress.Cypress, cy: Cypress.cy) { }) } - async function sendStaticResponse (requestId: string, staticResponse: StaticResponse) { - await emitNetEvent('send:static:response', { + function sendStaticResponse (requestId: string, staticResponse: StaticResponse) { + // tslint:disable-next-line:no-floating-promises + emitNetEvent('send:static:response', { requestId, staticResponse: getBackendStaticResponse(staticResponse), }) @@ -93,7 +94,8 @@ export function registerEvents (Cypress: Cypress.Cypress, cy: Cypress.cy) { if (!route) { if (frame.subscription.await) { // route not found, just resolve so the request can continue - await emitResolved(frame.data) + // tslint:disable-next-line:no-floating-promises + emitResolved(frame.data) } return