-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding blocking hosts example (#120)
* Update README.md * Create BlockHosts.md * Update README.md * Update BlockHosts.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update BlockHosts.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d0dc283
commit 2090bf9
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Blocking Hosts in Tests | ||
|
||
The most common host you want to block in the tests in Google Analytics. To do that use the [`blockHosts`](https://docs.cypress.io/app/references/configuration#blockHosts) configuration option. Here is an example of a list of hosts we block including Google Analytics: | ||
|
||
```javascript | ||
blockHosts: [ | ||
'*doubleclick.net', | ||
'*google-analytics.com', | ||
'*tealiumiq.com', | ||
'*quantummetric.com', | ||
'g*qualtrics.com', | ||
'*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://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)) | ||
if (logFetchDomainMatch) return | ||
|
||
return cypressLogOriginal(opts, ...other) | ||
} | ||
``` | ||
|
||
[Credit for the code snippet](https://gist.github.com/simenbrekken/3d2248f9e50c1143bf9dbe02e67f5399?permalink_comment_id=4190114#gistcomment-4190114). | ||
|
||
## Useful references | ||
|
||
- https://docs.cypress.io/app/references/configuration#blockHosts | ||
- https://gist.github.com/simenbrekken/3d2248f9e50c1143bf9dbe02e67f5399?permalink_comment_id=4190114#gistcomment-4190114 |