From d607100e4c42b51f1ad87937c9ab0f466987b646 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Tue, 30 Jun 2020 13:00:22 +0630 Subject: [PATCH] Rename uses of whitelist for renamed options. (#2928) --- source/api/commands/server.md | 17 +++++++++-------- source/api/cypress-api/cookies.md | 11 ++++++----- source/api/cypress-api/cypress-server.md | 2 +- source/faq/questions/using-cypress-faq.md | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/source/api/commands/server.md b/source/api/commands/server.md index aef407b912..59432fea6b 100644 --- a/source/api/commands/server.md +++ b/source/api/commands/server.md @@ -57,7 +57,7 @@ Option | Default | Description `onAnyRequest` | `undefined` | callback function called when any request is sent `onAnyResponse` | `undefined` | callback function called when any response is returned `urlMatchingOptions` | `{ matchBase: true }` | The default options passed to `minimatch` when using glob strings to match URLs -`whitelist` | function | Callback function that filters requests from ever being logged or stubbed. By default this matches against asset-like requests such as for `.js`, `.jsx`, `.html`, and `.css` files. +`ignore` | function | Callback function that filters requests from ever being logged or stubbed. By default this matches against asset-like requests such as for `.js`, `.jsx`, `.html`, and `.css` files. ## Yields {% helper_icon yields %} @@ -70,7 +70,7 @@ Option | Default | Description ### After starting a server: - Any request that does **NOT** match a {% url `cy.route()` route %} will {% url 'pass through to the server' network-requests#Don’t-Stub-Responses %}. -- Any request that matches the `options.whitelist` function will **NOT** be logged or stubbed. In other words it is filtered and ignored. +- Any request that matches the `options.ignore` function will **NOT** be logged or stubbed. - You will see requests named as `(XHR Stub)` or `(XHR)` in the Command Log. ```javascript @@ -181,19 +181,19 @@ cy.server({ ### Change the default filtering -`cy.server()` comes with a `whitelist` function that by default filters out any requests that are for static assets like `.html`, `.js`, `.jsx`, and `.css`. +`cy.server()` comes with an `ignore` function that by default filters out any requests that are for static assets like `.html`, `.js`, `.jsx`, and `.css`. -Any request that passes the `whitelist` will be ignored - it will not be logged nor will it be stubbed in any way (even if it matches a specific {% url `cy.route()` route %}). +Any request that passes the `ignore` will be ignored - it will not be logged nor will it be stubbed in any way (even if it matches a specific {% url `cy.route()` route %}). The idea is that we never want to interfere with static assets that are fetched via Ajax. **The default filter function in Cypress is:** ```javascript -const whitelist = (xhr) => { +const ignore = (xhr) => { // this function receives the xhr object in question and - // will filter if it's a GET that appears to be a static resource - return xhr.method === 'GET' && /\.(jsx?|html|css)(\?.*)?$/.test(xhr.url) + // will ignore if it's a GET that appears to be a static resource + return xhr.method === 'GET' && /\.(jsx?|coffee|html|less|s?css|svg)(\?.*)?$/.test(xhr.url) } ``` @@ -201,7 +201,7 @@ const whitelist = (xhr) => { ```javascript cy.server({ - whitelist: (xhr) => { + ignore: (xhr) => { // specify your own function that should return // truthy if you want this xhr to be ignored, // not logged, and not stubbed. @@ -270,6 +270,7 @@ The intention of {% url "`cy.request()`" request %} is to be used for checking e - `cy.server()` does *not* log in the Command Log {% history %} +{% url "5.0.0" changelog#5-0-0 %} | Renamed `whitelist` option to `ignore` {% url "0.13.6" changelog#0-13-6 %} | Added `onAbort` callback option {% url "0.5.10" changelog#0-5-10 %} | Added `delay` option {% url "0.3.3" changelog#0-3-3 %} | Added `whitelist` option diff --git a/source/api/cypress-api/cookies.md b/source/api/cypress-api/cookies.md index e0257e5171..163b57f858 100644 --- a/source/api/cypress-api/cookies.md +++ b/source/api/cypress-api/cookies.md @@ -129,7 +129,7 @@ Any change you make here will take effect immediately for the remainder of every A great place to put this configuration is in your `cypress/support/index.js` file, since it is loaded before any test files are evaluated. {% endnote %} -### `whitelist` accepts: +### `preserve` accepts: - String - Array @@ -142,7 +142,7 @@ A great place to put this configuration is in your `cypress/support/index.js` fi // now any cookie with the name 'session_id' will // not be cleared before each test runs Cypress.Cookies.defaults({ - whitelist: 'session_id' + preserve: 'session_id' }) ``` @@ -152,7 +152,7 @@ Cypress.Cookies.defaults({ // now any cookie with the name 'session_id' or 'remember_token' // will not be cleared before each test runs Cypress.Cookies.defaults({ - whitelist: ['session_id', 'remember_token'] + preserve: ['session_id', 'remember_token'] }) ``` @@ -162,7 +162,7 @@ Cypress.Cookies.defaults({ // now any cookie that matches this RegExp // will not be cleared before each test runs Cypress.Cookies.defaults({ - whitelist: /session|remember/ + preserve: /session|remember/ }) ``` @@ -170,7 +170,7 @@ Cypress.Cookies.defaults({ ```javascript Cypress.Cookies.defaults({ - whitelist: (cookie) => { + preserve: (cookie) => { // implement your own logic here // if the function returns truthy // then the cookie will not be cleared @@ -180,6 +180,7 @@ Cypress.Cookies.defaults({ ``` {% history %} +{% url "5.0.0" changelog#5-0-0 %} | Renamed `whitelist` option to `preserve` {% url "0.16.1" changelog#0-16-1 %} | `{verbose: false}` option added {% url "0.16.0" changelog#0-16-0 %} | Removed support for `Cypress.Cookies.get`, `Cypress.Cookies.set` and `Cypress.Cookies.remove` {% url "0.12.4" changelog#0-12-4 %} | `Cypress.Cookies` API added diff --git a/source/api/cypress-api/cypress-server.md b/source/api/cypress-api/cypress-server.md index 5052eca7cf..1a1329a1aa 100644 --- a/source/api/cypress-api/cypress-server.md +++ b/source/api/cypress-api/cypress-server.md @@ -28,7 +28,7 @@ Pass in an options object to change the default behavior of `Cypress.Server`. Cypress.Server.defaults({ delay: 500, force404: false, - whitelist: (xhr) => { + ignore: (xhr) => { // handle custom logic for filtering XHR requests } }) diff --git a/source/faq/questions/using-cypress-faq.md b/source/faq/questions/using-cypress-faq.md index aaba338a81..fa4f20f9c5 100644 --- a/source/faq/questions/using-cypress-faq.md +++ b/source/faq/questions/using-cypress-faq.md @@ -420,7 +420,7 @@ You can preserve specific cookies across tests using the {% url "Cypress.Cookies // now any cookie with the name 'session_id' will // not be cleared before each test runs Cypress.Cookies.defaults({ - whitelist: 'session_id' + preserve: 'session_id' }) ```