find-cypress-specs 1.5.0 → 1.9.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 +13 -5
- package/bin/find.js +50 -32
- package/package.json +6 -3
- package/src/index.js +28 -0
package/README.md
CHANGED
|
@@ -31,20 +31,24 @@ found 2 specs (4 tests, 1 pending)
|
|
|
31
31
|
|
|
32
32
|
Where the tags are listed inside `[ ... ]` (see [cypress-grep](https://github.com/cypress-io/cypress-grep)) and the [pending tests](https://glebbahmutov.com/blog/cypress-test-statuses/) are marked with `⊙` character.
|
|
33
33
|
|
|
34
|
+
You can print the results in JSON format using `--json` or `-j` option.
|
|
35
|
+
|
|
34
36
|
## Test tags
|
|
35
37
|
|
|
36
|
-
You can count tags attached to the individual tests using `--
|
|
38
|
+
You can count tags attached to the individual tests using `--tags` arguments
|
|
37
39
|
|
|
38
40
|
```
|
|
39
|
-
$ npx find-cypress-specs --
|
|
40
|
-
# prints the
|
|
41
|
+
$ npx find-cypress-specs --tags
|
|
42
|
+
# prints the tags table sorted by tag
|
|
41
43
|
|
|
42
|
-
Tag
|
|
44
|
+
Tag Tests
|
|
43
45
|
----- ----------
|
|
44
|
-
@user 2
|
|
45
46
|
@sign 1
|
|
47
|
+
@user 2
|
|
46
48
|
```
|
|
47
49
|
|
|
50
|
+
Each tag count includes the tests that use the tag directly, and the _effective_ tags applied from the parent suites.
|
|
51
|
+
|
|
48
52
|
## Details
|
|
49
53
|
|
|
50
54
|
Cypress uses the resolved [configuration values](https://on.cypress.io/configuration) to find the spec files to run. It searches the `integrationFolder` for all patterns listed in `testFiles` and removes any files matching the `ignoreTestFiles` patterns.
|
|
@@ -55,6 +59,10 @@ You can see how Cypress finds the specs using `DEBUG=cypress:cli,cypress:server:
|
|
|
55
59
|
|
|
56
60
|
Run the utility with environment variable `DEBUG=find-cypress-specs` to see the verbose logs
|
|
57
61
|
|
|
62
|
+
## Videos
|
|
63
|
+
|
|
64
|
+
- [Use Ava Snapshots And Execa-wrap To Write End-to-End Tests For CLI Utilities](https://youtu.be/rsw17RqP0G0)
|
|
65
|
+
|
|
58
66
|
## Small print
|
|
59
67
|
|
|
60
68
|
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
|
package/bin/find.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const arg = require('arg')
|
|
4
|
-
const { getSpecs } = require('../src')
|
|
4
|
+
const { getSpecs, collectResults } = require('../src')
|
|
5
5
|
const fs = require('fs')
|
|
6
6
|
const pluralize = require('pluralize')
|
|
7
7
|
const { getTestNames, formatTestList, countTags } = require('find-test-names')
|
|
@@ -10,16 +10,18 @@ const consoleTable = require('console.table')
|
|
|
10
10
|
const args = arg({
|
|
11
11
|
'--names': Boolean,
|
|
12
12
|
'--tags': Boolean,
|
|
13
|
+
'--json': Boolean,
|
|
13
14
|
|
|
14
15
|
// aliases
|
|
15
16
|
'-n': '--names',
|
|
16
17
|
'--name': '--names',
|
|
17
18
|
'-t': '--tags',
|
|
18
19
|
'--tag': '--tags',
|
|
20
|
+
'-j': '--json',
|
|
19
21
|
})
|
|
20
22
|
|
|
21
23
|
const specs = getSpecs()
|
|
22
|
-
if (args['--names']) {
|
|
24
|
+
if (args['--names'] || args['--tags']) {
|
|
23
25
|
if (!specs.length) {
|
|
24
26
|
console.log('no specs found')
|
|
25
27
|
} else {
|
|
@@ -30,7 +32,10 @@ if (args['--names']) {
|
|
|
30
32
|
// counts the number of tests for each tag across all specs
|
|
31
33
|
const tagTestCounts = {}
|
|
32
34
|
|
|
35
|
+
const jsonResults = {}
|
|
36
|
+
|
|
33
37
|
specs.forEach((filename) => {
|
|
38
|
+
jsonResults[filename] = []
|
|
34
39
|
const source = fs.readFileSync(filename, 'utf8')
|
|
35
40
|
const result = getTestNames(source, true)
|
|
36
41
|
// enable if need to debug the parsed test
|
|
@@ -40,18 +45,24 @@ if (args['--names']) {
|
|
|
40
45
|
const testCount = pluralize('test', result.testNames.length, true)
|
|
41
46
|
pendingTestsN += result.pendingTestCount
|
|
42
47
|
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
if (args['--names']) {
|
|
49
|
+
if (args['--json']) {
|
|
50
|
+
collectResults(result.structure, jsonResults[filename])
|
|
51
|
+
} else {
|
|
52
|
+
if (result.pendingTestCount) {
|
|
53
|
+
console.log(
|
|
54
|
+
'%s (%s, %d pending)',
|
|
55
|
+
filename,
|
|
56
|
+
testCount,
|
|
57
|
+
result.pendingTestCount,
|
|
58
|
+
)
|
|
59
|
+
} else {
|
|
60
|
+
console.log('%s (%s)', filename, testCount)
|
|
61
|
+
}
|
|
62
|
+
console.log(formatTestList(result.structure))
|
|
63
|
+
console.log('')
|
|
64
|
+
}
|
|
52
65
|
}
|
|
53
|
-
console.log(formatTestList(result.structure))
|
|
54
|
-
console.log('')
|
|
55
66
|
|
|
56
67
|
if (args['--tags']) {
|
|
57
68
|
const specTagCounts = countTags(result.structure)
|
|
@@ -65,29 +76,36 @@ if (args['--names']) {
|
|
|
65
76
|
}
|
|
66
77
|
})
|
|
67
78
|
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
if (args['--names']) {
|
|
80
|
+
if (args['--json']) {
|
|
81
|
+
console.log(JSON.stringify(jsonResults, null, 2))
|
|
82
|
+
} else {
|
|
83
|
+
if (pendingTestsN) {
|
|
84
|
+
console.log(
|
|
85
|
+
'found %s (%s, %d pending)',
|
|
86
|
+
pluralize('spec', specs.length, true),
|
|
87
|
+
pluralize('test', testsN, true),
|
|
88
|
+
pendingTestsN,
|
|
89
|
+
)
|
|
90
|
+
} else {
|
|
91
|
+
console.log(
|
|
92
|
+
'found %s (%s)',
|
|
93
|
+
pluralize('spec', specs.length, true),
|
|
94
|
+
pluralize('test', testsN, true),
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
console.log('')
|
|
81
99
|
}
|
|
82
|
-
console.log('')
|
|
83
100
|
|
|
84
101
|
if (args['--tags']) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
const tagEntries = Object.entries(tagTestCounts)
|
|
103
|
+
const sortedTagEntries = tagEntries.sort((a, b) => {
|
|
104
|
+
// every entry is [tag, count], so compare the tags
|
|
105
|
+
return a[0].localeCompare(b[0])
|
|
106
|
+
})
|
|
107
|
+
const table = consoleTable.getTable(['Tag', 'Tests'], sortedTagEntries)
|
|
89
108
|
console.log(table)
|
|
90
|
-
console.log('')
|
|
91
109
|
}
|
|
92
110
|
}
|
|
93
111
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"cy:run": "DEBUG=cypress:cli,cypress:server:specs cypress run",
|
|
16
16
|
"demo": "DEBUG=find-cypress-specs node ./bin/find",
|
|
17
17
|
"demo-names": "node ./bin/find --names",
|
|
18
|
-
"demo-tags": "node ./bin/find --
|
|
18
|
+
"demo-tags": "node ./bin/find --tags",
|
|
19
|
+
"demo-names-and-tags": "node ./bin/find --names --tags",
|
|
20
|
+
"demo-names-json": "node ./bin/find --names --json",
|
|
19
21
|
"semantic-release": "semantic-release"
|
|
20
22
|
},
|
|
21
23
|
"repository": {
|
|
@@ -34,6 +36,7 @@
|
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"ava": "^4.0.0",
|
|
36
38
|
"cypress": "^9.2.0",
|
|
39
|
+
"execa-wrap": "^1.4.0",
|
|
37
40
|
"prettier": "^2.5.1",
|
|
38
41
|
"semantic-release": "^18.0.1"
|
|
39
42
|
},
|
|
@@ -41,7 +44,7 @@
|
|
|
41
44
|
"arg": "^5.0.1",
|
|
42
45
|
"console.table": "^0.10.0",
|
|
43
46
|
"debug": "^4.3.3",
|
|
44
|
-
"find-test-names": "^1.
|
|
47
|
+
"find-test-names": "^1.14.1",
|
|
45
48
|
"globby": "^11.0.4",
|
|
46
49
|
"minimatch": "^3.0.4",
|
|
47
50
|
"pluralize": "^8.0.0"
|
package/src/index.js
CHANGED
|
@@ -72,9 +72,37 @@ function getSpecs() {
|
|
|
72
72
|
return specs
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
function collectResults(structure, results) {
|
|
76
|
+
structure.forEach((t) => {
|
|
77
|
+
const info = {
|
|
78
|
+
name: t.name,
|
|
79
|
+
type: t.type,
|
|
80
|
+
tags: t.tags,
|
|
81
|
+
}
|
|
82
|
+
if (t.pending) {
|
|
83
|
+
info.pending = t.pending
|
|
84
|
+
}
|
|
85
|
+
results.push(info)
|
|
86
|
+
if (t.type === 'suite') {
|
|
87
|
+
if (t.suites && t.suites.length) {
|
|
88
|
+
// skip empty nested suites
|
|
89
|
+
info.suites = []
|
|
90
|
+
collectResults(t.suites, info.suites)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (t.tests && t.tests.length) {
|
|
94
|
+
// skip empty nested tests
|
|
95
|
+
info.tests = []
|
|
96
|
+
collectResults(t.tests, info.tests)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
75
102
|
module.exports = {
|
|
76
103
|
getSpecs,
|
|
77
104
|
// individual utilities
|
|
78
105
|
getConfig,
|
|
79
106
|
findCypressSpecs,
|
|
107
|
+
collectResults,
|
|
80
108
|
}
|