You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 29, 2023. It is now read-only.
- table of contents
- move "api" sections to the top
- separate name + tag filter docs, because not all functionality
is available for both
- group general api info together
-[Debugging in the plugin](#debugging-in-the-plugin)
54
+
-[Debugging in the browser](#debugging-in-the-browser)
55
+
-[Examples](#examples)
56
+
-[See also](#see-also)
57
+
-[Migration guide](#migration-guide)
58
+
-[from v1 to v2](#from-v1-to-v2)
59
+
-[Videos & Blog Posts](#videos--blog-posts)
60
+
-[Blog posts](#blog-posts)
61
+
-[Small print](#small-print)
62
+
-[MIT License](#mit-license)
63
+
64
+
<!-- /MarkdownTOC -->
65
+
26
66
## Install
27
67
28
68
Assuming you have Cypress installed, add this module as a dev dependency
@@ -68,9 +108,13 @@ registerCypressGrep()
68
108
69
109
Installing the plugin via `setupNodeEvents()` is required to enable the [grepFilterSpecs](#grepfilterspecs) feature.
70
110
71
-
## Use
111
+
## Usage Overview
112
+
113
+
You can filter tests to run using part of their title via `grep`, and via explicit tags via `grepTags` Cypress environment variables.
72
114
73
-
Start grepping by title and tags:
115
+
Most likely you will pass these environment variables from the command line. For example, to only run tests with "login" in their title and tagged "smoke", you would run:
116
+
117
+
Here are a few examples:
74
118
75
119
```shell
76
120
# run only the tests with "auth user" in the title
@@ -92,32 +136,7 @@ $ npx cypress run --env grepTags=@smoke,grepFilterSpecs=true
92
136
$ npx cypress run --env grepUntagged=true
93
137
```
94
138
95
-
## Videos
96
-
97
-
Watch the video [intro to cypress-grep](https://www.youtube.com/watch?v=HS-Px-Sghd8) which shows how this repository tags tests, uses [cypress-grep](https://github.com/cypress-io/cypress-grep) plugin, and sets up the TypeScript intelligent code completion.
98
-
99
-
You can also watch [How I organize pull request workflows](https://youtu.be/SFW7Ecj5TNE) where I show how the GitHub workflows in [.github/workflows](./.github/workflows) are organized to run the smoke tests first on pull request.
100
-
101
-
Watch the video [Filter Specs First When Using cypress-grep Plugin](https://youtu.be/adL7KzO5dR0)
102
-
103
-
Watch the video [Run All Tests That Have No Tags Using cypress-grep Plugin](https://youtu.be/CtU43GzaicI)
104
-
105
-
## Blog posts
106
-
107
-
-[Burning Tests with cypress-grep](https://glebbahmutov.com/blog/burning-tests/)
108
-
-[Faster test execution with cypress-grep](https://glebbahmutov.com/blog/cypress-grep-filters/)
109
-
110
-
## Filters
111
-
112
-
You can filter tests to run using part of their title via `grep`, and via explicit tags via `grepTags` Cypress environment variables.
113
-
114
-
Most likely you will pass these environment variables from the command line. For example, to only run tests with "login" in their title and tagged "smoke", you would run:
115
-
116
-
```shell
117
-
$ npx cypress run --env grep=login,grepTags=smoke
118
-
```
119
-
120
-
You can use any way to modify the environment values `grep` and `grepTags`, except the run-time `Cypress.env('grep')` (because it is too late at run-time). You can set the `grep` value in the [config file](https://docs.cypress.io/guides/references/configuration) to run only tests with the substring `viewport` in their names
139
+
You can use any way to modify the environment values `grep` and `grepTags`, except the run-time `Cypress.env('grep')` (because it is too late at run-time). You can set the `grep` value in the `cypress.json` file to run only tests with the substring `viewport` in their names
You can also set the grep and grepTags from the DevTools console while running Cypress in the interactive mode `cypress open`, see [DevTools Console section](#devtools-console).
141
160
142
-
### Disable grep
143
-
144
-
If you specify the `grep` parameters inside the [config file](https://docs.cypress.io/guides/references/configuration), you can disable it from the command line
145
-
146
-
```
147
-
$ npx cypress run --env grep=,grepTags=,burn=
148
-
```
149
-
150
-
### grep by test title
161
+
## Filter by test title
151
162
152
163
```shell
153
164
# run all tests with "hello" in their title
@@ -156,14 +167,35 @@ $ npx cypress run --env grep=hello
156
167
$ npx cypress run --env grep="hello world"
157
168
```
158
169
170
+
### OR substring matching
171
+
159
172
You can pass multiple title substrings to match separating them with `;` character. Each substring is trimmed.
160
173
161
174
```shell
162
175
# run all tests with "hello world" or "auth user" in their title
163
176
$ npx cypress run --env grep="hello world; auth user"
164
177
```
165
178
166
-
### negative filter
179
+
### Test suites
180
+
181
+
The filter is also applied to the "describe" blocks. In that case, the tests look up if any of their outer suites are enabled.
182
+
183
+
```js
184
+
describe('block for config', () => {
185
+
it('should run', () => {})
186
+
187
+
it('should also work', () => {})
188
+
})
189
+
```
190
+
191
+
```
192
+
# run any tests in the blocks including "config"
193
+
--env grep=config
194
+
```
195
+
196
+
**Note:** global function `describe` and `context` are aliases and both supported by this plugin.
197
+
198
+
### Invert filter
167
199
168
200
```shell
169
201
# run all tests WITHOUT "hello world" in their title
**Note:** An inverted name filter that matches a suite name does not exclude its tests.
208
+
175
209
## Filter with tags
176
210
177
211
You can select tests to run or skip using tags by passing `--env grepTags=...` value.
@@ -208,7 +242,66 @@ it('works as a string', { tags: 'config' }, () => {
208
242
209
243
You can run both of these tests using `--env grepTags=config` string.
210
244
211
-
### grepFilterSpecs
245
+
### AND tags
246
+
247
+
Use `+` to require both tags to be present
248
+
249
+
```
250
+
--env grepTags=@smoke+@fast
251
+
```
252
+
253
+
### OR tags
254
+
255
+
You can run tests that match one tag or another using spaces. Make sure to quote the grep string!
256
+
257
+
```
258
+
# run tests with tags "@slow" or "@critical" in their names
259
+
--env grepTags='@slow @critical'
260
+
```
261
+
262
+
### Test suites
263
+
264
+
The tags are also applied to the "describe" blocks. In that case, the tests look up if any of their outer suites are enabled.
265
+
266
+
```js
267
+
describe('block with config tag', { tags:'@smoke' }, () => {})
268
+
```
269
+
270
+
```
271
+
# run any tests in the blocks having "@smoke" tag
272
+
--env grepTags=@smoke
273
+
# skip any blocks with "@smoke" tag
274
+
--env grepTags=-@smoke
275
+
```
276
+
277
+
See the [cypress/integration/describe-tags-spec.js](./cypress/integration/describe-tags-spec.js) file.
278
+
279
+
**Note:** global function `describe` and `context` are aliases and both supported by this plugin.
280
+
281
+
### Invert tag
282
+
283
+
You can skip running the tests with specific tag using the invert option: prefix the tag with the character `-`.
284
+
285
+
```
286
+
# do not run any tests with tag "@slow"
287
+
--env grepTags=-@slow
288
+
```
289
+
290
+
If you want to run all tests with tag `@slow` but without tag `@smoke`:
291
+
292
+
```
293
+
--env grepTags=@slow+-@smoke
294
+
```
295
+
296
+
### Grep untagged tests
297
+
298
+
Sometimes you want to run only the tests without any tags, and these tests are inside the describe blocks without any tags.
299
+
300
+
```
301
+
$ npx cypress run --env grepUntagged=true
302
+
```
303
+
304
+
## Pre-filter specs (grepFilterSpecs)
212
305
213
306
By default, when using `grep` and `grepTags` all specs are executed, and inside each the filters are applied. This can be very wasteful, if only a few specs contain the `grep` in the test titles. Thus when doing the positive `grep`, you can pre-filter specs using the `grepFilterSpecs=true` parameter.
$ npx cypress run --env grepTags=@smoke,grepFilterSpecs=true
221
314
```
222
315
223
-
Note: this requires installing this plugin in your project's plugin file, see the [Install](#install).
316
+
**Note 1:** this requires installing this plugin in your project's plugin file, see the [Install](#install).
224
317
225
-
Note 2: the `grepFilterSpecs` option is only compatible with the positive `grep` and `grepTags` options, not with the negative "!..." filter.
318
+
**Note 2:** the `grepFilterSpecs` option is only compatible with the positive `grep` and `grepTags` options, not with the negative "!..." filter.
226
319
227
-
Note 3: if there are no files remaining after filtering, the plugin prints a warning and leaves all files unchanged to avoid the test runner erroring with "No specs found".
320
+
**Note 3:** if there are no files remaining after filtering, the plugin prints a warning and leaves all files unchanged to avoid the test runner erroring with "No specs found".
228
321
229
322
**Tip:** you can set this environment variable in the [config file](https://docs.cypress.io/guides/references/configuration) file to enable it by default and skip using the environment variable:
230
323
@@ -236,7 +329,7 @@ Note 3: if there are no files remaining after filtering, the plugin prints a war
236
329
}
237
330
```
238
331
239
-
### omit filtered tests
332
+
##Omit filtered tests (grepOmitFiltered)
240
333
241
334
By default, all filtered tests are made _pending_ using `it.skip` method. If you want to completely omit them, pass the environment variable `grepOmitFiltered=true`.
242
335
@@ -266,15 +359,27 @@ cypress run --env grep="works 2",grepOmitFiltered=true
266
359
}
267
360
```
268
361
269
-
### grep untagged tests
362
+
##Disable grep
270
363
271
-
Sometimes you want to run only the tests without any tags, and these tests are inside the describe blocks without any tags.
364
+
If you specify the `grep` parameters inside `cypress.json` file, you can disable it from the command line
272
365
273
366
```
274
-
$ npx cypress run --env grepUntagged=true
367
+
$ npx cypress run --env grep=,grepTags=,burn=
275
368
```
276
369
277
-
### TypeScript users
370
+
## Burn (repeat) tests
371
+
372
+
You can burn the filtered tests to make sure they are flake-free
373
+
374
+
```
375
+
npx cypress run --env grep="hello world",burn=5
376
+
```
377
+
378
+
You can pass the number of times to run the tests via environment name `burn` or `grepBurn` or `grep-burn`. Note, if a lot of tests match the grep and grep tags, a lot of tests will be burnt!
379
+
380
+
If you do not specify the "grep" or "grep tags" option, the "burn" will repeat _every_ test.
381
+
382
+
## TypeScript support
278
383
279
384
Because the Cypress test config object type definition does not have the `tags` property we are using above, the TypeScript linter will show an error. Just add an ignore comment above the test:
280
385
@@ -305,87 +410,6 @@ If you have `tsconfig.json` file, add this library to the types list
305
410
}
306
411
```
307
412
308
-
## Test suites
309
-
310
-
The tags are also applied to the "describe" blocks. In that case, the tests look up if any of their outer suites are enabled.
311
-
312
-
```js
313
-
describe('block with config tag', { tags:'@smoke' }, () => {})
314
-
```
315
-
316
-
```
317
-
# run any tests in the blocks having "@smoke" tag
318
-
--env grepTags=@smoke
319
-
# skip any blocks with "@smoke" tag
320
-
--env grepTags=-@smoke
321
-
```
322
-
323
-
See the [cypress/integration/describe-tags-spec.js](./cypress/integration/describe-tags-spec.js) file.
324
-
325
-
**Note:** global function `describe` and `context` are aliases and both supported by this plugin.
326
-
327
-
### AND tags
328
-
329
-
Use `+` to require both tags to be present
330
-
331
-
```
332
-
--env grepTags=@smoke+@fast
333
-
```
334
-
335
-
### Invert tag
336
-
337
-
You can skip running the tests with specific tag using the invert option: prefix the tag with the character `-`.
338
-
339
-
```
340
-
# do not run any tests with tag "@slow"
341
-
--env grepTags=-@slow
342
-
```
343
-
344
-
If you want to run all tests with tag `@slow` but without tag `@smoke`:
345
-
346
-
```
347
-
--env grepTags=@slow+-@smoke
348
-
```
349
-
350
-
### OR tags
351
-
352
-
You can run tests that match one tag or another using spaces. Make sure to quote the grep string!
353
-
354
-
```
355
-
# run tests with tags "@slow" or "@critical" in their names
356
-
--env grepTags='@slow @critical'
357
-
```
358
-
359
-
### NOT tags
360
-
361
-
You can skip running the tests with specific tag, even if they have a tag that should run, using the not option: prefix the tag with `--`.
362
-
363
-
Note this is the same as appending `+-<tag to never run>` to each tag. May be useful with large number of tags.
364
-
365
-
If you want to run tests with tags `@slow` or `@regression` but without tag `@smoke`
You can repeat (burn) the filtered tests to make sure they are flake-free
380
-
381
-
```
382
-
npx cypress run --env grep="hello world",burn=5
383
-
```
384
-
385
-
You can pass the number of times to run the tests via environment name `burn` or `grepBurn` or `grep-burn`. Note, if a lot of tests match the grep and grep tags, a lot of tests will be burnt!
386
-
387
-
If you do not specify the "grep" or "grep tags" option, the "burn" will repeat _every_ test.
388
-
389
413
## General advice
390
414
391
415
- keep it simple.
@@ -536,6 +560,21 @@ The above scenario was confusing - did you want to find all tests with title con
536
560
--env grep=hello,grepTags=smoke
537
561
```
538
562
563
+
## Videos & Blog Posts
564
+
565
+
Watch the video [intro to cypress-grep](https://www.youtube.com/watch?v=HS-Px-Sghd8) which shows how this repository tags tests, uses [cypress-grep](https://github.com/cypress-io/cypress-grep) plugin, and sets up the TypeScript intelligent code completion.
566
+
567
+
You can also watch [How I organize pull request workflows](https://youtu.be/SFW7Ecj5TNE) where I show how the GitHub workflows in [.github/workflows](./.github/workflows) are organized to run the smoke tests first on pull request.
568
+
569
+
Watch the video [Filter Specs First When Using cypress-grep Plugin](https://youtu.be/adL7KzO5dR0)
570
+
571
+
Watch the video [Run All Tests That Have No Tags Using cypress-grep Plugin](https://youtu.be/CtU43GzaicI)
572
+
573
+
## Blog posts
574
+
575
+
-[Burning Tests with cypress-grep](https://glebbahmutov.com/blog/burning-tests/)
576
+
-[Faster test execution with cypress-grep](https://glebbahmutov.com/blog/cypress-grep-filters/)
0 commit comments