find-cypress-specs 1.9.0 → 1.12.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 -1
- package/bin/find.js +27 -3
- package/package.json +9 -4
- package/src/index.js +30 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# find-cypress-specs  [](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
|
|
|
@@ -8,6 +8,25 @@ $ npx find-cypress-specs
|
|
|
8
8
|
cypress/e2e/spec.js,cypress/e2e/featureA/user.js
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## against branch
|
|
12
|
+
|
|
13
|
+
By default, this module simply prints all spec filenames. You can add `--branch` parameter to only print the specs changed against that `origin/branch`.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ npx find-cypress-specs --branch main
|
|
17
|
+
# prints only some specs, the ones that have changed against the "origin/main"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### number of changed files
|
|
21
|
+
|
|
22
|
+
You can print just the number of changed specs
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
$ npx find-cypress-specs --branch main --count
|
|
26
|
+
# prints the number of spec files changed against the branch "origin/main"
|
|
27
|
+
5
|
|
28
|
+
```
|
|
29
|
+
|
|
11
30
|
## Test names
|
|
12
31
|
|
|
13
32
|
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))
|
|
@@ -49,6 +68,8 @@ Tag Tests
|
|
|
49
68
|
|
|
50
69
|
Each tag count includes the tests that use the tag directly, and the _effective_ tags applied from the parent suites.
|
|
51
70
|
|
|
71
|
+
You can print the results in JSON format using `--json` or `-j` option.
|
|
72
|
+
|
|
52
73
|
## Details
|
|
53
74
|
|
|
54
75
|
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.
|
|
@@ -103,3 +124,6 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
103
124
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
104
125
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
105
126
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
127
|
+
|
|
128
|
+
[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
|
|
129
|
+
[renovate-app]: https://renovateapp.com/
|
package/bin/find.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const arg = require('arg')
|
|
4
|
-
const { getSpecs, collectResults } = require('../src')
|
|
4
|
+
const { getSpecs, collectResults, findChangedFiles } = require('../src')
|
|
5
5
|
const fs = require('fs')
|
|
6
6
|
const pluralize = require('pluralize')
|
|
7
7
|
const { getTestNames, formatTestList, countTags } = require('find-test-names')
|
|
8
8
|
const consoleTable = require('console.table')
|
|
9
|
+
const debug = require('debug')('find-cypress-specs')
|
|
9
10
|
|
|
10
11
|
const args = arg({
|
|
11
12
|
'--names': Boolean,
|
|
12
13
|
'--tags': Boolean,
|
|
14
|
+
// output in JSON format
|
|
13
15
|
'--json': Boolean,
|
|
16
|
+
// find the specs that have changed against this Git branch
|
|
17
|
+
'--branch': String,
|
|
18
|
+
'--count': Boolean,
|
|
14
19
|
|
|
15
20
|
// aliases
|
|
16
21
|
'-n': '--names',
|
|
@@ -18,8 +23,11 @@ const args = arg({
|
|
|
18
23
|
'-t': '--tags',
|
|
19
24
|
'--tag': '--tags',
|
|
20
25
|
'-j': '--json',
|
|
26
|
+
'-b': '--branch',
|
|
21
27
|
})
|
|
22
28
|
|
|
29
|
+
debug('arguments %o', args)
|
|
30
|
+
|
|
23
31
|
const specs = getSpecs()
|
|
24
32
|
if (args['--names'] || args['--tags']) {
|
|
25
33
|
if (!specs.length) {
|
|
@@ -104,10 +112,26 @@ if (args['--names'] || args['--tags']) {
|
|
|
104
112
|
// every entry is [tag, count], so compare the tags
|
|
105
113
|
return a[0].localeCompare(b[0])
|
|
106
114
|
})
|
|
107
|
-
|
|
108
|
-
|
|
115
|
+
if (args['--json']) {
|
|
116
|
+
// assemble a json object with the tag counts
|
|
117
|
+
const tagResults = Object.fromEntries(sortedTagEntries)
|
|
118
|
+
console.log(JSON.stringify(tagResults, null, 2))
|
|
119
|
+
} else {
|
|
120
|
+
const table = consoleTable.getTable(['Tag', 'Tests'], sortedTagEntries)
|
|
121
|
+
console.log(table)
|
|
122
|
+
}
|
|
109
123
|
}
|
|
110
124
|
}
|
|
125
|
+
} else if (args['--branch']) {
|
|
126
|
+
debug('determining specs changed against branch %s', args['--branch'])
|
|
127
|
+
const changedFiles = findChangedFiles(args['--branch'])
|
|
128
|
+
debug('changed files %o', changedFiles)
|
|
129
|
+
const changedSpecs = specs.filter((file) => changedFiles.includes(file))
|
|
130
|
+
if (args['--count']) {
|
|
131
|
+
console.log(changedSpecs.length)
|
|
132
|
+
} else {
|
|
133
|
+
console.log(changedSpecs.join(','))
|
|
134
|
+
}
|
|
111
135
|
} else {
|
|
112
136
|
console.log(specs.join(','))
|
|
113
137
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -16,8 +16,12 @@
|
|
|
16
16
|
"demo": "DEBUG=find-cypress-specs node ./bin/find",
|
|
17
17
|
"demo-names": "node ./bin/find --names",
|
|
18
18
|
"demo-tags": "node ./bin/find --tags",
|
|
19
|
+
"demo-tags-json": "node ./bin/find --tags --json",
|
|
19
20
|
"demo-names-and-tags": "node ./bin/find --names --tags",
|
|
21
|
+
"demo-names-and-tags-json": "node ./bin/find --names --tags --json",
|
|
20
22
|
"demo-names-json": "node ./bin/find --names --json",
|
|
23
|
+
"print-changed-specs": "node ./bin/find --branch main",
|
|
24
|
+
"count-changed-specs": "node ./bin/find --branch main --count",
|
|
21
25
|
"semantic-release": "semantic-release"
|
|
22
26
|
},
|
|
23
27
|
"repository": {
|
|
@@ -35,10 +39,10 @@
|
|
|
35
39
|
"homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
|
|
36
40
|
"devDependencies": {
|
|
37
41
|
"ava": "^4.0.0",
|
|
38
|
-
"cypress": "
|
|
42
|
+
"cypress": "9.4.1",
|
|
39
43
|
"execa-wrap": "^1.4.0",
|
|
40
44
|
"prettier": "^2.5.1",
|
|
41
|
-
"semantic-release": "
|
|
45
|
+
"semantic-release": "19.0.2"
|
|
42
46
|
},
|
|
43
47
|
"dependencies": {
|
|
44
48
|
"arg": "^5.0.1",
|
|
@@ -47,6 +51,7 @@
|
|
|
47
51
|
"find-test-names": "^1.14.1",
|
|
48
52
|
"globby": "^11.0.4",
|
|
49
53
|
"minimatch": "^3.0.4",
|
|
50
|
-
"pluralize": "^8.0.0"
|
|
54
|
+
"pluralize": "^8.0.0",
|
|
55
|
+
"shelljs": "^0.8.5"
|
|
51
56
|
}
|
|
52
57
|
}
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ const fs = require('fs')
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
const globby = require('globby')
|
|
5
5
|
const minimatch = require('minimatch')
|
|
6
|
+
const shell = require('shelljs')
|
|
6
7
|
|
|
7
8
|
const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
|
|
8
9
|
|
|
@@ -99,10 +100,39 @@ function collectResults(structure, results) {
|
|
|
99
100
|
})
|
|
100
101
|
}
|
|
101
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Finds files changed or added in the current branch when compared to the "origin/branch".
|
|
105
|
+
* Returns a list of filenames. If there are no files, returns an empty list.
|
|
106
|
+
* @param {string} branch The branch to compare against.
|
|
107
|
+
*/
|
|
108
|
+
function findChangedFiles(branch) {
|
|
109
|
+
if (!branch) {
|
|
110
|
+
throw new Error('branch is required')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!shell.which('git')) {
|
|
114
|
+
shell.echo('Sorry, this script requires git')
|
|
115
|
+
return []
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const result = shell.exec(
|
|
119
|
+
`git diff --name-only --diff-filter=AMR origin/${branch}`,
|
|
120
|
+
{ silent: true },
|
|
121
|
+
)
|
|
122
|
+
if (result.code !== 0) {
|
|
123
|
+
debug('git diff failed with code %d', result.code)
|
|
124
|
+
return []
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const filenames = result.stdout.split('\n').filter(Boolean)
|
|
128
|
+
return filenames
|
|
129
|
+
}
|
|
130
|
+
|
|
102
131
|
module.exports = {
|
|
103
132
|
getSpecs,
|
|
104
133
|
// individual utilities
|
|
105
134
|
getConfig,
|
|
106
135
|
findCypressSpecs,
|
|
107
136
|
collectResults,
|
|
137
|
+
findChangedFiles,
|
|
108
138
|
}
|