find-cypress-specs 1.16.0 → 1.17.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 CHANGED
@@ -47,6 +47,16 @@ $ npx find-cypress-specs --branch main --count
47
47
  5
48
48
  ```
49
49
 
50
+ ### filter by a tag
51
+
52
+ You can filter all changed specs and only report (and count) the specs that have changed AND include the given tag(s)
53
+
54
+ ```bash
55
+ $ npx find-cypress-specs --branch main --tagged @user,@preview
56
+ # prints only some specs, the ones that have changed against the "origin/main"
57
+ # and that have any tests or suites inside tagged "@user" or "@preview"
58
+ ```
59
+
50
60
  ## Test names
51
61
 
52
62
  You can print each spec file with the suite and test names inside of it (found using [find-test-names](https://github.com/bahmutov/find-test-names))
package/bin/find.js CHANGED
@@ -115,7 +115,29 @@ if (args['--names'] || args['--tags']) {
115
115
  debug('determining specs changed against branch %s', args['--branch'])
116
116
  const changedFiles = findChangedFiles(args['--branch'], args['--parent'])
117
117
  debug('changed files %o', changedFiles)
118
- const changedSpecs = specs.filter((file) => changedFiles.includes(file))
118
+ debug('comparing against the specs %o', specs)
119
+ let changedSpecs = specs.filter((file) => changedFiles.includes(file))
120
+ debug('changed specs %o', changedSpecs)
121
+
122
+ if (args['--tagged']) {
123
+ const splitTags = args['--tagged']
124
+ .split(',')
125
+ .map((s) => s.trim())
126
+ .filter(Boolean)
127
+ debug('filtering changed specs by tags %o', splitTags)
128
+ changedSpecs = changedSpecs.filter((file) => {
129
+ const source = fs.readFileSync(file, 'utf8')
130
+ const result = getTestNames(source, true)
131
+ const specTagCounts = countTags(result.structure)
132
+ const specHasTags = Object.keys(specTagCounts).some((tag) =>
133
+ splitTags.includes(tag),
134
+ )
135
+ debug('spec %s has tags? %o', file, specHasTags)
136
+
137
+ return specHasTags
138
+ })
139
+ }
140
+
119
141
  if (args['--count']) {
120
142
  console.log(changedSpecs.length)
121
143
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
@@ -43,7 +43,9 @@
43
43
  "cypress": "9.5.3",
44
44
  "execa-wrap": "^1.4.0",
45
45
  "prettier": "^2.5.1",
46
+ "really-need": "^1.9.2",
46
47
  "semantic-release": "19.0.2",
48
+ "sinon": "^13.0.1",
47
49
  "typescript": "^4.6.3"
48
50
  },
49
51
  "dependencies": {
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ const path = require('path')
4
4
  const globby = require('globby')
5
5
  const minimatch = require('minimatch')
6
6
  const shell = require('shelljs')
7
+ const pluralize = require('pluralize')
7
8
 
8
9
  const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
9
10
 
@@ -139,7 +140,10 @@ function findChangedFiles(branch, useParent) {
139
140
  return []
140
141
  }
141
142
 
142
- const filenames = result.stdout.split('\n').filter(Boolean)
143
+ const filenames = result.stdout
144
+ .split('\n')
145
+ .filter(Boolean)
146
+ .map((s) => s.trim())
143
147
  return filenames
144
148
  } else {
145
149
  const command = `git diff --name-only --diff-filter=AMR origin/${branch}`
@@ -151,7 +155,15 @@ function findChangedFiles(branch, useParent) {
151
155
  return []
152
156
  }
153
157
 
154
- const filenames = result.stdout.split('\n').filter(Boolean)
158
+ const filenames = result.stdout
159
+ .split('\n')
160
+ .filter(Boolean)
161
+ .map((s) => s.trim())
162
+ debug(
163
+ 'found %d changed %s',
164
+ filenames.length,
165
+ pluralize('file', filenames.length),
166
+ )
155
167
  return filenames
156
168
  }
157
169
  }