@bahmutov/cy-grep 1.8.0 → 1.9.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 +14 -0
- package/package.json +1 -1
- package/src/plugin.js +12 -5
- package/src/support.js +13 -2
- package/src/utils.js +15 -3
package/README.md
CHANGED
@@ -62,6 +62,7 @@ Watch the video [intro to cypress-grep plugin](https://www.youtube.com/watch?v=H
|
|
62
62
|
- [Required tags](#required-tags)
|
63
63
|
- [Negative grep](#negative-grep)
|
64
64
|
- [TypeScript support](#typescript-support)
|
65
|
+
- [grepPrefixAt](#grepprefixat)
|
65
66
|
- [General advice](#general-advice)
|
66
67
|
- [DevTools console](#devtools-console)
|
67
68
|
- [grepFailed](#grepfailed)
|
@@ -538,6 +539,19 @@ If you have `tsconfig.json` file, add this library to the types list
|
|
538
539
|
}
|
539
540
|
```
|
540
541
|
|
542
|
+
## grepPrefixAt
|
543
|
+
|
544
|
+
Using test tags that start with `@` is so common, you can enforce it using the env option `grepPrefixAt: true`. This lets you use `@tag1,@tag2, ...` or `tag1,tag2, ...` when calling.
|
545
|
+
|
546
|
+
```
|
547
|
+
# use grepPrefixAt in your env settings object
|
548
|
+
# use { tags: '@tag1' } in your tests
|
549
|
+
|
550
|
+
# then these two are equivalent
|
551
|
+
--env grepTags=@tag1
|
552
|
+
--env grepTags=tag1
|
553
|
+
```
|
554
|
+
|
541
555
|
## General advice
|
542
556
|
|
543
557
|
- keep it simple.
|
package/package.json
CHANGED
package/src/plugin.js
CHANGED
@@ -22,11 +22,13 @@ function getGrepSettings(config) {
|
|
22
22
|
console.log('cy-grep: tests with "%s" in their names', grep.trim())
|
23
23
|
}
|
24
24
|
|
25
|
+
const grepPrefixAt = env.grepPrefixAt || env['grep-prefix-at']
|
26
|
+
|
25
27
|
const grepTags = env.grepTags || env['grep-tags']
|
26
28
|
|
27
29
|
if (grepTags) {
|
28
30
|
console.log('cy-grep: filtering using tag(s) "%s"', grepTags)
|
29
|
-
const parsedGrep = parseGrep(null, grepTags)
|
31
|
+
const parsedGrep = parseGrep(null, grepTags, grepPrefixAt)
|
30
32
|
|
31
33
|
debug('parsed grep tags %o', parsedGrep.tags)
|
32
34
|
}
|
@@ -51,7 +53,11 @@ function getGrepSettings(config) {
|
|
51
53
|
|
52
54
|
const grepFilterSpecs = env.grepFilterSpecs === true
|
53
55
|
|
54
|
-
|
56
|
+
if (grepPrefixAt) {
|
57
|
+
console.log('cy-grep: all tags will be forced to start with @')
|
58
|
+
}
|
59
|
+
|
60
|
+
return { grep, grepTags, grepFilterSpecs, grepPrefixAt }
|
55
61
|
}
|
56
62
|
|
57
63
|
/**
|
@@ -63,7 +69,8 @@ function cypressGrepPlugin(config) {
|
|
63
69
|
return config
|
64
70
|
}
|
65
71
|
|
66
|
-
const { grep, grepTags, grepFilterSpecs } =
|
72
|
+
const { grep, grepTags, grepFilterSpecs, grepPrefixAt } =
|
73
|
+
getGrepSettings(config)
|
67
74
|
|
68
75
|
if (grepFilterSpecs) {
|
69
76
|
const specFiles = getSpecs(config)
|
@@ -74,7 +81,7 @@ function cypressGrepPlugin(config) {
|
|
74
81
|
|
75
82
|
if (grep) {
|
76
83
|
console.log('cy-grep: filtering specs using "%s" in the title', grep)
|
77
|
-
const parsedGrep = parseGrep(grep)
|
84
|
+
const parsedGrep = parseGrep(grep, undefined, grepPrefixAt)
|
78
85
|
|
79
86
|
debug('parsed grep %o', parsedGrep)
|
80
87
|
greppedSpecs = specFiles.filter((specFile) => {
|
@@ -105,7 +112,7 @@ function cypressGrepPlugin(config) {
|
|
105
112
|
debug('found grep "%s" in %d specs', grep, greppedSpecs.length)
|
106
113
|
debug('%o', greppedSpecs)
|
107
114
|
} else if (grepTags) {
|
108
|
-
const parsedGrep = parseGrep(null, grepTags)
|
115
|
+
const parsedGrep = parseGrep(null, grepTags, grepPrefixAt)
|
109
116
|
debug('parsed grep tags %o', parsedGrep)
|
110
117
|
const mentionedTags = getMentionedTags(grepTags)
|
111
118
|
debug('user mentioned tags %o', mentionedTags)
|
package/src/support.js
CHANGED
@@ -61,12 +61,23 @@ function registerCyGrep() {
|
|
61
61
|
getPluginConfigValue('grepOmitFiltered') ||
|
62
62
|
getPluginConfigValue('grep-omit-filtered')
|
63
63
|
|
64
|
-
|
64
|
+
const grepPrefixAt =
|
65
|
+
getPluginConfigValue('grepPrefixAt') ||
|
66
|
+
getPluginConfigValue('grep-prefix-at')
|
67
|
+
|
68
|
+
debug('grep %o', {
|
69
|
+
grep,
|
70
|
+
grepTags,
|
71
|
+
grepBurn,
|
72
|
+
omitFiltered,
|
73
|
+
grepPrefixAt,
|
74
|
+
version,
|
75
|
+
})
|
65
76
|
if (!Cypress._.isInteger(grepBurn) || grepBurn < 1) {
|
66
77
|
throw new Error(`Invalid grep burn value: ${grepBurn}`)
|
67
78
|
}
|
68
79
|
|
69
|
-
const parsedGrep = parseGrep(grep, grepTags)
|
80
|
+
const parsedGrep = parseGrep(grep, grepTags, grepPrefixAt)
|
70
81
|
|
71
82
|
debug('parsed grep %o', parsedGrep)
|
72
83
|
|
package/src/utils.js
CHANGED
@@ -38,12 +38,13 @@ function parseFullTitleGrep(s) {
|
|
38
38
|
/**
|
39
39
|
* Parses tags to grep for.
|
40
40
|
* @param {string|string[]} s Tags string like "@tag1+@tag2", or array of tags
|
41
|
+
* @param {boolean} grepPrefixAt Prefix all tags with "@" if needed
|
41
42
|
* @example
|
42
43
|
* parseTagsGrep('@tag1+@tag2')
|
43
44
|
* @example
|
44
45
|
* parseTagsGrep(['@tag1', '@tag2'])
|
45
46
|
*/
|
46
|
-
function parseTagsGrep(s) {
|
47
|
+
function parseTagsGrep(s, grepPrefixAt = false) {
|
47
48
|
if (!s) {
|
48
49
|
return []
|
49
50
|
}
|
@@ -99,6 +100,17 @@ function parseTagsGrep(s) {
|
|
99
100
|
}
|
100
101
|
}
|
101
102
|
|
103
|
+
if (grepPrefixAt) {
|
104
|
+
const prefix = '@'
|
105
|
+
ORS_filtered.forEach((OR) => {
|
106
|
+
OR.forEach((token) => {
|
107
|
+
if (token.tag && !token.tag.startsWith(prefix)) {
|
108
|
+
token.tag = prefix + token.tag
|
109
|
+
}
|
110
|
+
})
|
111
|
+
})
|
112
|
+
}
|
113
|
+
|
102
114
|
return ORS_filtered
|
103
115
|
}
|
104
116
|
|
@@ -229,10 +241,10 @@ function shouldTestRun(
|
|
229
241
|
)
|
230
242
|
}
|
231
243
|
|
232
|
-
function parseGrep(titlePart, tags) {
|
244
|
+
function parseGrep(titlePart, tags, grepPrefixAt) {
|
233
245
|
return {
|
234
246
|
title: parseFullTitleGrep(titlePart),
|
235
|
-
tags: parseTagsGrep(tags),
|
247
|
+
tags: parseTagsGrep(tags, grepPrefixAt),
|
236
248
|
}
|
237
249
|
}
|
238
250
|
|