Skip to content

Commit

Permalink
fix(net-stubbing): do not fireChangeEvent for non-existing routes (#9425
Browse files Browse the repository at this point in the history
)
  • Loading branch information
flotwig authored Dec 3, 2020
1 parent 9543a42 commit c42667e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
54 changes: 54 additions & 0 deletions packages/driver/cypress/integration/commands/net_stubbing_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,60 @@ describe('network stubbing', { retries: 2 }, function () {
})
})

context('events', function () {
// @see https://github.com/cypress-io/cypress/issues/9170
it('gracefully handles request received without a known route', function () {
cy.intercept('/valid.json', (req) => {
req.reply({ bad: 'should not be received' })
})
.then(() => {
const routeIds = _.keys(state('routes'))

// delete the driver-side route - the server-side route will still exist and cause an event
// to be emitted to the driver
delete state('routes')[routeIds[0]]
expect(state('routes')).to.deep.eq({})

return $.get('/fixtures/valid.json')
})
.then((body) => {
expect(body).to.include({ foo: 1 })
})
})

it('gracefully handles response received without a known route', function () {
cy.intercept('/valid.json', (req) => {
state('routes', {})

req.reply((res) => {
res.send({ bad: 'should not be received' })
})
})
.then(() => {
return $.get('/fixtures/valid.json')
})
.then((body) => {
expect(body).to.include({ foo: 1 })
})
})

it('gracefully handles response completed without a known route', function () {
cy.intercept('/valid.json', (req) => {
req.reply((res) => {
state('routes', {})

res.send({ bar: 2 })
})
})
.then(() => {
return $.get('/fixtures/valid.json')
})
.then((body) => {
expect(body).to.include({ bar: 2 })
})
})
})

context('network handling', function () {
// @see https://github.com/cypress-io/cypress/issues/8497
it('can load transfer-encoding: chunked redirects', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ export const onRequestReceived: HandlerFn<NetEventFrames.HttpRequestReceived> =

continueSent = true

if (request) {
request.state = 'Intercepted'
}

if (continueFrame) {
// copy changeable attributes of userReq to req in frame
// @ts-ignore
Expand All @@ -149,7 +145,10 @@ export const onRequestReceived: HandlerFn<NetEventFrames.HttpRequestReceived> =
emitNetEvent('http:request:continue', continueFrame)
}

request.log.fireChangeEvent()
if (request) {
request.state = 'Intercepted'
request.log && request.log.fireChangeEvent()
}
}

if (!route) {
Expand Down

2 comments on commit c42667e

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c42667e Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.1.0/circle-develop-c42667e707c89aeaf9a46cc3afa3d9b3f2c2422d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c42667e Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.1.0/circle-develop-c42667e707c89aeaf9a46cc3afa3d9b3f2c2422d/cypress.tgz

Please sign in to comment.