Skip to content

Commit

Permalink
Update BlockHosts.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dmundra authored Nov 26, 2024
1 parent f63d8c4 commit 0e99d10
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/examples/BlockHosts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ The most common host you want to block in the tests in Google Analytics. To do t
'*nr-data.net',
'*youtube.com',
'*tiqcdn.com',
'*touchpoints.app.cloud.gov',
'*script.crazyegg.com',
'*googletagmanager.com',
'*googleapis.com'
],
```

While the hosts are blocked you still might see fetch/xhr requests in the Cypress logs/screenshots/videos. To hide those add the following to the `cypress/support/e2e.js` file:

```javascript
// Hide fetch/XHR requests
const cypressLogOriginal = Cypress.log
const cypressLogDomainsHidden = ['https://google-analytics.com']
const cypressLogDomainsHidden = ['https://www.google-analytics.com']
Cypress.log = function (opts, ...other) {
const logFetchIs = ['fetch'].includes(opts.displayName)
const logFetchDomainMatch =
logFetchIs && cypressLogDomainsHidden.find((d) => opts.url.includes(d))
const logFetchDomainMatch = logFetchIs && cypressLogDomainsHidden.find((d) => opts.url.includes(d))
if (logFetchDomainMatch) return

return cypressLogOriginal(opts, ...other)
Expand Down

0 comments on commit 0e99d10

Please sign in to comment.