find-cypress-specs 1.30.2 → 1.31.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 +25 -0
- package/bin/find.js +62 -51
- package/package.json +1 -1
- package/src/index.js +5 -2
package/README.md
CHANGED
|
@@ -10,6 +10,15 @@ cypress/e2e/spec.js,cypress/e2e/featureA/user.js
|
|
|
10
10
|
|
|
11
11
|
Supports JS and TS specs
|
|
12
12
|
|
|
13
|
+
## Count
|
|
14
|
+
|
|
15
|
+
You can count the number of specs found
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
$ npx find-cypress-specs --count
|
|
19
|
+
2
|
|
20
|
+
```
|
|
21
|
+
|
|
13
22
|
## Component specs
|
|
14
23
|
|
|
15
24
|
By default, it finds the E2E specs and tests. You can find component specs using `--component` CLI option
|
|
@@ -102,6 +111,15 @@ $ npx find-cypress-specs --branch main --tagged @user,@preview
|
|
|
102
111
|
# and that have any tests or suites inside tagged "@user" or "@preview"
|
|
103
112
|
```
|
|
104
113
|
|
|
114
|
+
### count tagged changed specs
|
|
115
|
+
|
|
116
|
+
Let's say we changed 2 specs that have tests tagged `@user`. We can output the count by adding `--count` option
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
$ npx find-cypress-specs --branch main --tagged @user --count
|
|
120
|
+
2
|
|
121
|
+
```
|
|
122
|
+
|
|
105
123
|
## Test names
|
|
106
124
|
|
|
107
125
|
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))
|
|
@@ -170,6 +188,13 @@ $ npx find-cypress-specs --tagged <single tag>
|
|
|
170
188
|
# cypress/e2e/spec.cy.js,cypress/e2e/featureA/user.cy.ts
|
|
171
189
|
```
|
|
172
190
|
|
|
191
|
+
You can print the number of found tagged specs by adding `--count` argument
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
$ npx find-cypress-specs --tagged <single tag>
|
|
195
|
+
3
|
|
196
|
+
```
|
|
197
|
+
|
|
173
198
|
## File names filtered by multiple tags
|
|
174
199
|
|
|
175
200
|
```
|
package/bin/find.js
CHANGED
|
@@ -61,55 +61,7 @@ const specType = args['--component'] ? 'component' : 'e2e'
|
|
|
61
61
|
|
|
62
62
|
const specs = getSpecs(undefined, specType)
|
|
63
63
|
|
|
64
|
-
if (args['--
|
|
65
|
-
// counts the number of tests for each tag across all specs
|
|
66
|
-
const { jsonResults, tagTestCounts } = getTests(specs, {
|
|
67
|
-
tags: args['--tags'],
|
|
68
|
-
tagged: args['--tagged'],
|
|
69
|
-
skipped: args['--skipped'],
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
if (args['--names']) {
|
|
73
|
-
if (args['--count']) {
|
|
74
|
-
let n = 0
|
|
75
|
-
Object.keys(jsonResults).forEach((filename) => {
|
|
76
|
-
const skippedCount = jsonResults[filename].counts.pending
|
|
77
|
-
n += skippedCount
|
|
78
|
-
})
|
|
79
|
-
console.log(n)
|
|
80
|
-
} else {
|
|
81
|
-
if (args['--json']) {
|
|
82
|
-
console.log(JSON.stringify(jsonResults, null, 2))
|
|
83
|
-
} else {
|
|
84
|
-
const str = stringAllInfo(jsonResults)
|
|
85
|
-
console.log(str)
|
|
86
|
-
}
|
|
87
|
-
console.log('')
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (args['--tags']) {
|
|
92
|
-
const tagEntries = Object.entries(tagTestCounts)
|
|
93
|
-
const sortedTagEntries = tagEntries.sort((a, b) => {
|
|
94
|
-
// every entry is [tag, count], so compare the tags
|
|
95
|
-
return a[0].localeCompare(b[0])
|
|
96
|
-
})
|
|
97
|
-
if (args['--json']) {
|
|
98
|
-
// assemble a json object with the tag counts
|
|
99
|
-
const tagResults = Object.fromEntries(sortedTagEntries)
|
|
100
|
-
console.log(JSON.stringify(tagResults, null, 2))
|
|
101
|
-
} else {
|
|
102
|
-
const table = consoleTable.getTable(['Tag', 'Tests'], sortedTagEntries)
|
|
103
|
-
console.log(table)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!args['--names'] && !args['--tags']) {
|
|
108
|
-
debug('printing the spec names list only')
|
|
109
|
-
const specNames = Object.keys(jsonResults).join(',')
|
|
110
|
-
console.log(specNames)
|
|
111
|
-
}
|
|
112
|
-
} else if (args['--branch']) {
|
|
64
|
+
if (args['--branch']) {
|
|
113
65
|
debug('determining specs changed against branch %s', args['--branch'])
|
|
114
66
|
let changedFiles = findChangedFiles(args['--branch'], args['--parent'])
|
|
115
67
|
debug('changed files %o', changedFiles)
|
|
@@ -205,7 +157,66 @@ if (args['--names'] || args['--tags'] || args['--tagged']) {
|
|
|
205
157
|
} else {
|
|
206
158
|
console.log(changedSpecs.join(','))
|
|
207
159
|
}
|
|
160
|
+
} else if (args['--names'] || args['--tags'] || args['--tagged']) {
|
|
161
|
+
// counts the number of tests for each tag across all specs
|
|
162
|
+
const { jsonResults, tagTestCounts } = getTests(specs, {
|
|
163
|
+
tags: args['--tags'],
|
|
164
|
+
tagged: args['--tagged'],
|
|
165
|
+
skipped: args['--skipped'],
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
if (args['--names']) {
|
|
169
|
+
if (args['--count']) {
|
|
170
|
+
let n = 0
|
|
171
|
+
Object.keys(jsonResults).forEach((filename) => {
|
|
172
|
+
const skippedCount = jsonResults[filename].counts.pending
|
|
173
|
+
n += skippedCount
|
|
174
|
+
})
|
|
175
|
+
console.log(n)
|
|
176
|
+
} else {
|
|
177
|
+
if (args['--json']) {
|
|
178
|
+
console.log(JSON.stringify(jsonResults, null, 2))
|
|
179
|
+
} else {
|
|
180
|
+
const str = stringAllInfo(jsonResults)
|
|
181
|
+
console.log(str)
|
|
182
|
+
}
|
|
183
|
+
console.log('')
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (args['--tags']) {
|
|
188
|
+
const tagEntries = Object.entries(tagTestCounts)
|
|
189
|
+
const sortedTagEntries = tagEntries.sort((a, b) => {
|
|
190
|
+
// every entry is [tag, count], so compare the tags
|
|
191
|
+
return a[0].localeCompare(b[0])
|
|
192
|
+
})
|
|
193
|
+
if (args['--json']) {
|
|
194
|
+
// assemble a json object with the tag counts
|
|
195
|
+
const tagResults = Object.fromEntries(sortedTagEntries)
|
|
196
|
+
console.log(JSON.stringify(tagResults, null, 2))
|
|
197
|
+
} else {
|
|
198
|
+
const table = consoleTable.getTable(['Tag', 'Tests'], sortedTagEntries)
|
|
199
|
+
console.log(table)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!args['--names'] && !args['--tags']) {
|
|
204
|
+
const specs = Object.keys(jsonResults)
|
|
205
|
+
if (args['--count']) {
|
|
206
|
+
debug('printing the number of specs %d', specs.length)
|
|
207
|
+
console.log(specs.length)
|
|
208
|
+
} else {
|
|
209
|
+
debug('printing the spec names list only')
|
|
210
|
+
const specNames = specs.join(',')
|
|
211
|
+
console.log(specNames)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
208
214
|
} else {
|
|
209
|
-
|
|
210
|
-
|
|
215
|
+
if (args['--count']) {
|
|
216
|
+
debug('printing the number of specs %d', specs.length)
|
|
217
|
+
console.log(specs.length)
|
|
218
|
+
} else {
|
|
219
|
+
debug('printing just %d spec names', specs.length)
|
|
220
|
+
console.log(specs.join(','))
|
|
221
|
+
}
|
|
211
222
|
}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -295,8 +295,11 @@ function findChangedFiles(branch, useParent) {
|
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
// can we find updated and added files?
|
|
298
|
-
|
|
299
|
-
|
|
298
|
+
debug(
|
|
299
|
+
'finding changed files against %s using parent?',
|
|
300
|
+
branch,
|
|
301
|
+
Boolean(useParent),
|
|
302
|
+
)
|
|
300
303
|
|
|
301
304
|
if (useParent) {
|
|
302
305
|
let result = shell.exec(`git merge-base origin/${branch} HEAD`, {
|