Skip to content

Commit d607100

Browse files
Rename uses of whitelist for renamed options. (#2928)
1 parent dca4c4e commit d607100

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

source/api/commands/server.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Option | Default | Description
5757
`onAnyRequest` | `undefined` | callback function called when any request is sent
5858
`onAnyResponse` | `undefined` | callback function called when any response is returned
5959
`urlMatchingOptions` | `{ matchBase: true }` | The default options passed to `minimatch` when using glob strings to match URLs
60-
`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.
60+
`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.
6161

6262
## Yields {% helper_icon yields %}
6363

@@ -70,7 +70,7 @@ Option | Default | Description
7070
### After starting a server:
7171

7272
- Any request that does **NOT** match a {% url `cy.route()` route %} will {% url 'pass through to the server' network-requests#Don’t-Stub-Responses %}.
73-
- Any request that matches the `options.whitelist` function will **NOT** be logged or stubbed. In other words it is filtered and ignored.
73+
- Any request that matches the `options.ignore` function will **NOT** be logged or stubbed.
7474
- You will see requests named as `(XHR Stub)` or `(XHR)` in the Command Log.
7575

7676
```javascript
@@ -181,27 +181,27 @@ cy.server({
181181

182182
### Change the default filtering
183183

184-
`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`.
184+
`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`.
185185

186-
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 %}).
186+
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 %}).
187187

188188
The idea is that we never want to interfere with static assets that are fetched via Ajax.
189189

190190
**The default filter function in Cypress is:**
191191

192192
```javascript
193-
const whitelist = (xhr) => {
193+
const ignore = (xhr) => {
194194
// this function receives the xhr object in question and
195-
// will filter if it's a GET that appears to be a static resource
196-
return xhr.method === 'GET' && /\.(jsx?|html|css)(\?.*)?$/.test(xhr.url)
195+
// will ignore if it's a GET that appears to be a static resource
196+
return xhr.method === 'GET' && /\.(jsx?|coffee|html|less|s?css|svg)(\?.*)?$/.test(xhr.url)
197197
}
198198
```
199199

200200
**You can override this function with your own specific logic:**
201201

202202
```javascript
203203
cy.server({
204-
whitelist: (xhr) => {
204+
ignore: (xhr) => {
205205
// specify your own function that should return
206206
// truthy if you want this xhr to be ignored,
207207
// not logged, and not stubbed.
@@ -270,6 +270,7 @@ The intention of {% url "`cy.request()`" request %} is to be used for checking e
270270
- `cy.server()` does *not* log in the Command Log
271271

272272
{% history %}
273+
{% url "5.0.0" changelog#5-0-0 %} | Renamed `whitelist` option to `ignore`
273274
{% url "0.13.6" changelog#0-13-6 %} | Added `onAbort` callback option
274275
{% url "0.5.10" changelog#0-5-10 %} | Added `delay` option
275276
{% url "0.3.3" changelog#0-3-3 %} | Added `whitelist` option

source/api/cypress-api/cookies.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Any change you make here will take effect immediately for the remainder of every
129129
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.
130130
{% endnote %}
131131

132-
### `whitelist` accepts:
132+
### `preserve` accepts:
133133

134134
- String
135135
- Array
@@ -142,7 +142,7 @@ A great place to put this configuration is in your `cypress/support/index.js` fi
142142
// now any cookie with the name 'session_id' will
143143
// not be cleared before each test runs
144144
Cypress.Cookies.defaults({
145-
whitelist: 'session_id'
145+
preserve: 'session_id'
146146
})
147147
```
148148

@@ -152,7 +152,7 @@ Cypress.Cookies.defaults({
152152
// now any cookie with the name 'session_id' or 'remember_token'
153153
// will not be cleared before each test runs
154154
Cypress.Cookies.defaults({
155-
whitelist: ['session_id', 'remember_token']
155+
preserve: ['session_id', 'remember_token']
156156
})
157157
```
158158

@@ -162,15 +162,15 @@ Cypress.Cookies.defaults({
162162
// now any cookie that matches this RegExp
163163
// will not be cleared before each test runs
164164
Cypress.Cookies.defaults({
165-
whitelist: /session|remember/
165+
preserve: /session|remember/
166166
})
167167
```
168168

169169
### Preserve Function
170170

171171
```javascript
172172
Cypress.Cookies.defaults({
173-
whitelist: (cookie) => {
173+
preserve: (cookie) => {
174174
// implement your own logic here
175175
// if the function returns truthy
176176
// then the cookie will not be cleared
@@ -180,6 +180,7 @@ Cypress.Cookies.defaults({
180180
```
181181

182182
{% history %}
183+
{% url "5.0.0" changelog#5-0-0 %} | Renamed `whitelist` option to `preserve`
183184
{% url "0.16.1" changelog#0-16-1 %} | `{verbose: false}` option added
184185
{% url "0.16.0" changelog#0-16-0 %} | Removed support for `Cypress.Cookies.get`, `Cypress.Cookies.set` and `Cypress.Cookies.remove`
185186
{% url "0.12.4" changelog#0-12-4 %} | `Cypress.Cookies` API added

source/api/cypress-api/cypress-server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Pass in an options object to change the default behavior of `Cypress.Server`.
2828
Cypress.Server.defaults({
2929
delay: 500,
3030
force404: false,
31-
whitelist: (xhr) => {
31+
ignore: (xhr) => {
3232
// handle custom logic for filtering XHR requests
3333
}
3434
})

source/faq/questions/using-cypress-faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ You can preserve specific cookies across tests using the {% url "Cypress.Cookies
420420
// now any cookie with the name 'session_id' will
421421
// not be cleared before each test runs
422422
Cypress.Cookies.defaults({
423-
whitelist: 'session_id'
423+
preserve: 'session_id'
424424
})
425425
```
426426

0 commit comments

Comments
 (0)