@bahmutov/cy-grep 1.8.0 → 1.9.1

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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bahmutov/cy-grep",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "Filter Cypress tests using title or tags",
5
5
  "main": "src/support.js",
6
6
  "scripts": {
@@ -8,7 +8,8 @@
8
8
  "cy:open": "cypress open --e2e -b electron --config specPattern='**/unit.js'",
9
9
  "badges": "npx -p dependency-version-badge update-badge cypress",
10
10
  "semantic-release": "semantic-release",
11
- "deps": "npm audit --report --omit dev"
11
+ "deps": "npm audit --report --omit dev",
12
+ "stop-only": "stop-only --folder cypress/e2e"
12
13
  },
13
14
  "dependencies": {
14
15
  "cypress-plugin-config": "^1.2.0",
@@ -23,6 +24,7 @@
23
24
  "cypress-expect": "^3.1.0",
24
25
  "prettier": "^2.8.1",
25
26
  "semantic-release": "^20.1.3",
27
+ "stop-only": "^3.3.1",
26
28
  "typescript": "^4.7.4"
27
29
  },
28
30
  "peerDependencies": {
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
- return { grep, grepTags, grepFilterSpecs }
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 } = getGrepSettings(config)
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,9 +112,9 @@ 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
- const mentionedTags = getMentionedTags(grepTags)
117
+ const mentionedTags = getMentionedTags(grepTags, grepPrefixAt)
111
118
  debug('user mentioned tags %o', mentionedTags)
112
119
  // unique tags found across all specs we search
113
120
  const foundTags = new Set()
package/src/support.js CHANGED
@@ -61,12 +61,23 @@ function registerCyGrep() {
61
61
  getPluginConfigValue('grepOmitFiltered') ||
62
62
  getPluginConfigValue('grep-omit-filtered')
63
63
 
64
- debug('grep %o', { grep, grepTags, grepBurn, omitFiltered, version })
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
 
@@ -106,9 +118,11 @@ function parseTagsGrep(s) {
106
118
  * Given a user string of tags to find, with various connectors,
107
119
  * returns the list of just the tags themselves. Could be used to
108
120
  * quickly filter test specs or find misspelled tags.
121
+ * @param {string} s String of tags passed by the user
122
+ * @param {boolean} grepPrefixAt Enforce the `@` character at the start of each tag
109
123
  * @returns {string[]} list of unique tags
110
124
  */
111
- function getMentionedTags(s) {
125
+ function getMentionedTags(s, grepPrefixAt = false) {
112
126
  if (!s) {
113
127
  return []
114
128
  }
@@ -120,6 +134,15 @@ function getMentionedTags(s) {
120
134
  // remove any "-" at the start of the tag
121
135
  // because these are to signal inverted tags
122
136
  .map((s) => (s.startsWith('-') ? s.slice(1) : s))
137
+ .map((tag) => {
138
+ if (grepPrefixAt) {
139
+ if (!tag.startsWith('@')) {
140
+ return '@' + tag
141
+ }
142
+ }
143
+
144
+ return tag
145
+ })
123
146
  const uniqueTags = [...new Set(tags)]
124
147
  return uniqueTags.sort()
125
148
  }
@@ -229,10 +252,10 @@ function shouldTestRun(
229
252
  )
230
253
  }
231
254
 
232
- function parseGrep(titlePart, tags) {
255
+ function parseGrep(titlePart, tags, grepPrefixAt) {
233
256
  return {
234
257
  title: parseFullTitleGrep(titlePart),
235
- tags: parseTagsGrep(tags),
258
+ tags: parseTagsGrep(tags, grepPrefixAt),
236
259
  }
237
260
  }
238
261