简体   繁体   中英

How to disable blockedHosts urls from Cypress test runner and console logs?

I have the following trackers blocked during Cypress tests. Cypress keeps on logging these urls in the test runner logs which is ugly and interferes with other useful log messages and assertions and increases scrolling/searching effort from the user.

Is there a way to disable logging of these urls in the test runner and console?

//cypress.json
{ ...
  "blockHosts": [
    "*hsappstatic.net",
    "*hubspot.com",
    "*hs-banner.com",
    "*usemessages.com",
    "*newrelic.com",
    "*nr-data.net",
    "*datadoghq.com"
  ],
  ...
}

CypressTestRunnerLogs

I was able to solve this by

//cypress/support/index.js

Cypress.Server.defaults({
  ignore: xhr => {
    return Cypress.config().blockHosts.some(blockedHost =>  // get blockHosts from cypress.json using Cypress.config()
      Cypress.minimatch(new URL(xhr.url).host, blockedHost)  // if current url matches any blockedHost item, return true
    )
  }
})

more details on https://github.com/cypress-io/cypress/discussions/16536

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM