@bahmutov/cy-grep 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +13 -51
- package/package.json +4 -4
- package/src/plugin.js +11 -11
- package/src/support.js +4 -6
package/README.md
CHANGED
@@ -56,9 +56,6 @@ Table of Contents
|
|
56
56
|
- [Debugging in the browser](#debugging-in-the-browser)
|
57
57
|
- [Examples](#examples)
|
58
58
|
- [See also](#see-also)
|
59
|
-
- [Migration guide](#migration-guide)
|
60
|
-
- [from v1 to v2](#from-v1-to-v2)
|
61
|
-
- [from v2 to v3](#from-v2-to-v3)
|
62
59
|
- [Small Print](#small-print)
|
63
60
|
|
64
61
|
<!-- /MarkdownTOC -->
|
@@ -217,8 +214,6 @@ $ npx cypress run --env grep="-hello world"
|
|
217
214
|
$ npx cypress run --env grep="hello; -world"
|
218
215
|
```
|
219
216
|
|
220
|
-
**Note:** Inverted title filter is not compatible with the `grepFilterSpecs` option
|
221
|
-
|
222
217
|
## Filter with tags
|
223
218
|
|
224
219
|
You can select tests to run or skip using tags by passing `--env grepTags=...` value.
|
@@ -547,30 +542,28 @@ This module uses [debug](https://github.com/visionmedia/debug#readme) to log ver
|
|
547
542
|
|
548
543
|
### Debugging in the plugin
|
549
544
|
|
550
|
-
Start Cypress with the environment variable `DEBUG=
|
545
|
+
Start Cypress with the environment variable `DEBUG=cy-grep`. You will see a few messages from this plugin in the terminal output:
|
551
546
|
|
552
547
|
```
|
553
|
-
$ DEBUG=
|
554
|
-
|
555
|
-
|
556
|
-
|
548
|
+
$ DEBUG=cy-grep npx cypress run --env grep=works,grepFilterSpecs=true
|
549
|
+
cy-grep: tests with "works" in their names
|
550
|
+
cy-grep: filtering specs using "works" in the title
|
551
|
+
cy-grep Cypress config env object: { grep: 'works', grepFilterSpecs: true }
|
557
552
|
...
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
553
|
+
cy-grep found 1 spec files +5ms
|
554
|
+
cy-grep [ 'spec.js' ] +0ms
|
555
|
+
cy-grep spec file spec.js +5ms
|
556
|
+
cy-grep suite and test names: [ 'hello world', 'works', 'works 2 @tag1',
|
562
557
|
'works 2 @tag1 @tag2', 'works @tag2' ] +0ms
|
563
|
-
|
564
|
-
|
558
|
+
cy-grep found "works" in 1 specs +0ms
|
559
|
+
cy-grep [ 'spec.js' ] +0ms
|
565
560
|
```
|
566
561
|
|
567
562
|
### Debugging in the browser
|
568
563
|
|
569
|
-
To enable debug console messages in the browser, from the DevTools console set `localStorage.debug='
|
570
|
-
|
571
|
-
![Debug messages](./images/debug.png)
|
564
|
+
To enable debug console messages in the browser, from the DevTools console set `localStorage.debug='cy-grep'` and run the tests again.
|
572
565
|
|
573
|
-
To see how to debug this plugin, watch the video [Debug cypress-grep Plugin](https://youtu.be/4YMAERddHYA)
|
566
|
+
To see how to debug this plugin, watch the video [Debug cypress-grep Plugin](https://youtu.be/4YMAERddHYA) but use the string `cy-grep`
|
574
567
|
|
575
568
|
## Examples
|
576
569
|
|
@@ -582,37 +575,6 @@ To see how to debug this plugin, watch the video [Debug cypress-grep Plugin](htt
|
|
582
575
|
- [cypress-select-tests](https://github.com/bahmutov/cypress-select-tests)
|
583
576
|
- [cypress-skip-test](https://github.com/cypress-io/cypress-skip-test)
|
584
577
|
|
585
|
-
## Migration guide
|
586
|
-
|
587
|
-
### from v1 to v2
|
588
|
-
|
589
|
-
In v2 we have separated grepping by part of the title string from tags.
|
590
|
-
|
591
|
-
**v1**
|
592
|
-
|
593
|
-
```
|
594
|
-
--env grep="one two"
|
595
|
-
```
|
596
|
-
|
597
|
-
The above scenario was confusing - did you want to find all tests with title containing "one two" or did you want to run tests tagged `one` or `two`?
|
598
|
-
|
599
|
-
**v2**
|
600
|
-
|
601
|
-
```
|
602
|
-
# enable the tests with string "one two" in their titles
|
603
|
-
--env grep="one two"
|
604
|
-
# enable the tests with tag "one" or "two"
|
605
|
-
--env grepTags="one two"
|
606
|
-
# enable the tests with both tags "one" and "two"
|
607
|
-
--env grepTags="one+two"
|
608
|
-
# enable the tests with "hello" in the title and tag "smoke"
|
609
|
-
--env grep=hello,grepTags=smoke
|
610
|
-
```
|
611
|
-
|
612
|
-
### from v2 to v3
|
613
|
-
|
614
|
-
Version >= 3 of cypress-grep _only_ supports Cypress >= 10.
|
615
|
-
|
616
578
|
## Small Print
|
617
579
|
|
618
580
|
License: MIT - do anything with the code, but don't blame me if it does not work.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bahmutov/cy-grep",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.1",
|
4
4
|
"description": "Filter Cypress tests using title or tags",
|
5
5
|
"main": "src/support.js",
|
6
6
|
"scripts": {
|
@@ -12,15 +12,15 @@
|
|
12
12
|
"dependencies": {
|
13
13
|
"cypress-plugin-config": "^1.2.0",
|
14
14
|
"debug": "^4.3.2",
|
15
|
-
"find-test-names": "^1.
|
15
|
+
"find-test-names": "^1.23.0",
|
16
16
|
"globby": "^11.0.4"
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
|
-
"cypress": "12.
|
19
|
+
"cypress": "12.3.0",
|
20
20
|
"cypress-each": "^1.11.0",
|
21
21
|
"cypress-expect": "^2.5.3",
|
22
22
|
"prettier": "^2.8.1",
|
23
|
-
"semantic-release": "^
|
23
|
+
"semantic-release": "^20.0.2",
|
24
24
|
"typescript": "^4.7.4"
|
25
25
|
},
|
26
26
|
"peerDependencies": {
|
package/src/plugin.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const debug = require('debug')('
|
1
|
+
const debug = require('debug')('cy-grep')
|
2
2
|
const globby = require('globby')
|
3
3
|
const { getTestNames, findEffectiveTestTags } = require('find-test-names')
|
4
4
|
const fs = require('fs')
|
@@ -6,7 +6,7 @@ const { version } = require('../package.json')
|
|
6
6
|
const { parseGrep, shouldTestRun } = require('./utils')
|
7
7
|
|
8
8
|
/**
|
9
|
-
* Prints the
|
9
|
+
* Prints the cy-grep environment values if any.
|
10
10
|
* @param {Cypress.ConfigOptions} config
|
11
11
|
*/
|
12
12
|
function cypressGrepPlugin(config) {
|
@@ -18,23 +18,23 @@ function cypressGrepPlugin(config) {
|
|
18
18
|
|
19
19
|
if (!config.specPattern) {
|
20
20
|
throw new Error(
|
21
|
-
'Incompatible versions detected,
|
21
|
+
'Incompatible versions detected, cy-grep requires Cypress 10.0.0+',
|
22
22
|
)
|
23
23
|
}
|
24
24
|
|
25
|
-
debug('
|
25
|
+
debug('cy-grep plugin version %s', version)
|
26
26
|
debug('Cypress config env object: %o', env)
|
27
27
|
|
28
28
|
const grep = env.grep ? String(env.grep) : undefined
|
29
29
|
|
30
30
|
if (grep) {
|
31
|
-
console.log('
|
31
|
+
console.log('cy-grep: tests with "%s" in their names', grep.trim())
|
32
32
|
}
|
33
33
|
|
34
34
|
const grepTags = env.grepTags || env['grep-tags']
|
35
35
|
|
36
36
|
if (grepTags) {
|
37
|
-
console.log('
|
37
|
+
console.log('cy-grep: filtering using tag(s) "%s"', grepTags)
|
38
38
|
const parsedGrep = parseGrep(null, grepTags)
|
39
39
|
|
40
40
|
debug('parsed grep tags %o', parsedGrep.tags)
|
@@ -43,19 +43,19 @@ function cypressGrepPlugin(config) {
|
|
43
43
|
const grepBurn = env.grepBurn || env['grep-burn'] || env.burn
|
44
44
|
|
45
45
|
if (grepBurn) {
|
46
|
-
console.log('
|
46
|
+
console.log('cy-grep: running filtered tests %d times', grepBurn)
|
47
47
|
}
|
48
48
|
|
49
49
|
const grepUntagged = env.grepUntagged || env['grep-untagged']
|
50
50
|
|
51
51
|
if (grepUntagged) {
|
52
|
-
console.log('
|
52
|
+
console.log('cy-grep: running untagged tests')
|
53
53
|
}
|
54
54
|
|
55
55
|
const omitFiltered = env.grepOmitFiltered || env['grep-omit-filtered']
|
56
56
|
|
57
57
|
if (omitFiltered) {
|
58
|
-
console.log('
|
58
|
+
console.log('cy-grep: will omit filtered tests')
|
59
59
|
}
|
60
60
|
|
61
61
|
const { specPattern, excludeSpecPattern } = config
|
@@ -78,7 +78,7 @@ function cypressGrepPlugin(config) {
|
|
78
78
|
let greppedSpecs = []
|
79
79
|
|
80
80
|
if (grep) {
|
81
|
-
console.log('
|
81
|
+
console.log('cy-grep: filtering specs using "%s" in the title', grep)
|
82
82
|
const parsedGrep = parseGrep(grep)
|
83
83
|
|
84
84
|
debug('parsed grep %o', parsedGrep)
|
@@ -123,7 +123,7 @@ function cypressGrepPlugin(config) {
|
|
123
123
|
debug('spec file %s', specFile)
|
124
124
|
debug('effective test tags %o', testTags)
|
125
125
|
return Object.keys(testTags).some((testTitle) => {
|
126
|
-
const effectiveTags = testTags[testTitle]
|
126
|
+
const effectiveTags = testTags[testTitle].effectiveTags
|
127
127
|
return shouldTestRun(parsedGrep, null, effectiveTags)
|
128
128
|
})
|
129
129
|
} catch (err) {
|
package/src/support.js
CHANGED
@@ -8,7 +8,8 @@ const {
|
|
8
8
|
getPluginConfigValue,
|
9
9
|
setPluginConfigValue,
|
10
10
|
} = require('cypress-plugin-config')
|
11
|
-
|
11
|
+
// to debug in the browser, set the "localStorage.debug='cy-grep'"
|
12
|
+
const debug = require('debug')('cy-grep')
|
12
13
|
|
13
14
|
debug.log = console.info.bind(console)
|
14
15
|
|
@@ -18,7 +19,7 @@ const _describe = describe
|
|
18
19
|
|
19
20
|
/**
|
20
21
|
* Wraps the "it" and "describe" functions that support tags.
|
21
|
-
* @see https://github.com/
|
22
|
+
* @see https://github.com/bahmutov/cy-grep
|
22
23
|
*/
|
23
24
|
function cypressGrep() {
|
24
25
|
/** @type {string} Part of the test title go grep */
|
@@ -70,9 +71,8 @@ function cypressGrep() {
|
|
70
71
|
debug('parsed grep %o', parsedGrep)
|
71
72
|
|
72
73
|
// prevent multiple registrations
|
73
|
-
// https://github.com/cypress-io/cypress-grep/issues/59
|
74
74
|
if (it.name === 'itGrep') {
|
75
|
-
debug('already registered
|
75
|
+
debug('already registered cy-grep')
|
76
76
|
|
77
77
|
return
|
78
78
|
}
|
@@ -205,7 +205,6 @@ function cypressGrep() {
|
|
205
205
|
it.skip = _it.skip
|
206
206
|
it.only = _it.only
|
207
207
|
// preserve "it.each" method if found
|
208
|
-
// https://github.com/cypress-io/cypress-grep/issues/72
|
209
208
|
if (typeof _it.each === 'function') {
|
210
209
|
it.each = _it.each
|
211
210
|
}
|
@@ -237,7 +236,6 @@ if (!Cypress.grep) {
|
|
237
236
|
* // remove all current grep settings
|
238
237
|
* // and run all tests
|
239
238
|
* Cypress.grep()
|
240
|
-
* @see "Grep from DevTools console" https://github.com/cypress-io/cypress-grep#devtools-console
|
241
239
|
*/
|
242
240
|
Cypress.grep = function grep(grep, tags, burn) {
|
243
241
|
setPluginConfigValue('grep', grep)
|