Skip to content
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

Is there an equivalent of cy.server({ignore: (xhr) => bool}) to disable logging, after moving to cy.intercept? #9358

Closed
lephuongbg opened this issue Nov 27, 2020 · 14 comments
Assignees
Labels
topic: cy.intercept() type: enhancement Requested enhancement of existing feature

Comments

@lephuongbg
Copy link

What would you like?

I would like to continue to be able to disable logging of some routes after moving to cy.intercept().

Why is this needed?

A nice side-effect of calling cy.server({ignore: (xhr) => bool}) to disable stubbing is that it also disables logging of matching routes. This helps decluttering the logs when we're running interactive tests.

Examples are ping-pong requests with back-end server, webpack-dev-server's sockjs route, etc.

@jennifer-shehane jennifer-shehane added topic: cy.intercept() type: enhancement Requested enhancement of existing feature labels Nov 30, 2020
@cypress-bot cypress-bot bot added the stage: proposal 💡 No work has been done of this issue label Nov 30, 2020
@Yethal
Copy link

Yethal commented Dec 3, 2020

Another reason one might want to disable request logging is to declutter the test reports. For example the cypress-allure-plugin by default creates a separate test step from every Cypress command ran which cause the resulting report to be unreadable if the application under test makes a ton of http calls under the hood. Ideally we should be able to turn the loggin on and off programmatically so that requests are logged when running tests in interactive mode but hidden when tests are ran on CI

@tonivj5
Copy link

tonivj5 commented Dec 23, 2020

I'm looking for an equivalent of cy.server's force404 option, without this option or similar behavior I can't move to cy.intercept... 😞

@volkanogretmen
Copy link

volkanogretmen commented Jan 6, 2021

I'm looking for an equivalent of cy.server's force404 option, without this option or similar behavior I can't move to cy.intercept... 😞

As far as I can tell, that's just the statusCode option you can pass on.

cy.intercept('POST', '/upload/', { statusCode: 404 }).as('upload');

All XHR's matching /upload/ will now be forced to a 404.

https://docs.cypress.io/api/commands/intercept.html#method-string

@Torresangl925
Copy link

Stop hiding fools

@slikts
Copy link

slikts commented Sep 29, 2021

If cy.intercept() is used for mocking, for example, assets and not just API calls, it can flood the command log and make it difficult to overview, so a feature to hide certain intercepted requests would be very nice to have for this use case.

@simenbrekken
Copy link

simenbrekken commented Oct 15, 2021

I ran into this problem myself and after a deep-dive into Cypress' logging internals I discovered a novel workaround, simply hide fetch/XHR command log entries with CSS.

https://gist.github.com/simenbrekken/3d2248f9e50c1143bf9dbe02e67f5399

@BiancaBobescu
Copy link

BiancaBobescu commented Nov 10, 2021

Another reason one might want to disable request logging is to declutter the test reports. For example the cypress-allure-plugin by default creates a separate test step from every Cypress command ran which cause the resulting report to be unreadable if the application under test makes a ton of http calls under the hood. Ideally we should be able to turn the loggin on and off programmatically so that requests are logged when running tests in interactive mode but hidden when tests are ran on CI

Did you find a solution for removing these request logs in the report with cypress-allure-plugin?

@secretwpn
Copy link

Just to add to the original question: we are using SignalR and it is constantly checking the connection state, thus filling the logs with hubs/hubName/negotiate... making them nearly unusable

@NEETweeb
Copy link

Stop hiding fools

Oi! Be nice.

@stringTrimmerMm
Copy link

stringTrimmerMm commented Mar 24, 2022

One workaround that might apply to some cases: if you have access to change the code of the application under test, you can make use of window.Cypress
https://docs.cypress.io/faq/questions/using-cypress-faq#Is-there-any-way-to-detect-if-my-app-is-running-under-Cypress

For instance the app I am working on embeds Microsoft Clarity (among other 3rd party user tracking tools), which does frequent xhr posts (polluting Cypress's command log). So I changed the app to not include Clarity when running under Cypress. Technically in my case Clarity was being pulled in via Google Tag Manager which I also didn't care to have active while testing with Cypress so my solution was something like:
function initializeTrackers() { if (window.Cypress) return; GoogleTagManager.initialize(); ... }
I'm sure you could get more fancy if you sometimes DO want those things running while testing.

@Zwimber
Copy link

Zwimber commented Jun 5, 2022

The solution of @cie works nicely in the latest version 10.0.2. Found here

It's also really easy to modify to your specific needs, simple example:

const cypressLogOriginal = Cypress.log
const cypressLogDomainsHidden = ['fontawesome.com']
Cypress.log = function (opts, ...other) {
	const logFetchIs = ['fetch'].includes(opts.displayName)
	const logFetchDomainMatch = logFetchIs && cypressLogDomainsHidden.find((d) => opts.url.includes(d))
	if (logFetchDomainMatch) return
    
	return cypressLogOriginal(opts, ...other)
}

@flotwig flotwig self-assigned this Jun 22, 2022
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress and removed stage: work in progress stage: needs review The PR code is done & tested, needs review labels Jun 22, 2022
@goska-malaga
Copy link

that would really be useful as an option, I need that on cy.visit in some cases and definitely on cy.reload, the log is not workable right now

@flotwig
Copy link
Contributor

flotwig commented Dec 15, 2022

Hey folks, I am consolidating this issue with #7362, please follow that issue for updates.

@flotwig flotwig closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 20, 2022

Released in 12.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.2.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Dec 20, 2022
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cy.intercept() type: enhancement Requested enhancement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.