diff --git a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts index 7cd7eaf505ed..20c24b39d745 100644 --- a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts +++ b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts @@ -1296,7 +1296,7 @@ describe('network stubbing', function () { it('fails test if network error occurs retrieving response and response is intercepted', function (done) { cy.on('fail', (err) => { expect(err.message) - .to.contain('req.reply() was provided a callback to intercept the upstream response, but a network error occurred while making the request:') + .to.contain('\`req.reply()\` was provided a callback to intercept the upstream response, but a network error occurred while making the request:') .and.contain('Error: connect ECONNREFUSED 127.0.0.1:3333') done() diff --git a/packages/driver/src/cy/net-stubbing/events/request-complete.ts b/packages/driver/src/cy/net-stubbing/events/request-complete.ts index b687a0e75302..846c3c18a5b7 100644 --- a/packages/driver/src/cy/net-stubbing/events/request-complete.ts +++ b/packages/driver/src/cy/net-stubbing/events/request-complete.ts @@ -1,3 +1,4 @@ +import { get } from 'lodash' import { NetEventFrames } from '@packages/net-stubbing/lib/types' import { errByPath, makeErrFromObj } from '../../../cypress/error_utils' import { HandlerFn } from './' @@ -16,7 +17,7 @@ export const onRequestComplete: HandlerFn = const err = errByPath(`net_stubbing.request_error.${errorName}`, { innerErr: makeErrFromObj(frame.error), req: request.request, - route: getRoute(frame.routeHandlerId), + route: get(getRoute(frame.routeHandlerId), 'options'), }) request.state = 'Errored' diff --git a/packages/driver/src/cy/net-stubbing/events/request-received.ts b/packages/driver/src/cy/net-stubbing/events/request-received.ts index b529d603be6b..953b63b59ade 100644 --- a/packages/driver/src/cy/net-stubbing/events/request-received.ts +++ b/packages/driver/src/cy/net-stubbing/events/request-received.ts @@ -107,11 +107,11 @@ export const onRequestReceived: HandlerFn = ...req, reply (responseHandler, maybeBody?, maybeHeaders?) { if (resolved) { - return $errUtils.throwErrByPath('net_stubbing.request_handling.reply_called_after_resolved', { args: { route: route.options, req } }) + return $errUtils.throwErrByPath('net_stubbing.request_handling.reply_called_after_resolved') } if (replyCalled) { - return $errUtils.throwErrByPath('net_stubbing.request_handling.multiple_reply_calls', { args: { route: route.options, req } }) + return $errUtils.throwErrByPath('net_stubbing.request_handling.multiple_reply_calls') } replyCalled = true diff --git a/packages/driver/src/cy/net-stubbing/events/response-received.ts b/packages/driver/src/cy/net-stubbing/events/response-received.ts index cd76a1f548d9..ea5b550f38f8 100644 --- a/packages/driver/src/cy/net-stubbing/events/response-received.ts +++ b/packages/driver/src/cy/net-stubbing/events/response-received.ts @@ -124,13 +124,13 @@ export const onResponseReceived: HandlerFn }, }) }) - .finally(() => { - resolved = true - }) .then(() => { if (!sendCalled) { // user did not call send, send response userRes.send() } }) + .finally(() => { + resolved = true + }) } diff --git a/packages/driver/src/cypress/error_messages.js b/packages/driver/src/cypress/error_messages.js index bd47482681f8..3373e31a8ef1 100644 --- a/packages/driver/src/cypress/error_messages.js +++ b/packages/driver/src/cypress/error_messages.js @@ -945,10 +945,10 @@ module.exports = { net_stubbing: { invalid_static_response: ({ cmd, message, staticResponse }) => { - return stripIndent`\ + return cyStripIndent(`\ An invalid StaticResponse was supplied to \`${cmd}()\`. ${message} - You passed: ${format(staticResponse)}` + You passed: ${format(staticResponse)}`, 8) }, route2: { needs_experimental: stripIndent`\ @@ -972,67 +972,53 @@ module.exports = { }, request_handling: { cb_failed: ({ err, req, route }) => { - return stripIndent`\ + return cyStripIndent(`\ A request callback passed to ${cmd('route2')} threw an error while intercepting a request: ${err.message} Route: ${format(route)} - Intercepted request: ${format(req)}` + Intercepted request: ${format(req)}`, 10) }, cb_timeout: ({ timeout, req, route }) => { - return stripIndent`\ + return cyStripIndent(`\ A request callback passed to ${cmd('route2')} timed out after returning a Promise that took more than the \`defaultCommandTimeout\` of \`${timeout}ms\` to resolve. If the request callback is expected to take longer than \`${timeout}ms\`, increase the configured \`defaultCommandTimeout\` value. Route: ${format(route)} - Intercepted request: ${format(req)}` - }, - multiple_reply_calls: ({ route, req }) => { - return stripIndent`\ - \`req.reply()\` was called multiple times in a request handler, but a request can only be replied to once. - - Route: ${format(route)} - - Intercepted request: ${format(req)}` - }, - reply_called_after_resolved: ({ route, req }) => { - return stripIndent`\ - \`req.reply()\` was called after the request handler finished executing, but \`req.reply()\` can not be called after the request has been passed on. - - Route: ${format(route)} - - Intercepted request: ${format(req)}` + Intercepted request: ${format(req)}`, 10) }, + multiple_reply_calls: `\`req.reply()\` was called multiple times in a request handler, but a request can only be replied to once.`, + reply_called_after_resolved: `\`req.reply()\` was called after the request handler finished executing, but \`req.reply()\` can not be called after the request has been passed on.`, }, request_error: { network_error: ({ innerErr, req, route }) => { - return stripIndent`\ + return cyStripIndent(`\ \`req.reply()\` was provided a callback to intercept the upstream response, but a network error occurred while making the request: ${normalizedStack(innerErr)} Route: ${format(route)} - Intercepted request: ${format(req)}` + Intercepted request: ${format(req)}`, 10) }, timeout: ({ innerErr, req, route }) => { - return stripIndent`\ + return cyStripIndent(`\ \`req.reply()\` was provided a callback to intercept the upstream response, but the request timed out after the \`responseTimeout\` of \`${req.responseTimeout}ms\`. ${normalizedStack(innerErr)} Route: ${format(route)} - Intercepted request: ${format(req)}` + Intercepted request: ${format(req)}`, 10) }, }, response_handling: { cb_failed: ({ err, req, res, route }) => { - return stripIndent`\ + return cyStripIndent(`\ A response callback passed to \`req.reply()\` threw an error while intercepting a response: ${err.message} @@ -1041,10 +1027,10 @@ module.exports = { Intercepted request: ${format(req)} - Intercepted response: ${format(res)}` + Intercepted response: ${format(res)}`, 10) }, cb_timeout: ({ timeout, req, res, route }) => { - return stripIndent`\ + return cyStripIndent(`\ A response callback passed to \`req.reply()\` timed out after returning a Promise that took more than the \`defaultCommandTimeout\` of \`${timeout}ms\` to resolve. If the response callback is expected to take longer than \`${timeout}ms\`, increase the configured \`defaultCommandTimeout\` value. @@ -1053,19 +1039,19 @@ module.exports = { Intercepted request: ${format(req)} - Intercepted response: ${format(res)}` + Intercepted response: ${format(res)}`, 10) }, multiple_send_calls: ({ res }) => { - return stripIndent`\ + return cyStripIndent(`\ \`res.send()\` was called multiple times in a response handler, but the response can only be sent once. - Response: ${format(res)}` + Response: ${format(res)}`, 10) }, send_called_after_resolved: ({ res }) => { - return stripIndent`\ + return cyStripIndent(`\ \`res.send()\` was called after the response handler finished executing, but \`res.send()\` can not be called after the response has been passed on. - Intercepted response: ${format(res)}` + Intercepted response: ${format(res)}`, 10) }, }, },