find-cypress-specs 1.37.0 → 1.38.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 +15 -2
- package/bin/find.js +18 -2
- package/package.json +5 -3
- package/src/index.js +1 -1
- package/src/print.js +77 -22
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
|
|
|
@@ -157,6 +157,17 @@ Required tags are marked with `[[ ... ]]`.
|
|
|
157
157
|
|
|
158
158
|
You can print the results in JSON format using `--json` or `-j` option.
|
|
159
159
|
|
|
160
|
+
You can print the tests in Markdown format using `--markdown` or `--md` option
|
|
161
|
+
|
|
162
|
+
| Spec |
|
|
163
|
+
| -------------------------------- |
|
|
164
|
+
| **`foo/a/spec.cy.js`** (3 tests) |
|
|
165
|
+
| `suite / test 1` |
|
|
166
|
+
| `suite / test 2` |
|
|
167
|
+
| `suite / test 3` |
|
|
168
|
+
| **`foo/b/spec.cy.js`** (1 test) |
|
|
169
|
+
| `another / test / test 1` |
|
|
170
|
+
|
|
160
171
|
## Test tags
|
|
161
172
|
|
|
162
173
|
You can count tags attached to the individual tests using `--tags` arguments
|
|
@@ -200,10 +211,12 @@ $ npx find-cypress-specs --tagged <single tag>
|
|
|
200
211
|
# cypress/e2e/spec.cy.js,cypress/e2e/featureA/user.cy.ts
|
|
201
212
|
```
|
|
202
213
|
|
|
214
|
+
If you pass an empty string argument like `--tagged ''`, an empty list is returned.
|
|
215
|
+
|
|
203
216
|
You can print the number of found tagged specs by adding `--count` argument
|
|
204
217
|
|
|
205
218
|
```
|
|
206
|
-
$ npx find-cypress-specs --tagged <single tag>
|
|
219
|
+
$ npx find-cypress-specs --tagged <single tag> --count
|
|
207
220
|
3
|
|
208
221
|
```
|
|
209
222
|
|
package/bin/find.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const arg = require('arg')
|
|
4
4
|
const { getSpecs, findChangedFiles, getTests } = require('../src')
|
|
5
5
|
const { getTestCounts } = require('../src/tests-counts')
|
|
6
|
-
const { stringAllInfo } = require('../src/print')
|
|
6
|
+
const { stringAllInfo, stringMarkdownTests } = require('../src/print')
|
|
7
7
|
const { updateBadge } = require('../src/badge')
|
|
8
8
|
|
|
9
9
|
const fs = require('fs')
|
|
@@ -49,6 +49,9 @@ const args = arg({
|
|
|
49
49
|
'--test-counts': Boolean,
|
|
50
50
|
// if we count the tests, we can update the README badge
|
|
51
51
|
'--update-badge': Boolean,
|
|
52
|
+
// output the list in Markdown format
|
|
53
|
+
'--markdown': Boolean,
|
|
54
|
+
//
|
|
52
55
|
// aliases
|
|
53
56
|
'-n': '--names',
|
|
54
57
|
'--name': '--names',
|
|
@@ -62,6 +65,7 @@ const args = arg({
|
|
|
62
65
|
// https://glebbahmutov.com/blog/cypress-test-statuses/
|
|
63
66
|
'--pending': '--skipped',
|
|
64
67
|
'--tc': '--test-counts',
|
|
68
|
+
'--md': '--markdown',
|
|
65
69
|
})
|
|
66
70
|
|
|
67
71
|
debug('arguments %o', args)
|
|
@@ -85,6 +89,10 @@ if (args['--test-counts']) {
|
|
|
85
89
|
|
|
86
90
|
const specs = getSpecs(undefined, specType)
|
|
87
91
|
|
|
92
|
+
// if the user passes "--tagged ''" we want to find the specs
|
|
93
|
+
// but then filter them all out
|
|
94
|
+
const isTaggedPresent = args['--tagged'] || args['--tagged'] === ''
|
|
95
|
+
|
|
88
96
|
if (args['--branch']) {
|
|
89
97
|
debug('determining specs changed against branch %s', args['--branch'])
|
|
90
98
|
let changedFiles = findChangedFiles(args['--branch'], args['--parent'])
|
|
@@ -191,8 +199,9 @@ if (args['--test-counts']) {
|
|
|
191
199
|
} else {
|
|
192
200
|
console.log(changedSpecs.join(','))
|
|
193
201
|
}
|
|
194
|
-
} else if (args['--names'] || args['--tags'] ||
|
|
202
|
+
} else if (args['--names'] || args['--tags'] || isTaggedPresent) {
|
|
195
203
|
// counts the number of tests for each tag across all specs
|
|
204
|
+
debug('count number of tests')
|
|
196
205
|
const { jsonResults, tagTestCounts } = getTests(specs, {
|
|
197
206
|
tags: args['--tags'],
|
|
198
207
|
tagged: args['--tagged'],
|
|
@@ -204,6 +213,7 @@ if (args['--test-counts']) {
|
|
|
204
213
|
debug(tagTestCounts)
|
|
205
214
|
|
|
206
215
|
if (args['--names']) {
|
|
216
|
+
debug('output test names')
|
|
207
217
|
if (args['--count']) {
|
|
208
218
|
debug('names and count')
|
|
209
219
|
let n = 0
|
|
@@ -214,8 +224,14 @@ if (args['--test-counts']) {
|
|
|
214
224
|
console.log(n)
|
|
215
225
|
} else {
|
|
216
226
|
if (args['--json']) {
|
|
227
|
+
debug('names in json format')
|
|
217
228
|
console.log(JSON.stringify(jsonResults, null, 2))
|
|
229
|
+
} else if (args['--markdown']) {
|
|
230
|
+
debug('names in Markdown format')
|
|
231
|
+
const str = stringMarkdownTests(jsonResults)
|
|
232
|
+
console.log(str)
|
|
218
233
|
} else {
|
|
234
|
+
debug('names to standard out')
|
|
219
235
|
const str = stringAllInfo(jsonResults)
|
|
220
236
|
console.log(str)
|
|
221
237
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"cy:run": "DEBUG=cypress:cli,cypress:server:specs cypress run",
|
|
17
17
|
"demo": "DEBUG=find-cypress-specs node ./bin/find",
|
|
18
18
|
"demo-names": "DEBUG=find-cypress-specs node ./bin/find --names",
|
|
19
|
+
"demo-names-markdown": "node ./bin/find --names --markdown",
|
|
19
20
|
"demo-skipped-tests": "DEBUG=find-cypress-specs node ./bin/find --names --skipped",
|
|
20
21
|
"demo-count-skipped-tests": "DEBUG=find-cypress-specs node ./bin/find --names --skipped --count",
|
|
21
22
|
"demo-custom-cypress-config": "DEBUG=find-cypress-specs CYPRESS_CONFIG_FILE=test-ts/cypress.config.custom.ts node ./bin/find",
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
"demo-names-and-tags-json": "node ./bin/find --names --tags --json",
|
|
26
27
|
"demo-names-json": "node ./bin/find --names --json",
|
|
27
28
|
"demo-names-tagged": "node ./bin/find --names --tagged @user",
|
|
29
|
+
"demo-tagged-empty-string": "node ./bin/find --tagged ''",
|
|
28
30
|
"demo-subfolder": "DEBUG=find-cypress-specs CYPRESS_CONFIG_FILE=mocks/my-app/e2e/cypress.config.js node ./bin/find --names",
|
|
29
31
|
"print-changed-specs": "node ./bin/find --branch main",
|
|
30
32
|
"count-changed-specs": "node ./bin/find --branch main --count",
|
|
@@ -53,12 +55,12 @@
|
|
|
53
55
|
"homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
|
|
54
56
|
"devDependencies": {
|
|
55
57
|
"ava": "^4.0.0",
|
|
56
|
-
"cypress": "13.
|
|
58
|
+
"cypress": "13.6.0",
|
|
57
59
|
"dependency-version-badge": "^1.11.0",
|
|
58
60
|
"execa-wrap": "^1.4.0",
|
|
59
61
|
"prettier": "^2.5.1",
|
|
60
62
|
"really-need": "^1.9.2",
|
|
61
|
-
"semantic-release": "22.0.
|
|
63
|
+
"semantic-release": "22.0.8",
|
|
62
64
|
"sinon": "^13.0.1",
|
|
63
65
|
"typescript": "^4.6.3"
|
|
64
66
|
},
|
package/src/index.js
CHANGED
|
@@ -449,7 +449,7 @@ function getTests(specs, options = {}) {
|
|
|
449
449
|
debug('added counts')
|
|
450
450
|
debug(jsonResults)
|
|
451
451
|
|
|
452
|
-
if (tagged) {
|
|
452
|
+
if (tagged || tagged === '') {
|
|
453
453
|
// filter all collected tests to those that have the given tag(s)
|
|
454
454
|
const splitTags = tagged
|
|
455
455
|
.split(',')
|
package/src/print.js
CHANGED
|
@@ -7,36 +7,35 @@ const { formatTestList } = require('find-test-names')
|
|
|
7
7
|
*/
|
|
8
8
|
function stringFileTests(fileName, fileInfo, tagged) {
|
|
9
9
|
if (tagged) {
|
|
10
|
-
const headerLine = fileName
|
|
11
|
-
|
|
10
|
+
const headerLine = fileName
|
|
11
|
+
return headerLine
|
|
12
12
|
} else {
|
|
13
13
|
const testCount = pluralize('test', fileInfo.counts.tests, true)
|
|
14
14
|
const headerLine = fileInfo.counts.pending
|
|
15
15
|
? `${fileName} (${testCount}, ${fileInfo.counts.pending} pending)`
|
|
16
16
|
: `${fileName} (${testCount})`
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
// console.log(fileInfo.tests)
|
|
19
19
|
const body = formatTestList(fileInfo.tests)
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
return headerLine + '\n' + body + '\n'
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function stringAllInfo(allInfo, tagged) {
|
|
26
|
-
let fileCount = 0
|
|
27
|
-
let testCount = 0
|
|
28
|
-
let pendingTestCount = 0
|
|
29
|
-
|
|
30
26
|
if (!tagged) {
|
|
27
|
+
let fileCount = 0
|
|
28
|
+
let testCount = 0
|
|
29
|
+
let pendingTestCount = 0
|
|
31
30
|
const allInfoString = Object.keys(allInfo)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
.map((fileName) => {
|
|
32
|
+
const fileInfo = allInfo[fileName]
|
|
33
|
+
fileCount += 1
|
|
34
|
+
testCount += fileInfo.counts.tests
|
|
35
|
+
pendingTestCount += fileInfo.counts.pending
|
|
36
|
+
return stringFileTests(fileName, fileInfo, tagged)
|
|
37
|
+
})
|
|
38
|
+
.join('\n')
|
|
40
39
|
// footer line is something like
|
|
41
40
|
// found 2 specs (4 tests, 1 pending)
|
|
42
41
|
let footer = `found ${pluralize('spec', fileCount, true)}`
|
|
@@ -50,17 +49,73 @@ function stringAllInfo(allInfo, tagged) {
|
|
|
50
49
|
return allInfoString + '\n' + footer
|
|
51
50
|
} else {
|
|
52
51
|
const allInfoString = Object.keys(allInfo)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
.map((fileName) => {
|
|
53
|
+
const fileInfo = allInfo[fileName]
|
|
54
|
+
return stringFileTests(fileName, fileInfo, tagged)
|
|
55
|
+
})
|
|
56
|
+
.join(',')
|
|
58
57
|
|
|
59
58
|
return allInfoString
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
|
|
62
|
+
function getJustTheTestNames(tests, parentName = '', justNames = []) {
|
|
63
|
+
// console.log(tests)
|
|
64
|
+
// console.log(justNames)
|
|
65
|
+
// console.log('parent name "%s"', parentName)
|
|
66
|
+
|
|
67
|
+
if (tests.type === 'test') {
|
|
68
|
+
justNames.push(parentName + tests.name)
|
|
69
|
+
return
|
|
70
|
+
} else if (tests.type === 'suite') {
|
|
71
|
+
const prefix = parentName
|
|
72
|
+
? parentName + tests.name + ' / '
|
|
73
|
+
: tests.name + ' / '
|
|
74
|
+
getJustTheTestNames(tests.tests, prefix, justNames)
|
|
75
|
+
if (tests.suites) {
|
|
76
|
+
tests.suites.forEach((suite) => {
|
|
77
|
+
getJustTheTestNames(suite, prefix, justNames)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// tests can include regular tests plus suites nodes
|
|
84
|
+
tests.forEach((testOrSuite) => {
|
|
85
|
+
getJustTheTestNames(testOrSuite, parentName, justNames)
|
|
86
|
+
})
|
|
87
|
+
return justNames
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns a single string with all specs and test names
|
|
92
|
+
* as a Markdown table
|
|
93
|
+
* @returns {string}
|
|
94
|
+
*/
|
|
95
|
+
function stringMarkdownTests(allInfo) {
|
|
96
|
+
const allInfoString =
|
|
97
|
+
'| Spec |\n| --- |\n' +
|
|
98
|
+
Object.keys(allInfo)
|
|
99
|
+
.map((fileName) => {
|
|
100
|
+
const fileInfo = allInfo[fileName]
|
|
101
|
+
const n = fileInfo.counts.tests
|
|
102
|
+
// console.log(fileInfo)
|
|
103
|
+
|
|
104
|
+
let specTest =
|
|
105
|
+
'| **`' + fileName + '`**' + ` (${n} ${pluralize('test', n)}) |\n`
|
|
106
|
+
const testNames = getJustTheTestNames(fileInfo.tests)
|
|
107
|
+
testNames.forEach((name) => {
|
|
108
|
+
specTest += '| `' + name + '` |\n'
|
|
109
|
+
})
|
|
110
|
+
return specTest
|
|
111
|
+
})
|
|
112
|
+
.join('')
|
|
113
|
+
|
|
114
|
+
return allInfoString
|
|
115
|
+
}
|
|
116
|
+
|
|
63
117
|
module.exports = {
|
|
64
118
|
stringFileTests,
|
|
65
119
|
stringAllInfo,
|
|
66
|
-
|
|
120
|
+
stringMarkdownTests,
|
|
121
|
+
}
|