find-cypress-specs 1.10.0 → 1.11.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 -1
- package/bin/find.js +14 -1
- package/package.json +4 -2
- package/src/index.js +30 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# find-cypress-specs 
|
|
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
|
|
|
@@ -8,6 +8,15 @@ $ 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
|
+
|
|
11
20
|
## Test names
|
|
12
21
|
|
|
13
22
|
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))
|
|
@@ -105,3 +114,6 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
105
114
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
106
115
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
107
116
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
117
|
+
|
|
118
|
+
[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
|
|
119
|
+
[renovate-app]: https://renovateapp.com/
|
package/bin/find.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
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,
|
|
14
18
|
|
|
15
19
|
// aliases
|
|
16
20
|
'-n': '--names',
|
|
@@ -18,8 +22,11 @@ const args = arg({
|
|
|
18
22
|
'-t': '--tags',
|
|
19
23
|
'--tag': '--tags',
|
|
20
24
|
'-j': '--json',
|
|
25
|
+
'-b': '--branch',
|
|
21
26
|
})
|
|
22
27
|
|
|
28
|
+
debug('arguments %o', args)
|
|
29
|
+
|
|
23
30
|
const specs = getSpecs()
|
|
24
31
|
if (args['--names'] || args['--tags']) {
|
|
25
32
|
if (!specs.length) {
|
|
@@ -114,6 +121,12 @@ if (args['--names'] || args['--tags']) {
|
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
123
|
}
|
|
124
|
+
} else if (args['--branch']) {
|
|
125
|
+
debug('determining specs changed against branch %s', args['--branch'])
|
|
126
|
+
const changedFiles = findChangedFiles(args['--branch'])
|
|
127
|
+
debug('changed files %o', changedFiles)
|
|
128
|
+
const changedSpecs = specs.filter((file) => changedFiles.includes(file))
|
|
129
|
+
console.log(changedSpecs.join(','))
|
|
117
130
|
} else {
|
|
118
131
|
console.log(specs.join(','))
|
|
119
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"demo-names-and-tags": "node ./bin/find --names --tags",
|
|
21
21
|
"demo-names-and-tags-json": "node ./bin/find --names --tags --json",
|
|
22
22
|
"demo-names-json": "node ./bin/find --names --json",
|
|
23
|
+
"print-changed-specs": "node ./bin/find --branch main",
|
|
23
24
|
"semantic-release": "semantic-release"
|
|
24
25
|
},
|
|
25
26
|
"repository": {
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"find-test-names": "^1.14.1",
|
|
50
51
|
"globby": "^11.0.4",
|
|
51
52
|
"minimatch": "^3.0.4",
|
|
52
|
-
"pluralize": "^8.0.0"
|
|
53
|
+
"pluralize": "^8.0.0",
|
|
54
|
+
"shelljs": "^0.8.5"
|
|
53
55
|
}
|
|
54
56
|
}
|
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
|
}
|