cypress
cypress copied to clipboard
Support dynamically disabling request logs via `cy.intercept()`
What would you like?
Add the ability to dynamically disable request logs in cy.intercept(), like so:
cy.intercept('/foo', (req) => {
req.log = false
}
Why is this needed?
#25547 adds the ability to control log via StaticResponseWithOptions. However, this can only be done statically, not dynamically via an interceptor function.
The reasons why it was done this way are detailed in the original ClickUp initiative. TL;DR: dynamically setting log can cause a log to be hidden/shown asynchronously, which requires making some hard UI decisions about how to indicate this at each step.
Other
No response
Make sure to update the docs when this issue is closed in the future. https://github.com/cypress-io/cypress-documentation/pull/5106
Any updates on this?
It would be nice to have an option to log only when there is an error.
Other options are:
- to change the signature and move the log option to a "third" options argument (or "fourth" if method or url are passed on separately), like so:
Currently it is a bit of an odd-one-out option in the StaticResponse object. Not sure if other intercept options would qualify for this object.cy.intercept({method and/or url or RouteMatcher}, {StaticResponse or RouteHandler}, { log: false }) - to add the possibility to set the RouteHandler via an option in StaticResponse, like so:
cy.intercept({method and/or url or RouteMatcer}, { handler: (req) => { ... }, log: false })
Obviously thorough analysis is necessary to check if these signatures are not dubiously conflicting with the existing signature.
Argh, also needed this to make my logs look a bit prettier.
same here
Other options are:
* to change the signature and move the log option to a "third" options argument (or "fourth" if method or url are passed on separately), like so: ```ts cy.intercept({method and/or url or RouteMatcher}, {StaticResponse or RouteHandler}, { log: false }) ``` Currently it is a bit of an odd-one-out option in the StaticResponse object. Not sure if other intercept options would qualify for this object. * to add the possibility to set the RouteHandler via an option in StaticResponse, like so: ```ts cy.intercept({method and/or url or RouteMatcer}, { handler: (req) => { ... }, log: false }) ```Obviously thorough analysis is necessary to check if these signatures are not dubiously conflicting with the existing signature.
Wouldn't the last option you suggest also be compatible with the current signature ? The code basically has to check if the 2nd argument is a plain handler, or if it's an object with a "handler" property, and decide what to do based on that. This way there's no need to check all the codebase for conflicts, as it would be backwards-compatible. Am I missing something @verheyenkoen ?
Also in need of something like this, we are using a custom handler function to set aliases for our GraphQL requests and would like to also control the logging behavior at the same time
might be a workaround for some cases. This worked for me:
cy.intercept('/something/**', (req) => {
// redirect to local dev server
const url = new URL(req.url)
url.hostname = Cypress.env('dev_host')
url.port = Cypress.env('dev_port')
url.pathname = url.pathname.replace('/something', '')
req.url = url.toString()
})
// disable logs
cy.intercept('/something/**', { log: false })