fix: don't wrap errors thrown by cy.intercept req/res handlers (#15769)

This commit is contained in:
Zach Bloomquist
2021-04-05 11:25:56 -04:00
committed by GitHub
parent e4f5bb7181
commit 9360ae12e4
5 changed files with 6 additions and 54 deletions
@@ -1659,9 +1659,8 @@ describe('network stubbing', { retries: { runMode: 2, openMode: 0 } }, function
})
it('fails test if an exception is thrown in req handler', function (done) {
testFail((err2) => {
expect(err2.message).to.contain('A request callback passed to `cy.intercept()` threw an error while intercepting a request')
.and.contain(err.message)
cy.on('fail', (err2) => {
expect(err2).to.eq(err)
done()
})
@@ -1675,8 +1674,7 @@ describe('network stubbing', { retries: { runMode: 2, openMode: 0 } }, function
it('fails test if req.reply is called with an invalid StaticResponse', function (done) {
testFail((err) => {
expect(err.message).to.contain('A request callback passed to `cy.intercept()` threw an error while intercepting a request')
.and.contain('must be a number between 100 and 999 (inclusive).')
expect(err.message).to.contain('must be a number between 100 and 999 (inclusive).')
done()
})
@@ -2291,10 +2289,8 @@ describe('network stubbing', { retries: { runMode: 2, openMode: 0 } }, function
})
it('fails test if an exception is thrown in res handler', function (done) {
testFail((err2) => {
expect(err2.message).to.contain('A response handler threw an error while intercepting a response')
.and.contain(err.message)
cy.on('fail', (err2) => {
expect(err2).to.eq(err)
done()
})
@@ -2313,8 +2309,7 @@ describe('network stubbing', { retries: { runMode: 2, openMode: 0 } }, function
it('fails test if res.send is called with an invalid StaticResponse', function (done) {
testFail((err) => {
expect(err.message).to.contain('A response handler threw an error while intercepting a response')
.and.contain('must be a number between 100 and 999 (inclusive).')
expect(err.message).to.include('must be a number between 100 and 999 (inclusive).')
done()
})
@@ -266,15 +266,6 @@ export const onBeforeRequest: HandlerFn<CyHttpMessages.IncomingRequest> = (Cypre
return Bluebird.try(() => {
return userHandler(userReq)
})
.catch((err) => {
$errUtils.throwErrByPath('net_stubbing.request_handling.cb_failed', {
args: {
err,
req,
route: route.options,
},
})
})
.timeout(timeout)
.catch(Bluebird.TimeoutError, (err) => {
if (Cypress.state('test') !== curTest) {
@@ -126,16 +126,6 @@ export const onResponse: HandlerFn<CyHttpMessages.IncomingResponse> = async (Cyp
return Bluebird.try(() => {
return userHandler!(userRes)
})
.catch((err) => {
$errUtils.throwErrByPath('net_stubbing.response_handling.cb_failed', {
args: {
err,
req: request.request,
route: _.get(getRoute(routeId), 'options'),
res,
},
})
})
.timeout(timeout)
.catch(Bluebird.TimeoutError, (err) => {
if (Cypress.state('test') !== curTest) {
@@ -953,16 +953,6 @@ module.exports = {
handler_required: `When invoking ${cmd('intercept')} with a \`RouteMatcher\` as the second parameter, a handler (function or \`StaticResponse\`) must be specified as the third parameter. If you intended to stub out a response body by passing an object as the 2nd parameter, pass an object with a \`body\` property containing the desired response body instead.`,
},
request_handling: {
cb_failed: ({ err, req, route }) => {
return cyStripIndent(`\
A request callback passed to ${cmd('intercept')} threw an error while intercepting a request:
${err.message}
Route: ${format(route)}
Intercepted request: ${format(req)}`, 10)
},
cb_timeout: ({ timeout, req, route }) => {
return cyStripIndent(`\
A request callback passed to ${cmd('intercept')} timed out after returning a Promise that took more than the \`defaultCommandTimeout\` of \`${timeout}ms\` to resolve.
@@ -1011,18 +1001,6 @@ module.exports = {
},
},
response_handling: {
cb_failed: ({ err, req, res, route }) => {
return cyStripIndent(`\
A response handler threw an error while intercepting a response:
${err.message}
Route: ${format(route)}
Intercepted request: ${format(req)}
Intercepted response: ${format(res)}`, 10)
},
cb_timeout: ({ timeout, req, res, route }) => {
return cyStripIndent(`\
A response handler timed out after returning a Promise that took more than the \`defaultCommandTimeout\` of \`${timeout}ms\` to resolve.
@@ -275,7 +275,6 @@ describe('errors ui', () => {
file,
column: 22,
message: [
'A request callback passed to cy.intercept() threw an error while intercepting a request',
`expected 'a' to equal 'b'`,
],
notInMessage: [
@@ -288,7 +287,6 @@ describe('errors ui', () => {
column: 24,
codeFrameText: '.reply(()=>{',
message: [
'A response handler threw an error while intercepting a response:',
`expected 'b' to equal 'c'`,
],
notInMessage: [