find-cypress-specs 1.14.2 → 1.16.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 +26 -1
- package/bin/find.js +3 -1
- package/package.json +4 -3
- package/src/index.js +40 -12
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
|
|
|
@@ -8,6 +8,8 @@ $ npx find-cypress-specs
|
|
|
8
8
|
cypress/e2e/spec.js,cypress/e2e/featureA/user.js
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Supports JS and TS specs
|
|
12
|
+
|
|
11
13
|
## against branch
|
|
12
14
|
|
|
13
15
|
By default, this module simply prints all spec filenames. You can add `--branch` parameter to only print the specs changed against that `origin/branch`.
|
|
@@ -17,6 +19,24 @@ $ npx find-cypress-specs --branch main
|
|
|
17
19
|
# prints only some specs, the ones that have changed against the "origin/main"
|
|
18
20
|
```
|
|
19
21
|
|
|
22
|
+
## against the parent commit
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
$ npx find-cypress-specs --branch main --parent
|
|
28
|
+
# same as
|
|
29
|
+
# git diff --name-only --diff-filter=AMR $(git merge-base origin/main HEAD)..
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Note: to get the changed files, we need to fetch the repo, see [pr.yml](./.github/workflows/pr.yml)
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
$ checkout
|
|
36
|
+
$ git fetch
|
|
37
|
+
$ npx find-cypress-specs --branch main --parent
|
|
38
|
+
```
|
|
39
|
+
|
|
20
40
|
### number of changed files
|
|
21
41
|
|
|
22
42
|
You can print just the number of changed specs
|
|
@@ -99,6 +119,10 @@ Run the utility with environment variable `DEBUG=find-cypress-specs` to see the
|
|
|
99
119
|
|
|
100
120
|
- [Use Ava Snapshots And Execa-wrap To Write End-to-End Tests For CLI Utilities](https://youtu.be/rsw17RqP0G0)
|
|
101
121
|
|
|
122
|
+
## Examples
|
|
123
|
+
|
|
124
|
+
- [chat.io](https://github.com/bahmutov/chat.io) as described in the blog post [Get Faster Feedback From Your Cypress Tests Running On CircleCI](https://glebbahmutov.com/blog/faster-ci-feedback-on-circleci/)
|
|
125
|
+
|
|
102
126
|
## Small print
|
|
103
127
|
|
|
104
128
|
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
|
|
@@ -109,6 +133,7 @@ Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
|
|
|
109
133
|
- [videos](https://www.youtube.com/glebbahmutov)
|
|
110
134
|
- [presentations](https://slides.com/bahmutov)
|
|
111
135
|
- [cypress.tips](https://cypress.tips)
|
|
136
|
+
- [Cypress Tips&Tricks](https://cypresstips.substack.com/) newsletter
|
|
112
137
|
|
|
113
138
|
License: MIT - do anything with the code, but don't blame me if it does not work.
|
|
114
139
|
|
package/bin/find.js
CHANGED
|
@@ -18,6 +18,8 @@ const args = arg({
|
|
|
18
18
|
'--json': Boolean,
|
|
19
19
|
// find the specs that have changed against this Git branch
|
|
20
20
|
'--branch': String,
|
|
21
|
+
// find the specs that have changed against the parent of the branch
|
|
22
|
+
'--parent': Boolean,
|
|
21
23
|
'--count': Boolean,
|
|
22
24
|
// filter all tests to those that have the given tag
|
|
23
25
|
'--tagged': String,
|
|
@@ -111,7 +113,7 @@ if (args['--names'] || args['--tags']) {
|
|
|
111
113
|
}
|
|
112
114
|
} else if (args['--branch']) {
|
|
113
115
|
debug('determining specs changed against branch %s', args['--branch'])
|
|
114
|
-
const changedFiles = findChangedFiles(args['--branch'])
|
|
116
|
+
const changedFiles = findChangedFiles(args['--branch'], args['--parent'])
|
|
115
117
|
debug('changed files %o', changedFiles)
|
|
116
118
|
const changedSpecs = specs.filter((file) => changedFiles.includes(file))
|
|
117
119
|
if (args['--count']) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -40,10 +40,11 @@
|
|
|
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
|
-
"semantic-release": "19.0.2"
|
|
46
|
+
"semantic-release": "19.0.2",
|
|
47
|
+
"typescript": "^4.6.3"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
50
|
"arg": "^5.0.1",
|
package/src/index.js
CHANGED
|
@@ -25,7 +25,7 @@ function getConfig(filename = 'cypress.json') {
|
|
|
25
25
|
function findCypressSpecs(opts = {}) {
|
|
26
26
|
const defaults = {
|
|
27
27
|
integrationFolder: 'cypress/integration',
|
|
28
|
-
testFiles: '**/*.js',
|
|
28
|
+
testFiles: '**/*.{js,ts}',
|
|
29
29
|
ignoreTestFiles: [],
|
|
30
30
|
}
|
|
31
31
|
const options = {
|
|
@@ -104,8 +104,9 @@ function collectResults(structure, results) {
|
|
|
104
104
|
* Finds files changed or added in the current branch when compared to the "origin/branch".
|
|
105
105
|
* Returns a list of filenames. If there are no files, returns an empty list.
|
|
106
106
|
* @param {string} branch The branch to compare against.
|
|
107
|
+
* @param {boolean} useParent Determine the changes only against the parent commit.
|
|
107
108
|
*/
|
|
108
|
-
function findChangedFiles(branch) {
|
|
109
|
+
function findChangedFiles(branch, useParent) {
|
|
109
110
|
if (!branch) {
|
|
110
111
|
throw new Error('branch is required')
|
|
111
112
|
}
|
|
@@ -115,17 +116,44 @@ function findChangedFiles(branch) {
|
|
|
115
116
|
return []
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
// can we find updated and added files?
|
|
120
|
+
debug('finding changed files against %s', branch)
|
|
121
|
+
debug('using parent?', useParent)
|
|
122
|
+
|
|
123
|
+
if (useParent) {
|
|
124
|
+
let result = shell.exec(`git merge-base origin/${branch} HEAD`, {
|
|
125
|
+
silent: true,
|
|
126
|
+
})
|
|
127
|
+
if (result.code !== 0) {
|
|
128
|
+
debug('git failed to find merge base with the branch %s', branch)
|
|
129
|
+
return []
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const commit = result.stdout.trim()
|
|
133
|
+
debug('merge commit with branch "%s" is %s', branch, commit)
|
|
134
|
+
result = shell.exec(`git diff --name-only --diff-filter=AMR ${commit}..`, {
|
|
135
|
+
silent: true,
|
|
136
|
+
})
|
|
137
|
+
if (result.code !== 0) {
|
|
138
|
+
debug('git diff failed with code %d', result.code)
|
|
139
|
+
return []
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const filenames = result.stdout.split('\n').filter(Boolean)
|
|
143
|
+
return filenames
|
|
144
|
+
} else {
|
|
145
|
+
const command = `git diff --name-only --diff-filter=AMR origin/${branch}`
|
|
146
|
+
debug('command: %s', command)
|
|
126
147
|
|
|
127
|
-
|
|
128
|
-
|
|
148
|
+
const result = shell.exec(command, { silent: true })
|
|
149
|
+
if (result.code !== 0) {
|
|
150
|
+
debug('git diff failed with code %d', result.code)
|
|
151
|
+
return []
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const filenames = result.stdout.split('\n').filter(Boolean)
|
|
155
|
+
return filenames
|
|
156
|
+
}
|
|
129
157
|
}
|
|
130
158
|
|
|
131
159
|
module.exports = {
|