find-cypress-specs 1.22.0 → 1.24.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.
Files changed (3) hide show
  1. package/README.md +13 -0
  2. package/bin/find.js +44 -3
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -61,6 +61,19 @@ $ npx find-cypress-specs --branch main --parent --trace-imports cypress
61
61
 
62
62
  **Note:** the argument is the subfolder name to limit the number of files to inspect when tracing the imports.
63
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
+
75
+ You can limit the number of added traced files using the `--max-added-traced-specs <N>` parameter. This avoids ALL specs added when you change some common utility that many specs import.
76
+
64
77
  ### number of changed files
65
78
 
66
79
  You can print just the number of changed specs
package/bin/find.js CHANGED
@@ -37,6 +37,11 @@ const args = arg({
37
37
  // to set two named outputs, one for number of changed specs
38
38
  // another for actual list of files
39
39
  '--set-gha-outputs': Boolean,
40
+ // save a JSON file with traced dependencies to save time
41
+ '--cache-trace': Boolean,
42
+ '--time-trace': Boolean,
43
+ // do not add more than this number of extra specs after tracing
44
+ '--max-added-traced-specs': Number,
40
45
  // aliases
41
46
  '-n': '--names',
42
47
  '--name': '--names',
@@ -141,10 +146,41 @@ if (args['--names'] || args['--tags']) {
141
146
  debug('comparing against the specs %o', specs)
142
147
  if (args['--trace-imports']) {
143
148
  debug('tracing dependent changes in folder %s', args['--trace-imports'])
144
- const absoluteFolder = path.join(process.cwd(), args['--trace-imports'])
145
- const deps = getDependsInFolder(absoluteFolder)
149
+
150
+ const saveDependenciesFile = 'deps.json'
151
+ let deps
152
+ if (args['--cache-trace']) {
153
+ if (fs.existsSync(saveDependenciesFile)) {
154
+ debug(
155
+ 'loading cached traced dependencies from file %s',
156
+ saveDependenciesFile,
157
+ )
158
+ deps = JSON.parse(fs.readFileSync(saveDependenciesFile, 'utf-8')).deps
159
+ }
160
+ }
161
+
162
+ if (!deps) {
163
+ const absoluteFolder = path.join(process.cwd(), args['--trace-imports'])
164
+ const depsOptions = { folder: absoluteFolder, time: args['--time-trace'] }
165
+ if (args['--cache-trace']) {
166
+ depsOptions.saveDepsFilename = saveDependenciesFile
167
+ debug(
168
+ 'will save found dependencies into the file %s',
169
+ saveDependenciesFile,
170
+ )
171
+ }
172
+ debug('tracing options %o', depsOptions)
173
+ deps = getDependsInFolder(depsOptions)
174
+ }
146
175
  debug('traced dependencies via imports and require')
147
176
  debug(deps)
177
+
178
+ // add a sensible limit to the number of extra specs to add
179
+ // when we trace the dependencies in the changed source files
180
+ const addedTracedFiles = []
181
+ const maxAddTracedFiles = args['--max-added-traced-specs'] || 1000
182
+ debug('maximum traced files to add %d', maxAddTracedFiles)
183
+
148
184
  Object.entries(deps).forEach(([filename, fileDependents]) => {
149
185
  const f = path.join(args['--trace-imports'], filename)
150
186
  if (changedFiles.includes(f)) {
@@ -156,12 +192,17 @@ if (args['--names'] || args['--tags']) {
156
192
  fileDependents.forEach((name) => {
157
193
  const nameInCypressFolder = path.join(args['--trace-imports'], name)
158
194
  if (!changedFiles.includes(nameInCypressFolder)) {
159
- changedFiles.push(nameInCypressFolder)
195
+ if (addedTracedFiles.length < maxAddTracedFiles) {
196
+ changedFiles.push(nameInCypressFolder)
197
+ addedTracedFiles.push(nameInCypressFolder)
198
+ }
160
199
  }
161
200
  })
162
201
  }
163
202
  })
203
+ debug('added %d traced specs %o', addedTracedFiles.length, addedTracedFiles)
164
204
  }
205
+
165
206
  let changedSpecs = specs.filter((file) => changedFiles.includes(file))
166
207
  debug('changed %d specs %o', changedSpecs.length, changedSpecs)
167
208
  if (args['--set-gha-outputs']) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.22.0",
3
+ "version": "1.24.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",
@@ -62,7 +62,7 @@
62
62
  "pluralize": "^8.0.0",
63
63
  "require-and-forget": "^1.0.0",
64
64
  "shelljs": "^0.8.5",
65
- "spec-change": "^1.4.0",
65
+ "spec-change": "^1.6.0",
66
66
  "ts-node": "^10.9.1"
67
67
  }
68
68
  }