find-cypress-specs 1.25.3 → 1.26.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 +29 -1
- package/bin/find.js +36 -85
- package/package.json +5 -5
- package/src/index.js +71 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# find-cypress-specs [![renovate-app badge][renovate-badge]][renovate-app]  [](https://github.com/bahmutov/find-cypress-specs/actions/workflows/ci.yml)
|
|
2
2
|
|
|
3
3
|
> Find Cypress spec files using the config settings
|
|
4
4
|
|
|
@@ -224,6 +224,8 @@ You can see how Cypress finds the specs using `DEBUG=cypress:cli,cypress:server:
|
|
|
224
224
|
|
|
225
225
|
Run the utility with environment variable `DEBUG=find-cypress-specs` to see the verbose logs
|
|
226
226
|
|
|
227
|
+

|
|
228
|
+
|
|
227
229
|
## Videos
|
|
228
230
|
|
|
229
231
|
- [Use Ava Snapshots And Execa-wrap To Write End-to-End Tests For CLI Utilities](https://youtu.be/rsw17RqP0G0)
|
|
@@ -237,6 +239,8 @@ Run the utility with environment variable `DEBUG=find-cypress-specs` to see the
|
|
|
237
239
|
|
|
238
240
|
You can use this module via its NPM module API.
|
|
239
241
|
|
|
242
|
+
### getSpecs
|
|
243
|
+
|
|
240
244
|
```js
|
|
241
245
|
const { getSpecs } = require('find-cypress-specs')
|
|
242
246
|
// somewhere in the cypress.config.js
|
|
@@ -246,6 +250,30 @@ setupNodeEvents(on, config) {
|
|
|
246
250
|
}
|
|
247
251
|
```
|
|
248
252
|
|
|
253
|
+
You can pass the `config` object to the `getSpecs` method. If there is no `config` parameter, it will read the config file automatically.
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
const specs = getSpecs({
|
|
257
|
+
e2e: {
|
|
258
|
+
specPattern: '*/e2e/featureA/*.cy.ts',
|
|
259
|
+
},
|
|
260
|
+
})
|
|
261
|
+
// ['cypress/e2e/featureA/spec.cy.ts']
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### getTests
|
|
265
|
+
|
|
266
|
+
Returns an object with individual test information
|
|
267
|
+
|
|
268
|
+
```js
|
|
269
|
+
const { getTests } = require('find-cypress-specs')
|
|
270
|
+
const { jsonResults, tagTestCounts } = getTests()
|
|
271
|
+
// jsonResults is an object
|
|
272
|
+
// with an entry per spec file
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
See [get-tests.js](./test/npm/get-tests.js) for details and examples.
|
|
276
|
+
|
|
249
277
|
## Small print
|
|
250
278
|
|
|
251
279
|
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
|
package/bin/find.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const arg = require('arg')
|
|
4
|
-
const { getSpecs,
|
|
5
|
-
const { pickTaggedTestsFrom, leavePendingTestsOnly } = require('../src/tagged')
|
|
6
|
-
const { addCounts } = require('../src/count')
|
|
4
|
+
const { getSpecs, findChangedFiles, getTests } = require('../src')
|
|
7
5
|
const { stringAllInfo } = require('../src/print')
|
|
8
6
|
|
|
9
7
|
const fs = require('fs')
|
|
@@ -60,92 +58,45 @@ debug('arguments %o', args)
|
|
|
60
58
|
|
|
61
59
|
const specs = getSpecs()
|
|
62
60
|
if (args['--names'] || args['--tags']) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
tests: [],
|
|
78
|
-
}
|
|
79
|
-
const source = fs.readFileSync(filename, 'utf8')
|
|
80
|
-
const result = getTestNames(source, true)
|
|
81
|
-
// enable if need to debug the parsed test
|
|
82
|
-
// console.dir(result.structure, { depth: null })
|
|
83
|
-
collectResults(result.structure, jsonResults[filename].tests)
|
|
84
|
-
|
|
85
|
-
if (args['--tags']) {
|
|
86
|
-
const specTagCounts = countTags(result.structure)
|
|
87
|
-
Object.keys(specTagCounts).forEach((tag) => {
|
|
88
|
-
if (!(tag in tagTestCounts)) {
|
|
89
|
-
tagTestCounts[tag] = specTagCounts[tag]
|
|
90
|
-
} else {
|
|
91
|
-
tagTestCounts[tag] += specTagCounts[tag]
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
addCounts(jsonResults)
|
|
98
|
-
|
|
99
|
-
if (args['--names']) {
|
|
100
|
-
if (args['--tagged']) {
|
|
101
|
-
// filter all collected tests to those that have the given tag(s)
|
|
102
|
-
const splitTags = args['--tagged']
|
|
103
|
-
.split(',')
|
|
104
|
-
.map((s) => s.trim())
|
|
105
|
-
.filter(Boolean)
|
|
106
|
-
debug('filtering all tests by tag "%o"', splitTags)
|
|
107
|
-
pickTaggedTestsFrom(jsonResults, splitTags)
|
|
108
|
-
// recompute the number of tests
|
|
109
|
-
addCounts(jsonResults)
|
|
110
|
-
} else if (args['--skipped']) {
|
|
111
|
-
debug('leaving only skipped (pending) tests')
|
|
112
|
-
leavePendingTestsOnly(jsonResults)
|
|
113
|
-
// recompute the number of tests
|
|
114
|
-
addCounts(jsonResults)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (args['--count']) {
|
|
118
|
-
let n = 0
|
|
119
|
-
Object.keys(jsonResults).forEach((filename) => {
|
|
120
|
-
const skippedCount = jsonResults[filename].counts.pending
|
|
121
|
-
n += skippedCount
|
|
122
|
-
})
|
|
123
|
-
console.log(n)
|
|
124
|
-
} else {
|
|
125
|
-
if (args['--json']) {
|
|
126
|
-
console.log(JSON.stringify(jsonResults, null, 2))
|
|
127
|
-
} else {
|
|
128
|
-
const str = stringAllInfo(jsonResults)
|
|
129
|
-
console.log(str)
|
|
130
|
-
}
|
|
131
|
-
console.log('')
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (args['--tags']) {
|
|
136
|
-
const tagEntries = Object.entries(tagTestCounts)
|
|
137
|
-
const sortedTagEntries = tagEntries.sort((a, b) => {
|
|
138
|
-
// every entry is [tag, count], so compare the tags
|
|
139
|
-
return a[0].localeCompare(b[0])
|
|
61
|
+
// counts the number of tests for each tag across all specs
|
|
62
|
+
const { jsonResults, tagTestCounts } = getTests(specs, {
|
|
63
|
+
tags: args['--tags'],
|
|
64
|
+
tagged: args['--tagged'],
|
|
65
|
+
skipped: args['--skipped'],
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
if (args['--names']) {
|
|
69
|
+
if (args['--count']) {
|
|
70
|
+
let n = 0
|
|
71
|
+
Object.keys(jsonResults).forEach((filename) => {
|
|
72
|
+
const skippedCount = jsonResults[filename].counts.pending
|
|
73
|
+
n += skippedCount
|
|
140
74
|
})
|
|
75
|
+
console.log(n)
|
|
76
|
+
} else {
|
|
141
77
|
if (args['--json']) {
|
|
142
|
-
|
|
143
|
-
const tagResults = Object.fromEntries(sortedTagEntries)
|
|
144
|
-
console.log(JSON.stringify(tagResults, null, 2))
|
|
78
|
+
console.log(JSON.stringify(jsonResults, null, 2))
|
|
145
79
|
} else {
|
|
146
|
-
const
|
|
147
|
-
console.log(
|
|
80
|
+
const str = stringAllInfo(jsonResults)
|
|
81
|
+
console.log(str)
|
|
148
82
|
}
|
|
83
|
+
console.log('')
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (args['--tags']) {
|
|
88
|
+
const tagEntries = Object.entries(tagTestCounts)
|
|
89
|
+
const sortedTagEntries = tagEntries.sort((a, b) => {
|
|
90
|
+
// every entry is [tag, count], so compare the tags
|
|
91
|
+
return a[0].localeCompare(b[0])
|
|
92
|
+
})
|
|
93
|
+
if (args['--json']) {
|
|
94
|
+
// assemble a json object with the tag counts
|
|
95
|
+
const tagResults = Object.fromEntries(sortedTagEntries)
|
|
96
|
+
console.log(JSON.stringify(tagResults, null, 2))
|
|
97
|
+
} else {
|
|
98
|
+
const table = consoleTable.getTable(['Tag', 'Tests'], sortedTagEntries)
|
|
99
|
+
console.log(table)
|
|
149
100
|
}
|
|
150
101
|
}
|
|
151
102
|
} else if (args['--branch']) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"test": "ava",
|
|
15
15
|
"cy:run": "DEBUG=cypress:cli,cypress:server:specs cypress run",
|
|
16
16
|
"demo": "DEBUG=find-cypress-specs node ./bin/find",
|
|
17
|
-
"demo-names": "node ./bin/find --names",
|
|
18
|
-
"demo-skipped-tests": "node ./bin/find --names --skipped",
|
|
19
|
-
"demo-count-skipped-tests": "node ./bin/find --names --skipped --count",
|
|
17
|
+
"demo-names": "DEBUG=find-cypress-specs node ./bin/find --names",
|
|
18
|
+
"demo-skipped-tests": "DEBUG=find-cypress-specs node ./bin/find --names --skipped",
|
|
19
|
+
"demo-count-skipped-tests": "DEBUG=find-cypress-specs node ./bin/find --names --skipped --count",
|
|
20
20
|
"demo-tags": "node ./bin/find --tags",
|
|
21
21
|
"demo-tags-json": "node ./bin/find --tags --json",
|
|
22
22
|
"demo-names-and-tags": "node ./bin/find --names --tags",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"ava": "^4.0.0",
|
|
47
|
-
"cypress": "12.
|
|
47
|
+
"cypress": "12.7.0",
|
|
48
48
|
"execa-wrap": "^1.4.0",
|
|
49
49
|
"prettier": "^2.5.1",
|
|
50
50
|
"really-need": "^1.9.2",
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const { addCounts } = require('../src/count')
|
|
2
|
+
const { getTestNames, countTags } = require('find-test-names')
|
|
3
|
+
const { pickTaggedTestsFrom, leavePendingTestsOnly } = require('../src/tagged')
|
|
4
|
+
|
|
1
5
|
const debug = require('debug')('find-cypress-specs')
|
|
2
6
|
const fs = require('fs')
|
|
3
7
|
const path = require('path')
|
|
@@ -155,8 +159,10 @@ function findCypressSpecsV10(opts = {}) {
|
|
|
155
159
|
return filtered
|
|
156
160
|
}
|
|
157
161
|
|
|
158
|
-
function getSpecs() {
|
|
159
|
-
|
|
162
|
+
function getSpecs(options) {
|
|
163
|
+
if (typeof options === 'undefined') {
|
|
164
|
+
options = getConfig()
|
|
165
|
+
}
|
|
160
166
|
return findCypressSpecs(options)
|
|
161
167
|
}
|
|
162
168
|
|
|
@@ -266,6 +272,68 @@ function findChangedFiles(branch, useParent) {
|
|
|
266
272
|
}
|
|
267
273
|
}
|
|
268
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Collects all specs and for each finds all suits and tests with their tags.
|
|
277
|
+
*/
|
|
278
|
+
function getTests(specs, options = {}) {
|
|
279
|
+
if (!specs) {
|
|
280
|
+
specs = getSpecs()
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const { tags, tagged, skipped } = options
|
|
284
|
+
|
|
285
|
+
// counts the number of tests for each tag across all specs
|
|
286
|
+
const tagTestCounts = {}
|
|
287
|
+
const jsonResults = {}
|
|
288
|
+
|
|
289
|
+
specs.forEach((filename) => {
|
|
290
|
+
jsonResults[filename] = {
|
|
291
|
+
counts: {
|
|
292
|
+
tests: 0,
|
|
293
|
+
pending: 0,
|
|
294
|
+
},
|
|
295
|
+
tests: [],
|
|
296
|
+
}
|
|
297
|
+
const source = fs.readFileSync(filename, 'utf8')
|
|
298
|
+
const result = getTestNames(source, true)
|
|
299
|
+
// enable if need to debug the parsed test
|
|
300
|
+
// console.dir(result.structure, { depth: null })
|
|
301
|
+
collectResults(result.structure, jsonResults[filename].tests)
|
|
302
|
+
|
|
303
|
+
if (tags) {
|
|
304
|
+
const specTagCounts = countTags(result.structure)
|
|
305
|
+
Object.keys(specTagCounts).forEach((tag) => {
|
|
306
|
+
if (!(tag in tagTestCounts)) {
|
|
307
|
+
tagTestCounts[tag] = specTagCounts[tag]
|
|
308
|
+
} else {
|
|
309
|
+
tagTestCounts[tag] += specTagCounts[tag]
|
|
310
|
+
}
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
addCounts(jsonResults)
|
|
316
|
+
|
|
317
|
+
if (tagged) {
|
|
318
|
+
// filter all collected tests to those that have the given tag(s)
|
|
319
|
+
const splitTags = tagged
|
|
320
|
+
.split(',')
|
|
321
|
+
.map((s) => s.trim())
|
|
322
|
+
.filter(Boolean)
|
|
323
|
+
debug('filtering all tests by tag "%o"', splitTags)
|
|
324
|
+
pickTaggedTestsFrom(jsonResults, splitTags)
|
|
325
|
+
// recompute the number of tests
|
|
326
|
+
addCounts(jsonResults)
|
|
327
|
+
} else if (skipped) {
|
|
328
|
+
debug('leaving only skipped (pending) tests')
|
|
329
|
+
leavePendingTestsOnly(jsonResults)
|
|
330
|
+
// recompute the number of tests
|
|
331
|
+
addCounts(jsonResults)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return { jsonResults, tagTestCounts }
|
|
335
|
+
}
|
|
336
|
+
|
|
269
337
|
module.exports = {
|
|
270
338
|
getSpecs,
|
|
271
339
|
// individual utilities
|
|
@@ -273,4 +341,5 @@ module.exports = {
|
|
|
273
341
|
findCypressSpecs,
|
|
274
342
|
collectResults,
|
|
275
343
|
findChangedFiles,
|
|
344
|
+
getTests,
|
|
276
345
|
}
|