find-cypress-specs 1.14.0 → 1.15.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 +25 -1
- package/bin/find.js +18 -1
- package/package.json +3 -3
- package/src/index.js +29 -4
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
|
|
|
@@ -17,6 +17,29 @@ $ npx find-cypress-specs --branch main
|
|
|
17
17
|
# prints only some specs, the ones that have changed against the "origin/main"
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
## against the parent commit
|
|
21
|
+
|
|
22
|
+
When dealing with a long-term branch, you do not want to see the changed files in the main branch. Instead, you want to only consider the specs changed in the _current_ branch all the way to its parent commit. You can pass the flag `--parent` to only pick the modified and added specs.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
$ npx find-cypress-specs --parent
|
|
26
|
+
# same as
|
|
27
|
+
# git diff --name-only --diff-filter=AMR HEAD^!
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Note: in order to trace the commits back to the parent commit of the branch, fetch the entire repo or enough commits to have this information when checking out the repo. For example, in [pr.yml](./.github/workflows/pr.yml) we fetch the entire history
|
|
31
|
+
|
|
32
|
+
```yml
|
|
33
|
+
- name: Checkout 🛎
|
|
34
|
+
# https://github.com/actions/checkout
|
|
35
|
+
uses: actions/checkout@v3
|
|
36
|
+
# check out all the commits in the repo
|
|
37
|
+
# to make sure we detect the changed files in this branch
|
|
38
|
+
# against its parent commit
|
|
39
|
+
with:
|
|
40
|
+
fetch-depth: 0
|
|
41
|
+
```
|
|
42
|
+
|
|
20
43
|
### number of changed files
|
|
21
44
|
|
|
22
45
|
You can print just the number of changed specs
|
|
@@ -109,6 +132,7 @@ Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
|
|
|
109
132
|
- [videos](https://www.youtube.com/glebbahmutov)
|
|
110
133
|
- [presentations](https://slides.com/bahmutov)
|
|
111
134
|
- [cypress.tips](https://cypress.tips)
|
|
135
|
+
- [Cypress Tips&Tricks](https://cypresstips.substack.com/) newsletter
|
|
112
136
|
|
|
113
137
|
License: MIT - do anything with the code, but don't blame me if it does not work.
|
|
114
138
|
|
package/bin/find.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const arg = require('arg')
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
getSpecs,
|
|
6
|
+
collectResults,
|
|
7
|
+
findChangedFiles,
|
|
8
|
+
findChangedFilesAgainstParent,
|
|
9
|
+
} = require('../src')
|
|
5
10
|
const { pickTaggedTestsFrom } = require('../src/tagged')
|
|
6
11
|
const { addCounts } = require('../src/count')
|
|
7
12
|
const { stringAllInfo } = require('../src/print')
|
|
@@ -18,6 +23,8 @@ const args = arg({
|
|
|
18
23
|
'--json': Boolean,
|
|
19
24
|
// find the specs that have changed against this Git branch
|
|
20
25
|
'--branch': String,
|
|
26
|
+
// find the specs that have changed against the parent of this branch
|
|
27
|
+
'--parent': Boolean,
|
|
21
28
|
'--count': Boolean,
|
|
22
29
|
// filter all tests to those that have the given tag
|
|
23
30
|
'--tagged': String,
|
|
@@ -119,6 +126,16 @@ if (args['--names'] || args['--tags']) {
|
|
|
119
126
|
} else {
|
|
120
127
|
console.log(changedSpecs.join(','))
|
|
121
128
|
}
|
|
129
|
+
} else if (args['--parent']) {
|
|
130
|
+
debug('determining specs changed against the parent of this branch')
|
|
131
|
+
const changedFiles = findChangedFilesAgainstParent()
|
|
132
|
+
debug('changed files %o', changedFiles)
|
|
133
|
+
const changedSpecs = specs.filter((file) => changedFiles.includes(file))
|
|
134
|
+
if (args['--count']) {
|
|
135
|
+
console.log(changedSpecs.length)
|
|
136
|
+
} else {
|
|
137
|
+
console.log(changedSpecs.join(','))
|
|
138
|
+
}
|
|
122
139
|
} else {
|
|
123
140
|
console.log(specs.join(','))
|
|
124
141
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"ava": "^4.0.0",
|
|
43
|
-
"cypress": "9.5.
|
|
43
|
+
"cypress": "9.5.3",
|
|
44
44
|
"execa-wrap": "^1.4.0",
|
|
45
45
|
"prettier": "^2.5.1",
|
|
46
46
|
"semantic-release": "19.0.2"
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"arg": "^5.0.1",
|
|
50
50
|
"console.table": "^0.10.0",
|
|
51
51
|
"debug": "^4.3.3",
|
|
52
|
-
"find-test-names": "^1.
|
|
52
|
+
"find-test-names": "^1.15.1",
|
|
53
53
|
"globby": "^11.0.4",
|
|
54
54
|
"minimatch": "^3.0.4",
|
|
55
55
|
"pluralize": "^8.0.0",
|
package/src/index.js
CHANGED
|
@@ -115,10 +115,34 @@ function findChangedFiles(branch) {
|
|
|
115
115
|
return []
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
118
|
+
// can we find updated and added files?
|
|
119
|
+
debug('finding changed files against %s', branch)
|
|
120
|
+
const command = `git diff --name-only --diff-filter=AMR origin/${branch}`
|
|
121
|
+
debug('command: %s', command)
|
|
122
|
+
|
|
123
|
+
const result = shell.exec(command, { silent: true })
|
|
124
|
+
if (result.code !== 0) {
|
|
125
|
+
debug('git diff failed with code %d', result.code)
|
|
126
|
+
return []
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const filenames = result.stdout.split('\n').filter(Boolean)
|
|
130
|
+
return filenames
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Finds files modified or added against the parent commit of the current branch.
|
|
135
|
+
* Returns a list of filenames. If there are no files, returns an empty list.
|
|
136
|
+
*/
|
|
137
|
+
function findChangedFilesAgainstParent() {
|
|
138
|
+
if (!shell.which('git')) {
|
|
139
|
+
shell.echo('Sorry, this script requires git')
|
|
140
|
+
return []
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const result = shell.exec(`git diff --name-only --diff-filter=AMR HEAD^!`, {
|
|
144
|
+
silent: true,
|
|
145
|
+
})
|
|
122
146
|
if (result.code !== 0) {
|
|
123
147
|
debug('git diff failed with code %d', result.code)
|
|
124
148
|
return []
|
|
@@ -135,4 +159,5 @@ module.exports = {
|
|
|
135
159
|
findCypressSpecs,
|
|
136
160
|
collectResults,
|
|
137
161
|
findChangedFiles,
|
|
162
|
+
findChangedFilesAgainstParent,
|
|
138
163
|
}
|