find-cypress-specs 1.21.0 → 1.23.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 -0
- package/bin/find.js +39 -3
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -19,6 +19,20 @@ $ npx find-cypress-specs --branch main
|
|
|
19
19
|
# prints only some specs, the ones that have changed against the "origin/main"
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## set GitHub Actions outputs
|
|
23
|
+
|
|
24
|
+
If you add `--set-gh-outputs` command line switch, then the number of changed specs and the comma-separated file list will be set as GH Actions outputs `changedSpecsN` and `changedSpecs`. See [pr.yml](./.github/workflows/pr.yml) for example
|
|
25
|
+
|
|
26
|
+
```yml
|
|
27
|
+
- name: Print specs changed against the parent of this branch 🌳
|
|
28
|
+
# and set GitHub Actions output
|
|
29
|
+
id: step1
|
|
30
|
+
run: node ./bin/find --branch main --parent --set-gha-outputs
|
|
31
|
+
|
|
32
|
+
- name: Print set outputs
|
|
33
|
+
run: echo ${{ steps.step1.outputs.changedSpecsN }} ${{ steps.step1.outputs.changedSpecs }}
|
|
34
|
+
```
|
|
35
|
+
|
|
22
36
|
## against the parent commit
|
|
23
37
|
|
|
24
38
|
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.
|
|
@@ -47,6 +61,17 @@ $ npx find-cypress-specs --branch main --parent --trace-imports cypress
|
|
|
47
61
|
|
|
48
62
|
**Note:** the argument is the subfolder name to limit the number of files to inspect when tracing the imports.
|
|
49
63
|
|
|
64
|
+
You can time how long tracing takes by adding option `--time-trace` to the command line arguments. You can also saved traced dependencies using `--cache-trace` argument. Next time the dependencies will be loaded from the file without recomputing. This is convenient on CI to avoid recomputing them. For example, if you need the number of affected files and their filenames
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
# get the number of affected specs
|
|
68
|
+
$ npx find-cypress-specs --branch main --parent --trace-imports cypress --cache-trace --count
|
|
69
|
+
# quickly get the affected specs without recomputing the dependencies
|
|
70
|
+
$ npx find-cypress-specs --branch main --parent --trace-imports cypress --cache-trace
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The cached trace will be saved in file `deps.json`, you probably want to Git ignore it.
|
|
74
|
+
|
|
50
75
|
### number of changed files
|
|
51
76
|
|
|
52
77
|
You can print just the number of changed specs
|
package/bin/find.js
CHANGED
|
@@ -12,6 +12,7 @@ const { getTestNames, countTags } = require('find-test-names')
|
|
|
12
12
|
const consoleTable = require('console.table')
|
|
13
13
|
const debug = require('debug')('find-cypress-specs')
|
|
14
14
|
const { getDependsInFolder } = require('spec-change')
|
|
15
|
+
const core = require('@actions/core')
|
|
15
16
|
|
|
16
17
|
const args = arg({
|
|
17
18
|
'--names': Boolean,
|
|
@@ -32,7 +33,13 @@ const args = arg({
|
|
|
32
33
|
// and consider specs that import a changes source file changed to
|
|
33
34
|
// The value of this argument is the subfolder with Cypress tests, like "cypress"
|
|
34
35
|
'--trace-imports': String,
|
|
35
|
-
|
|
36
|
+
// when enabled, this code uses GitHub Actions Core package
|
|
37
|
+
// to set two named outputs, one for number of changed specs
|
|
38
|
+
// another for actual list of files
|
|
39
|
+
'--set-gha-outputs': Boolean,
|
|
40
|
+
// save a JSON file with traced dependencies to save time
|
|
41
|
+
'--cache-trace': Boolean,
|
|
42
|
+
'--time-trace': Boolean,
|
|
36
43
|
// aliases
|
|
37
44
|
'-n': '--names',
|
|
38
45
|
'--name': '--names',
|
|
@@ -137,8 +144,32 @@ if (args['--names'] || args['--tags']) {
|
|
|
137
144
|
debug('comparing against the specs %o', specs)
|
|
138
145
|
if (args['--trace-imports']) {
|
|
139
146
|
debug('tracing dependent changes in folder %s', args['--trace-imports'])
|
|
140
|
-
|
|
141
|
-
const
|
|
147
|
+
|
|
148
|
+
const saveDependenciesFile = 'deps.json'
|
|
149
|
+
let deps
|
|
150
|
+
if (args['--cache-trace']) {
|
|
151
|
+
if (fs.existsSync(saveDependenciesFile)) {
|
|
152
|
+
debug(
|
|
153
|
+
'loading cached traced dependencies from file %s',
|
|
154
|
+
saveDependenciesFile,
|
|
155
|
+
)
|
|
156
|
+
deps = JSON.parse(fs.readFileSync(saveDependenciesFile, 'utf-8')).deps
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!deps) {
|
|
161
|
+
const absoluteFolder = path.join(process.cwd(), args['--trace-imports'])
|
|
162
|
+
const depsOptions = { folder: absoluteFolder, time: args['--time-trace'] }
|
|
163
|
+
if (args['--cache-trace']) {
|
|
164
|
+
depsOptions.saveDepsFilename = saveDependenciesFile
|
|
165
|
+
debug(
|
|
166
|
+
'will save found dependencies into the file %s',
|
|
167
|
+
saveDependenciesFile,
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
debug('tracing options %o', depsOptions)
|
|
171
|
+
deps = getDependsInFolder(depsOptions)
|
|
172
|
+
}
|
|
142
173
|
debug('traced dependencies via imports and require')
|
|
143
174
|
debug(deps)
|
|
144
175
|
Object.entries(deps).forEach(([filename, fileDependents]) => {
|
|
@@ -160,6 +191,11 @@ if (args['--names'] || args['--tags']) {
|
|
|
160
191
|
}
|
|
161
192
|
let changedSpecs = specs.filter((file) => changedFiles.includes(file))
|
|
162
193
|
debug('changed %d specs %o', changedSpecs.length, changedSpecs)
|
|
194
|
+
if (args['--set-gha-outputs']) {
|
|
195
|
+
debug('setting GitHub Actions outputs changedSpecsN and changedSpecs')
|
|
196
|
+
core.setOutput('changedSpecsN', changedSpecs.length)
|
|
197
|
+
core.setOutput('changedSpecs', changedSpecs.join(','))
|
|
198
|
+
}
|
|
163
199
|
|
|
164
200
|
if (args['--tagged']) {
|
|
165
201
|
const splitTags = args['--tagged']
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"count-changed-specs": "node ./bin/find --branch main --count",
|
|
27
27
|
"semantic-release": "semantic-release",
|
|
28
28
|
"deps": "spec-change --folder . --mask 'cypress/**/*.{js,ts}'",
|
|
29
|
-
"deps-changed": "DEBUG=find-cypress-specs node ./bin/find --branch main --parent --trace-imports cypress"
|
|
29
|
+
"deps-changed": "DEBUG=find-cypress-specs node ./bin/find --branch main --parent --trace-imports cypress --time-trace --cache-trace"
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"typescript": "^4.6.3"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
+
"@actions/core": "^1.10.0",
|
|
55
56
|
"arg": "^5.0.1",
|
|
56
57
|
"console.table": "^0.10.0",
|
|
57
58
|
"debug": "^4.3.3",
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
"pluralize": "^8.0.0",
|
|
62
63
|
"require-and-forget": "^1.0.0",
|
|
63
64
|
"shelljs": "^0.8.5",
|
|
64
|
-
"spec-change": "^1.
|
|
65
|
+
"spec-change": "^1.6.0",
|
|
65
66
|
"ts-node": "^10.9.1"
|
|
66
67
|
}
|
|
67
68
|
}
|