New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: change cy.intercept override behavior #14543
Conversation
Thanks for taking the time to open a PR!
|
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
9a46454
to
9bcaf32
Compare
38763e7
to
a8f51b2
Compare
@flotwig I think I have found a regression with this patch against the RWA with request modifications not being honored in some way. In v6.6.0, when I remove the cy.intercept("GET", "/notifications", (req) => {
delete req.headers["if-none-match"];
}).as("getNotifications"); Subsequent Under this branch, the response is |
As of commit, c52133c |
3456757
to
762d6eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
The 2 failing stages are currently failing in 7.0-release as well, merging. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
User facing changelog
cy.intercept
are now matched starting with the most-recently-defined request interceptor. This allows users to override request handlers by callingcy.intercept
again. This matches the previous behavior that was standard incy.route
.req
object forcy.intercept
:before:response
,response
,after:response
.req.continue(cb)
) supplied tocy.intercept
will be called in reverse order untilres.send
is called or until there are no more response handlers.middleware
, has been added to theRouteMatcher
type. Iftrue
, the supplied request handler will be called before any non-middleware request handlers.req.continue(cb)
, is available on request objects yielded bycy.intercept
. It is functionally the same asreq.reply(cb)
- the request will stop propagating to other event handlers, will be sent outgoing, and the response will be handled bycb
.cy.intercept
can now be called with a new overload:cy.intercept(url, routeMatcher, handler)
.routeMatcher
will be merged withurl
, and the handler is required.response.body
would be incorrect after stubbing a response usingres.send({ fixture })
in areq.continue
callback or abefore:response
orresponse
handler.Additional details
See changes to
net_stubbing_spec
for new + updated tests.How has the user experience changed?
RouteMatcher
option:middleware: boolean
middleware: true
will be called in the order they are defined and chained.middleware: true
, only dynamic handlers are supported - makes no sense to supportcy.intercept({ middleware: true }, staticResponse)
req
now emits events (regardless ofmiddleware
setting)req
:cypress/packages/net-stubbing/lib/external-types.ts
Lines 207 to 226 in 762d6eb
req.continue(cb)
has been added.req.reply(cb)
still works.cy.intercept
has been added, to allow users to more easily do things likecy.intercept('/url', { middleware: true }, ...)
to set middleware, etc:cypress/packages/net-stubbing/lib/external-types.ts
Lines 459 to 470 in 042050c
PR Tasks
cypress-documentation
? docs: cy.intercept 7.0 changes cypress-documentation#3715type definitions
?cypress.schema.json
?