@bahmutov/cy-grep 2.0.37 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -59
- package/package.json +6 -6
- package/src/plugin.js +45 -36
- package/src/support.js +15 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# @bahmutov/cy-grep 
|
|
2
2
|
|
|
3
3
|
> Filter tests using substring or tag
|
|
4
4
|
|
|
5
5
|
```shell
|
|
6
6
|
# run only tests with "hello" in their names
|
|
7
|
-
npx cypress run --
|
|
7
|
+
npx cypress run --expose grep=hello
|
|
8
8
|
|
|
9
9
|
✓ hello world
|
|
10
10
|
- works
|
|
@@ -147,11 +147,11 @@ registerCypressGrep()
|
|
|
147
147
|
|
|
148
148
|
Installing the plugin via `setupNodeEvents()` is required to enable the [grepFilterSpecs](#pre-filter-specs-grepfilterspecs) feature.
|
|
149
149
|
|
|
150
|
-
**Tip:** you probably want to set these `
|
|
150
|
+
**Tip:** you probably want to set these `expose` settings in your config file
|
|
151
151
|
|
|
152
152
|
```js
|
|
153
153
|
module.exports = defineConfig({
|
|
154
|
-
|
|
154
|
+
expose: { grepFilterSpecs: true, grepOmitFiltered: true },
|
|
155
155
|
...
|
|
156
156
|
})
|
|
157
157
|
```
|
|
@@ -193,7 +193,7 @@ Put the common settings into `cypress.json`
|
|
|
193
193
|
|
|
194
194
|
```json
|
|
195
195
|
{
|
|
196
|
-
"
|
|
196
|
+
"expose": {
|
|
197
197
|
"grepOmitFiltered": true,
|
|
198
198
|
"grepFilterSpecs": true
|
|
199
199
|
}
|
|
@@ -210,40 +210,40 @@ Here are a few examples:
|
|
|
210
210
|
|
|
211
211
|
```shell
|
|
212
212
|
# run only the tests with "auth user" in the title
|
|
213
|
-
$ npx cypress run --
|
|
213
|
+
$ npx cypress run --expose grep="auth user"
|
|
214
214
|
# run tests with "hello" or "auth user" in their titles
|
|
215
215
|
# by separating them with ";" character
|
|
216
|
-
$ npx cypress run --
|
|
216
|
+
$ npx cypress run --expose grep="hello; auth user"
|
|
217
217
|
# run tests tagged @fast
|
|
218
|
-
$ npx cypress run --
|
|
218
|
+
$ npx cypress run --expose grepTags=@fast
|
|
219
219
|
# run only the tests tagged "smoke"
|
|
220
220
|
# that have "login" in their titles
|
|
221
|
-
$ npx cypress run --
|
|
221
|
+
$ npx cypress run --expose grep=login,grepTags=smoke
|
|
222
222
|
# only run the specs that have any tests with "user" in their titles
|
|
223
|
-
$ npx cypress run --
|
|
223
|
+
$ npx cypress run --expose grep=user,grepFilterSpecs=true
|
|
224
224
|
# only run the specs that have any tests tagged "@smoke"
|
|
225
|
-
$ npx cypress run --
|
|
225
|
+
$ npx cypress run --expose grepTags=@smoke,grepFilterSpecs=true
|
|
226
226
|
# run only tests that do not have any tags
|
|
227
227
|
# and are not inside suites that have any tags
|
|
228
|
-
$ npx cypress run --
|
|
228
|
+
$ npx cypress run --expose grepUntagged=true
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
You can use any way to modify the environment values `grep` and `grepTags`, except the run-time `Cypress.
|
|
231
|
+
You can use any way to modify the environment values `grep` and `grepTags`, except the run-time `Cypress.expose('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
|
|
232
232
|
|
|
233
233
|
```json
|
|
234
234
|
{
|
|
235
|
-
"
|
|
235
|
+
"expose": {
|
|
236
236
|
"grep": "viewport"
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
-
You can also set the `
|
|
241
|
+
You can also set the `expose.grep` object in the plugin file, but remember to return the changed config object:
|
|
242
242
|
|
|
243
243
|
```js
|
|
244
244
|
// cypress/plugin/index.js
|
|
245
245
|
module.exports = (on, config) => {
|
|
246
|
-
config.
|
|
246
|
+
config.expose.grep = 'viewport'
|
|
247
247
|
return config
|
|
248
248
|
}
|
|
249
249
|
```
|
|
@@ -254,9 +254,9 @@ You can also set the grep and grepTags from the DevTools console while running C
|
|
|
254
254
|
|
|
255
255
|
```shell
|
|
256
256
|
# run all tests with "hello" in their title
|
|
257
|
-
$ npx cypress run --
|
|
257
|
+
$ npx cypress run --expose grep=hello
|
|
258
258
|
# run all tests with "hello world" in their title
|
|
259
|
-
$ npx cypress run --
|
|
259
|
+
$ npx cypress run --expose grep="hello world"
|
|
260
260
|
```
|
|
261
261
|
|
|
262
262
|
### OR substring matching
|
|
@@ -265,7 +265,7 @@ You can pass multiple title substrings to match separating them with `;` charact
|
|
|
265
265
|
|
|
266
266
|
```shell
|
|
267
267
|
# run all tests with "hello world" or "auth user" in their title
|
|
268
|
-
$ npx cypress run --
|
|
268
|
+
$ npx cypress run --expose grep="hello world; auth user"
|
|
269
269
|
```
|
|
270
270
|
|
|
271
271
|
### Test suites
|
|
@@ -282,7 +282,7 @@ describe('block for config', () => {
|
|
|
282
282
|
|
|
283
283
|
```
|
|
284
284
|
# run any tests in the blocks including "config"
|
|
285
|
-
--
|
|
285
|
+
--expose grep=config
|
|
286
286
|
```
|
|
287
287
|
|
|
288
288
|
**Note:** global function `describe` and `context` are aliases and both supported by this plugin.
|
|
@@ -291,22 +291,22 @@ describe('block for config', () => {
|
|
|
291
291
|
|
|
292
292
|
```shell
|
|
293
293
|
# run all tests WITHOUT "hello world" in their title
|
|
294
|
-
$ npx cypress run --
|
|
294
|
+
$ npx cypress run --expose grep="-hello world"
|
|
295
295
|
# run tests with "hello", but without "world" in the titles
|
|
296
|
-
$ npx cypress run --
|
|
296
|
+
$ npx cypress run --expose grep="hello; -world"
|
|
297
297
|
```
|
|
298
298
|
|
|
299
299
|
## Filter with tags
|
|
300
300
|
|
|
301
|
-
You can select tests to run or skip using tags by passing `--
|
|
301
|
+
You can select tests to run or skip using tags by passing `--expose grepTags=...` value.
|
|
302
302
|
|
|
303
303
|
```
|
|
304
304
|
# enable the tests with tag "one" or "two"
|
|
305
|
-
--
|
|
305
|
+
--expose grepTags="one two"
|
|
306
306
|
# enable the tests with both tags "one" and "two"
|
|
307
|
-
--
|
|
307
|
+
--expose grepTags="one+two"
|
|
308
308
|
# enable the tests with "hello" in the title and tag "smoke"
|
|
309
|
-
--
|
|
309
|
+
--expose grep=hello,grepTags=smoke
|
|
310
310
|
```
|
|
311
311
|
|
|
312
312
|
If you can pass commas in the environment variable `grepTags`, you can use `,` to separate the tags
|
|
@@ -319,7 +319,7 @@ CYPRESS_grepTags=one,two npx cypress run
|
|
|
319
319
|
If a specific tag is not found in the specs, you will get a warning in the terminal:
|
|
320
320
|
|
|
321
321
|
```
|
|
322
|
-
$ npx cypress run --
|
|
322
|
+
$ npx cypress run --expose grepTags=@wrong-tag
|
|
323
323
|
cy-grep: could not find the tag "@wrong-tag" in any of the specs
|
|
324
324
|
```
|
|
325
325
|
|
|
@@ -337,14 +337,14 @@ it('works as a string', { tags: 'config' }, () => {
|
|
|
337
337
|
})
|
|
338
338
|
```
|
|
339
339
|
|
|
340
|
-
You can run both of these tests using `--
|
|
340
|
+
You can run both of these tests using `--expose grepTags=config` string.
|
|
341
341
|
|
|
342
342
|
### AND tags
|
|
343
343
|
|
|
344
344
|
Use `+` to require both tags to be present
|
|
345
345
|
|
|
346
346
|
```
|
|
347
|
-
--
|
|
347
|
+
--expose grepTags=@smoke+@fast
|
|
348
348
|
```
|
|
349
349
|
|
|
350
350
|
### OR tags
|
|
@@ -353,7 +353,7 @@ You can run tests that match one tag or another using spaces. Make sure to quote
|
|
|
353
353
|
|
|
354
354
|
```
|
|
355
355
|
# run tests with tags "@slow" or "@critical" in their names
|
|
356
|
-
--
|
|
356
|
+
--expose grepTags='@slow @critical'
|
|
357
357
|
```
|
|
358
358
|
|
|
359
359
|
### Inverted tags
|
|
@@ -362,13 +362,13 @@ You can skip running the tests with specific tag using the invert option: prefix
|
|
|
362
362
|
|
|
363
363
|
```
|
|
364
364
|
# do not run any tests with tag "@slow"
|
|
365
|
-
--
|
|
365
|
+
--expose grepTags=-@slow
|
|
366
366
|
```
|
|
367
367
|
|
|
368
368
|
If you want to run all tests with tag `@slow` but without tag `@smoke`:
|
|
369
369
|
|
|
370
370
|
```
|
|
371
|
-
--
|
|
371
|
+
--expose grepTags=@slow+-@smoke
|
|
372
372
|
```
|
|
373
373
|
|
|
374
374
|
**Note:** Inverted tag filter is not compatible with the `grepFilterSpecs` option
|
|
@@ -382,13 +382,13 @@ Note this is the same as appending `+-<tag to never run>` to each tag. May be us
|
|
|
382
382
|
If you want to run tests with tags `@slow` or `@regression` but without tag `@smoke`
|
|
383
383
|
|
|
384
384
|
```
|
|
385
|
-
--
|
|
385
|
+
--expose grepTags='@slow @regression --@smoke'
|
|
386
386
|
```
|
|
387
387
|
|
|
388
388
|
which is equivalent to
|
|
389
389
|
|
|
390
390
|
```
|
|
391
|
-
--
|
|
391
|
+
--expose grepTags='@slow+-@smoke @regression+-@smoke'
|
|
392
392
|
```
|
|
393
393
|
|
|
394
394
|
### Tags in test suites
|
|
@@ -401,9 +401,9 @@ describe('block with config tag', { tags: '@smoke' }, () => {})
|
|
|
401
401
|
|
|
402
402
|
```
|
|
403
403
|
# run any tests in the blocks having "@smoke" tag
|
|
404
|
-
--
|
|
404
|
+
--expose grepTags=@smoke
|
|
405
405
|
# skip any blocks with "@smoke" tag
|
|
406
|
-
--
|
|
406
|
+
--expose grepTags=-@smoke
|
|
407
407
|
```
|
|
408
408
|
|
|
409
409
|
See the [cypress/integration/describe-tags-spec.js](./cypress/integration/describe-tags-spec.js) file.
|
|
@@ -415,18 +415,18 @@ See the [cypress/integration/describe-tags-spec.js](./cypress/integration/descri
|
|
|
415
415
|
Sometimes you want to run only the tests without any tags, and these tests are inside the describe blocks without any tags.
|
|
416
416
|
|
|
417
417
|
```
|
|
418
|
-
$ npx cypress run --
|
|
418
|
+
$ npx cypress run --expose grepUntagged=true
|
|
419
419
|
```
|
|
420
420
|
|
|
421
421
|
### Access the tags in the test
|
|
422
422
|
|
|
423
|
-
You can check the current test's tags (including its parent suites) by checking the `Cypress.
|
|
423
|
+
You can check the current test's tags (including its parent suites) by checking the `Cypress.expose('testTags')` list
|
|
424
424
|
|
|
425
425
|
```js
|
|
426
426
|
describe('parent', { tags: ['@p1', '@p2'] }, () => {
|
|
427
427
|
describe('child', { tags: '@c1' }, () => {
|
|
428
428
|
it('has all effective test tags', { tags: '@t1' }, () => {
|
|
429
|
-
const tags = Cypress.
|
|
429
|
+
const tags = Cypress.expose('testTags')
|
|
430
430
|
// includes tags from the parent suites and the test itself
|
|
431
431
|
expect(tags, 'tags').to.deep.equal(['@p1', '@p2', '@c1', '@t1'])
|
|
432
432
|
})
|
|
@@ -434,16 +434,54 @@ describe('parent', { tags: ['@p1', '@p2'] }, () => {
|
|
|
434
434
|
})
|
|
435
435
|
```
|
|
436
436
|
|
|
437
|
+
Additionally, you can check both tags and required tags for each test within the current spec by checking the `Cypress.expose('specTags')` object
|
|
438
|
+
|
|
439
|
+
See [spec.js](./cypress/e2e/spec.js) for practical test spec example.
|
|
440
|
+
|
|
441
|
+
Example output:
|
|
442
|
+
|
|
443
|
+
```js
|
|
444
|
+
{
|
|
445
|
+
"hello world": {
|
|
446
|
+
"effectiveTestTags": [],
|
|
447
|
+
"requiredTestTags": []
|
|
448
|
+
},
|
|
449
|
+
"works": {
|
|
450
|
+
"effectiveTestTags": [],
|
|
451
|
+
"requiredTestTags": []
|
|
452
|
+
},
|
|
453
|
+
"works 2 @tag1": {
|
|
454
|
+
"effectiveTestTags": [
|
|
455
|
+
"@tag1"
|
|
456
|
+
],
|
|
457
|
+
"requiredTestTags": []
|
|
458
|
+
},
|
|
459
|
+
"works 2 @tag1 @tag2": {
|
|
460
|
+
"effectiveTestTags": [
|
|
461
|
+
"@tag1",
|
|
462
|
+
"@tag2"
|
|
463
|
+
],
|
|
464
|
+
"requiredTestTags": []
|
|
465
|
+
},
|
|
466
|
+
"works @tag2": {
|
|
467
|
+
"effectiveTestTags": [
|
|
468
|
+
"@tag2"
|
|
469
|
+
],
|
|
470
|
+
"requiredTestTags": []
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
437
475
|
## Pre-filter specs (grepFilterSpecs)
|
|
438
476
|
|
|
439
477
|
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.
|
|
440
478
|
|
|
441
|
-
```
|
|
479
|
+
```shell
|
|
442
480
|
# filter all specs first, and only run the ones with
|
|
443
481
|
# suite or test titles containing the string "it loads"
|
|
444
|
-
$ npx cypress run --
|
|
482
|
+
$ npx cypress run --expose grep="it loads",grepFilterSpecs=true
|
|
445
483
|
# filter all specs files, only run the specs with a tag "@smoke"
|
|
446
|
-
$ npx cypress run --
|
|
484
|
+
$ npx cypress run --expose grepTags=@smoke,grepFilterSpecs=true
|
|
447
485
|
```
|
|
448
486
|
|
|
449
487
|
**Note 1:** this requires installing this plugin in your project's plugin file, see the [Install](#install).
|
|
@@ -472,7 +510,7 @@ By default, all filtered tests are made _pending_ using `it.skip` method. If you
|
|
|
472
510
|
Pending filtered tests
|
|
473
511
|
|
|
474
512
|
```
|
|
475
|
-
cypress run --
|
|
513
|
+
cypress run --expose grep="works 2"
|
|
476
514
|
```
|
|
477
515
|
|
|
478
516
|

|
|
@@ -480,7 +518,7 @@ cypress run --env grep="works 2"
|
|
|
480
518
|
Omit filtered tests
|
|
481
519
|
|
|
482
520
|
```
|
|
483
|
-
cypress run --
|
|
521
|
+
cypress run --expose grep="works 2",grepOmitFiltered=true
|
|
484
522
|
```
|
|
485
523
|
|
|
486
524
|

|
|
@@ -500,7 +538,7 @@ cypress run --env grep="works 2",grepOmitFiltered=true
|
|
|
500
538
|
If you specify the `grep` parameters the [config file](https://docs.cypress.io/guides/references/configuration), you can disable it from the command line
|
|
501
539
|
|
|
502
540
|
```
|
|
503
|
-
$ npx cypress run --
|
|
541
|
+
$ npx cypress run --expose grep=,grepTags=,burn=
|
|
504
542
|
```
|
|
505
543
|
|
|
506
544
|
## Burn (repeat) tests
|
|
@@ -508,7 +546,7 @@ $ npx cypress run --env grep=,grepTags=,burn=
|
|
|
508
546
|
You can burn the filtered tests to make sure they are flake-free
|
|
509
547
|
|
|
510
548
|
```
|
|
511
|
-
npx cypress run --
|
|
549
|
+
npx cypress run --expose grep="hello world",burn=5
|
|
512
550
|
```
|
|
513
551
|
|
|
514
552
|
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!
|
|
@@ -520,7 +558,7 @@ If you do not specify the "grep" or "grep tags" option, the "burn" will repeat _
|
|
|
520
558
|
Sometimes you want to pre-filter specs using tags AND then run extra specs without any filtering. You can set the list of specs / patterns using the `grepExtraSpecs` env string. For example, to filter specs using tag `@a` plus run the spec "b.cy.js":
|
|
521
559
|
|
|
522
560
|
```
|
|
523
|
-
npx cypress run --
|
|
561
|
+
npx cypress run --expose grepTags=@a,grepExtraSpecs=cypress/e2e/b.cy.js
|
|
524
562
|
```
|
|
525
563
|
|
|
526
564
|
## Required tags
|
|
@@ -531,7 +569,7 @@ Sometimes you might want to run a test or a suite of tests _only_ if a specific
|
|
|
531
569
|
it('cleans up the data', { requiredTags: '@nightly' }, () => {...})
|
|
532
570
|
```
|
|
533
571
|
|
|
534
|
-
When you run the tests now, this test will be skipped, as if it were `it.skip`. It will only run if you use the tag `@nightly`, for example: `npx cypress run --
|
|
572
|
+
When you run the tests now, this test will be skipped, as if it were `it.skip`. It will only run if you use the tag `@nightly`, for example: `npx cypress run --expose grepTags=@nightly`.
|
|
535
573
|
|
|
536
574
|
If `grepFilterSpecs=true` and a spec has only required tags, and you are running without any tags, the the spec will be skipped completely.
|
|
537
575
|
|
|
@@ -555,7 +593,7 @@ describe('projects', () => {
|
|
|
555
593
|
})
|
|
556
594
|
```
|
|
557
595
|
|
|
558
|
-
You can run the tests inside the suite "projects" by using `--
|
|
596
|
+
You can run the tests inside the suite "projects" by using `--expose grep=projects` and you can skip the tests in the suite `projects` by using `--expose grep=-projects`.
|
|
559
597
|
|
|
560
598
|
## TypeScript support
|
|
561
599
|
|
|
@@ -615,16 +653,16 @@ Using test tags that start with `@` is so common, you can enforce it using the e
|
|
|
615
653
|
# use { tags: '@tag1' } in your tests
|
|
616
654
|
|
|
617
655
|
# then these two are equivalent
|
|
618
|
-
--
|
|
619
|
-
--
|
|
656
|
+
--expose grepTags=@tag1
|
|
657
|
+
--expose grepTags=tag1
|
|
620
658
|
```
|
|
621
659
|
|
|
622
660
|
## grepSpec
|
|
623
661
|
|
|
624
|
-
If the user selected spec(s) to run, then it might conflict with `grepFilterSpecs=true` that filters the specs. There is no way to "know" if the user used `--spec <...>` option when the plugin runs, see issues [33](https://github.com/bahmutov/cy-grep/issues/33) and [26032](https://github.com/cypress-io/cypress/issues/26032). Thus if you use `--spec pattern`, you need to pass it to the plugin via `CYPRESS_grepSpec=pattern` or `--
|
|
662
|
+
If the user selected spec(s) to run, then it might conflict with `grepFilterSpecs=true` that filters the specs. There is no way to "know" if the user used `--spec <...>` option when the plugin runs, see issues [33](https://github.com/bahmutov/cy-grep/issues/33) and [26032](https://github.com/cypress-io/cypress/issues/26032). Thus if you use `--spec pattern`, you need to pass it to the plugin via `CYPRESS_grepSpec=pattern` or `--expose grepSpec=pattern` option.
|
|
625
663
|
|
|
626
664
|
```
|
|
627
|
-
cypress run --spec a.cy.js --
|
|
665
|
+
cypress run --spec a.cy.js --expose grepTags=...,grepSpec=a.cy.js
|
|
628
666
|
```
|
|
629
667
|
|
|
630
668
|
## General advice
|
|
@@ -648,13 +686,13 @@ Grepping the tests
|
|
|
648
686
|
|
|
649
687
|
```shell
|
|
650
688
|
# run the tests by title
|
|
651
|
-
$ npx cypress run --
|
|
689
|
+
$ npx cypress run --expose grep="works quickly"
|
|
652
690
|
# run all tests tagged @smoke
|
|
653
|
-
$ npx cypress run --
|
|
691
|
+
$ npx cypress run --expose grepTags=@smoke
|
|
654
692
|
# run all tests except tagged @smoke
|
|
655
|
-
$ npx cypress run --
|
|
693
|
+
$ npx cypress run --expose grepTags=-@smoke
|
|
656
694
|
# run all tests that have tag @fast but do not have tag @smoke
|
|
657
|
-
$ npx cypress run --
|
|
695
|
+
$ npx cypress run --expose grepTags=@fast+-@smoke
|
|
658
696
|
```
|
|
659
697
|
|
|
660
698
|
I would run all tests by default, and grep tests from the command line. For example, I could run the smoke tests first using grep plugin, and if the smoke tests pass, then run all the tests. See the video [How I organize pull request workflows by running smoke tests first](https://www.youtube.com/watch?v=SFW7Ecj5TNE) and its [pull request workflow file](https://github.com/bahmutov/cypress-grep-example/blob/main/.github/workflows/pr.yml).
|
|
@@ -715,7 +753,7 @@ info This module exists because it's specified in "devDependencies".
|
|
|
715
753
|
Second, make sure you are passing the values to the plugin correctly by inspecting the "Settings" tab in the Cypress Desktop GUI screen. You should see the values you have passed in the "Config" object under the `env` property. For example, if I start the Test Runner with
|
|
716
754
|
|
|
717
755
|
```text
|
|
718
|
-
$ npx cypress open --
|
|
756
|
+
$ npx cypress open --expose grep=works,grepFilterTests=true
|
|
719
757
|
```
|
|
720
758
|
|
|
721
759
|
Then I expect to see the grep string and the "filter tests" flag in the `env` object.
|
|
@@ -731,7 +769,7 @@ This module uses [debug](https://github.com/visionmedia/debug#readme) to log ver
|
|
|
731
769
|
Start Cypress with the environment variable `DEBUG=cy-grep`. You will see a few messages from this plugin in the terminal output:
|
|
732
770
|
|
|
733
771
|
```
|
|
734
|
-
$ DEBUG=cy-grep npx cypress run --
|
|
772
|
+
$ DEBUG=cy-grep npx cypress run --expose grep=works,grepFilterSpecs=true
|
|
735
773
|
cy-grep: tests with "works" in their names
|
|
736
774
|
cy-grep: filtering specs using "works" in the title
|
|
737
775
|
cy-grep Cypress config env object: { grep: 'works', grepFilterSpecs: true }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bahmutov/cy-grep",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Filter Cypress tests using title or tags",
|
|
5
5
|
"main": "src/support.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,20 +13,20 @@
|
|
|
13
13
|
"stop-only": "stop-only --folder cypress/e2e"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"cypress-plugin-config": "^
|
|
16
|
+
"cypress-plugin-config": "^2.0.0",
|
|
17
17
|
"debug": "^4.3.2",
|
|
18
18
|
"find-cypress-specs": "^1.35.1",
|
|
19
19
|
"find-test-names": "1.29.19",
|
|
20
20
|
"globby": "^11.1.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"cypress": "15.
|
|
23
|
+
"cypress": "15.11.0",
|
|
24
24
|
"cypress-each": "^1.11.0",
|
|
25
25
|
"cypress-expect": "^3.1.0",
|
|
26
|
-
"prettier": "^3.
|
|
27
|
-
"semantic-release": "^
|
|
26
|
+
"prettier": "^3.8.1",
|
|
27
|
+
"semantic-release": "^25.0.3",
|
|
28
28
|
"stop-only": "^3.3.1",
|
|
29
|
-
"typescript": "^5.
|
|
29
|
+
"typescript": "^5.9.3"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"cypress": ">=8"
|
package/src/plugin.js
CHANGED
|
@@ -12,23 +12,27 @@ const minimatch = require('minimatch')
|
|
|
12
12
|
|
|
13
13
|
const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
|
|
14
14
|
|
|
15
|
-
const isCypressV9 = (config) => !('specPattern' in config)
|
|
16
|
-
|
|
17
15
|
function getGrepSettings(config) {
|
|
18
|
-
const { env } = config
|
|
16
|
+
const { env, expose } = config
|
|
19
17
|
|
|
20
18
|
debug('cy-grep plugin version %s', version)
|
|
21
|
-
debug('Cypress config env object: %o',
|
|
19
|
+
debug('Cypress config env object: %o', expose)
|
|
22
20
|
|
|
23
|
-
const
|
|
21
|
+
const grepStringMaybe = env.grep || expose.grep
|
|
22
|
+
const grep = grepStringMaybe ? String(grepStringMaybe) : undefined
|
|
24
23
|
|
|
25
24
|
if (grep) {
|
|
26
25
|
console.log('cy-grep: tests with "%s" in their names', grep.trim())
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
const grepPrefixAt =
|
|
28
|
+
const grepPrefixAt =
|
|
29
|
+
env.grepPrefixAt ||
|
|
30
|
+
env['grep-prefix-at'] ||
|
|
31
|
+
expose.grepPrefixAt ||
|
|
32
|
+
expose['grep-prefix-at']
|
|
30
33
|
|
|
31
|
-
const grepTags =
|
|
34
|
+
const grepTags =
|
|
35
|
+
env.grepTags || env['grep-tags'] || expose.grepTags || expose['grep-tags']
|
|
32
36
|
|
|
33
37
|
if (grepTags) {
|
|
34
38
|
console.log('cy-grep: filtering using tag(s) "%s"', grepTags)
|
|
@@ -37,25 +41,40 @@ function getGrepSettings(config) {
|
|
|
37
41
|
debug('parsed grep tags %o', parsedGrep.tags)
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
const grepBurn =
|
|
44
|
+
const grepBurn =
|
|
45
|
+
env.grepBurn ||
|
|
46
|
+
env['grep-burn'] ||
|
|
47
|
+
env.burn ||
|
|
48
|
+
expose.grepBurn ||
|
|
49
|
+
expose['grep-burn'] ||
|
|
50
|
+
expose.burn
|
|
41
51
|
|
|
42
52
|
if (grepBurn) {
|
|
43
53
|
console.log('cy-grep: running filtered tests %d times', grepBurn)
|
|
44
54
|
}
|
|
45
55
|
|
|
46
|
-
const grepUntagged =
|
|
56
|
+
const grepUntagged =
|
|
57
|
+
env.grepUntagged ||
|
|
58
|
+
env['grep-untagged'] ||
|
|
59
|
+
expose.grepUntagged ||
|
|
60
|
+
expose['grep-untagged']
|
|
47
61
|
|
|
48
62
|
if (grepUntagged) {
|
|
49
63
|
console.log('cy-grep: running untagged tests')
|
|
50
64
|
}
|
|
51
65
|
|
|
52
|
-
const omitFiltered =
|
|
66
|
+
const omitFiltered =
|
|
67
|
+
env.grepOmitFiltered ||
|
|
68
|
+
env['grep-omit-filtered'] ||
|
|
69
|
+
expose.grepOmitFiltered ||
|
|
70
|
+
expose['grep-omit-filtered']
|
|
53
71
|
|
|
54
72
|
if (omitFiltered) {
|
|
55
73
|
console.log('cy-grep: will omit filtered tests')
|
|
56
74
|
}
|
|
57
75
|
|
|
58
|
-
const grepFilterSpecs =
|
|
76
|
+
const grepFilterSpecs =
|
|
77
|
+
env.grepFilterSpecs === true || expose.grepFilterSpecs === true
|
|
59
78
|
|
|
60
79
|
if (grepPrefixAt) {
|
|
61
80
|
console.log('cy-grep: all tags will be forced to start with @')
|
|
@@ -80,7 +99,7 @@ function cypressGrepPlugin(config) {
|
|
|
80
99
|
)
|
|
81
100
|
}
|
|
82
101
|
|
|
83
|
-
if (!config || !config.
|
|
102
|
+
if (!config || !config.expose) {
|
|
84
103
|
return config
|
|
85
104
|
}
|
|
86
105
|
|
|
@@ -92,7 +111,12 @@ function cypressGrepPlugin(config) {
|
|
|
92
111
|
|
|
93
112
|
debug('found %d spec file(s)', specFiles.length)
|
|
94
113
|
debug('%o', specFiles)
|
|
95
|
-
|
|
114
|
+
// grab spec parameter from "env" or "expose"
|
|
115
|
+
const specPattern =
|
|
116
|
+
config.env?.grepSpec ||
|
|
117
|
+
config.env?.grepSpecs ||
|
|
118
|
+
config.expose?.grepSpec ||
|
|
119
|
+
config.expose?.grepSpecs
|
|
96
120
|
if (specPattern) {
|
|
97
121
|
debug('custom spec pattern: %s', specPattern)
|
|
98
122
|
// https://github.com/bahmutov/cy-grep/issues/33
|
|
@@ -164,7 +188,7 @@ function cypressGrepPlugin(config) {
|
|
|
164
188
|
tags.requiredTags.forEach((tag) => {
|
|
165
189
|
foundTags.add(tag)
|
|
166
190
|
})
|
|
167
|
-
})
|
|
191
|
+
})
|
|
168
192
|
|
|
169
193
|
return Object.keys(testTags).some((testTitle) => {
|
|
170
194
|
const effectiveTags = testTags[testTitle].effectiveTags
|
|
@@ -228,7 +252,9 @@ function cypressGrepPlugin(config) {
|
|
|
228
252
|
})
|
|
229
253
|
}
|
|
230
254
|
|
|
231
|
-
|
|
255
|
+
// grab the extra specs from either "env" or "expose" objects
|
|
256
|
+
const extraSpecsPattern =
|
|
257
|
+
config.env?.grepExtraSpecs || config.expose?.grepExtraSpecs
|
|
232
258
|
if (extraSpecsPattern) {
|
|
233
259
|
debug('processing the extra specs pattern "%s"', extraSpecsPattern)
|
|
234
260
|
const extraSpecs = resolveFilePatterns(extraSpecsPattern)
|
|
@@ -242,30 +268,13 @@ function cypressGrepPlugin(config) {
|
|
|
242
268
|
}
|
|
243
269
|
})
|
|
244
270
|
|
|
245
|
-
config.
|
|
271
|
+
config.expose.grepExtraSpecs = resolvedExtraSpecs
|
|
246
272
|
}
|
|
247
273
|
|
|
248
274
|
if (greppedSpecs.length) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const integrationFolder = config.integrationFolder
|
|
253
|
-
const relativeNames = greppedSpecs.map((filename) =>
|
|
254
|
-
path.relative(integrationFolder, filename),
|
|
255
|
-
)
|
|
256
|
-
const relativeSpecs = relativeNames.join(', ')
|
|
257
|
-
debug(
|
|
258
|
-
'specs in the integration folder %s %s',
|
|
259
|
-
integrationFolder,
|
|
260
|
-
relativeSpecs,
|
|
261
|
-
)
|
|
262
|
-
// @ts-ignore
|
|
263
|
-
config.testFiles = relativeNames
|
|
264
|
-
} else {
|
|
265
|
-
debug('setting selected %d specs (>= v10)', greppedSpecs.length)
|
|
266
|
-
// @ts-ignore
|
|
267
|
-
config.specPattern = greppedSpecs
|
|
268
|
-
}
|
|
275
|
+
debug('setting selected %d specs (>= v10)', greppedSpecs.length)
|
|
276
|
+
// @ts-ignore
|
|
277
|
+
config.specPattern = greppedSpecs
|
|
269
278
|
} else {
|
|
270
279
|
// hmm, we filtered out all specs, probably something is wrong
|
|
271
280
|
console.warn('cy-grep: grep and/or grepTags has eliminated all specs')
|
package/src/support.js
CHANGED
|
@@ -20,6 +20,10 @@ const _describe = describe
|
|
|
20
20
|
// includes both the test tags and the suite tags
|
|
21
21
|
// and the required test tags
|
|
22
22
|
const testTree = {}
|
|
23
|
+
// keeps all collected test tags by the individual test title
|
|
24
|
+
// includes both the test tags and the suite tags
|
|
25
|
+
// used to expose within a Cypress environment variable
|
|
26
|
+
const modifiedTestTree = {}
|
|
23
27
|
|
|
24
28
|
beforeEach(() => {
|
|
25
29
|
// set the test tags for the current test
|
|
@@ -27,9 +31,9 @@ beforeEach(() => {
|
|
|
27
31
|
const info = testTree[testTitle]
|
|
28
32
|
if (info) {
|
|
29
33
|
const allTags = info.effectiveTestTags.concat(info.requiredTestTags)
|
|
30
|
-
Cypress.
|
|
34
|
+
Cypress.expose('testTags', allTags)
|
|
31
35
|
} else {
|
|
32
|
-
Cypress.
|
|
36
|
+
Cypress.expose('testTags', null)
|
|
33
37
|
}
|
|
34
38
|
})
|
|
35
39
|
|
|
@@ -136,6 +140,10 @@ function registerCyGrep() {
|
|
|
136
140
|
.map((item) => item.name)
|
|
137
141
|
.concat(name)
|
|
138
142
|
.join(' ')
|
|
143
|
+
const nameOfTest = suiteStack
|
|
144
|
+
.map((item) => item.name)
|
|
145
|
+
.concat(name)
|
|
146
|
+
.pop()
|
|
139
147
|
const effectiveTestTags = suiteStack
|
|
140
148
|
.flatMap((item) => item.tags)
|
|
141
149
|
.concat(configTags)
|
|
@@ -147,6 +155,11 @@ function registerCyGrep() {
|
|
|
147
155
|
debug({ nameToGrep, effectiveTestTags, requiredTestTags })
|
|
148
156
|
testTree[nameToGrep] = { effectiveTestTags, requiredTestTags }
|
|
149
157
|
|
|
158
|
+
// Store the tags by individual name of test
|
|
159
|
+
// Expose the object within the Cypress environment variables
|
|
160
|
+
modifiedTestTree[nameOfTest] = { effectiveTestTags, requiredTestTags }
|
|
161
|
+
Cypress.expose('specTags', modifiedTestTree)
|
|
162
|
+
|
|
150
163
|
const shouldRun = shouldTestRun(
|
|
151
164
|
parsedGrep,
|
|
152
165
|
nameToGrep,
|