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

feat(driver): add filtering API for request logs #22458

Closed
wants to merge 34 commits into from

Conversation

flotwig
Copy link
Contributor

@flotwig flotwig commented Jun 22, 2022

Flaky test issues:

User facing changelog

Exposed a new function, Cypress.RequestLogs.filter, which enables users to selectively enable or disable Command Log output for HTTP requests.

Additional details

Steps to test

Follow the examples below and see what gets logged when HTTP requests are made.

How has the user experience changed?

New API is available for selectively logging HTTP requests:

// disable all XHR and fetch logs
Cypress.RequestLogs.showAllXhrFetch = false

// only log the current origin's requests if they are XHRs
Cypress.RequestLogs.showAllXhrFetch = false
Cypress.RequestLogs.filter = (req) => req.resourceType === 'xhr' && req.url.startsWith(window.location.origin)

// only log the current origin's requests
Cypress.RequestLogs.showAllXhrFetch = false
Cypress.RequestLogs.filter = (req) => req.url.startsWith(window.location.origin)

// only log cy.intercept() requests, not XHRs
Cypress.RequestLogs.showAllXhrFetch = false

// disable all request logs
Cypress.RequestLogs.showAllXhrFetch = false
Cypress.RequestLogs.showAllIntercepts = false

// throws since we're not setting a function
Cypress.RequestLogs.filter = 'foo'

PR Tasks

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 22, 2022

Thanks for taking the time to open a PR!

@flotwig flotwig changed the title feat(driver): add filtering API for proxy logs feat(driver): add filtering API for network logs Jul 13, 2022
@flotwig flotwig changed the base branch from develop to release/12.0.0 November 8, 2022 20:23

context('Cypress.ProxyLogging', () => {
describe('.logInterception', () => {
it('creates a fake log for unmatched requests', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now covered by 'can ignore an intercept log' which was added above.

@cypress
Copy link

cypress bot commented Nov 15, 2022



Test summary

21664 1 1696 0Flakiness 2


Run details

Project cypress
Status Failed
Commit a79b943
Started Nov 30, 2022 6:56 PM
Ended Nov 30, 2022 7:14 PM
Duration 17:43 💡
OS Linux Debian -
Browser Multiple

View run in Cypress Dashboard ➡️


Failures

cypress/e2e/commands/waiting.cy.js Failed
1 ... > errors > throws when bar cannot resolve

Flakiness

specs_list_latest_runs.cy.ts Flakiness
1 App/Cloud Integration - Latest runs and Average duration > when no runs are recorded > shows placeholders for all visible specs
cypress-origin-communicator.cy.ts Flakiness
1 Cypress In Cypress Origin Communicator > cy.origin passivity with app interactions > passes upon test reload mid test execution

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

@flotwig flotwig changed the title feat(driver): add filtering API for network logs feat(driver): add filtering API for request logs Nov 23, 2022
@flotwig flotwig marked this pull request as ready for review November 24, 2022 00:21
@@ -0,0 +1,443 @@
import { expect } from 'chai'

describe('Request Logs', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of this file is the same as it was in proxy-logging.cy.ts, but GitHub's diff viewer doesn't seem to detect the rename.

To match the phrasing used by DevTools and elsewhere.
@@ -278,7 +278,7 @@ class $Cypress {

// TODO: Remove this after $Events functions are added to $Cypress.
// @ts-ignore
this.ProxyLogging = new ProxyLogging(this)
this.NetworkLogs = new NetworkLogs(this)
Copy link
Member

Choose a reason for hiding this comment

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

this is a much better name!

@flotwig flotwig marked this pull request as draft December 1, 2022 19:23
@mjhenkes mjhenkes deleted the branch delease/12.0.0 December 2, 2022 23:10
@mjhenkes mjhenkes closed this Dec 2, 2022
@flotwig
Copy link
Contributor Author

flotwig commented Dec 8, 2022

We will most likely not add this API for the time being. Instead, we will solve #9358 by implementing two features:

  1. Ability to match cy.intercept() by resourceType: feat: add resourceType support to cy.intercept() on req/routeMatcher #25075
  2. Ability to disable logs per-intercept

Then, users can disable the default logging like so:

cy.intercept({ resourceType: /xhr|fetch/ }, { log: false })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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