find-cypress-specs 1.20.2 → 1.21.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 +11 -1
- package/bin/find.js +33 -2
- package/package.json +6 -3
- package/src/index.js +2 -2
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
|
|
|
@@ -37,6 +37,16 @@ $ git fetch
|
|
|
37
37
|
$ npx find-cypress-specs --branch main --parent
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
## with traced import and require statements
|
|
41
|
+
|
|
42
|
+
Imagine you open a pull request and only change something in an `utils.js` file used by other specs. Which specs should you run? By default `--branch main --parent` would not find any changed specs, so no specs would execute, and you will have to run _all_ specs just to be safe. This program has a mode `--trace-imports <subfolder>` which uses [spec-change](https://github.com/bahmutov/spec-change) to inspect JS/TS files and find dependencies between them. Thus it can discover that when `utils.js` changes, the specs that `import './utils'` or `require('./utils')` should also be considered modified.
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
$ npx find-cypress-specs --branch main --parent --trace-imports cypress
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Note:** the argument is the subfolder name to limit the number of files to inspect when tracing the imports.
|
|
49
|
+
|
|
40
50
|
### number of changed files
|
|
41
51
|
|
|
42
52
|
You can print just the number of changed specs
|
package/bin/find.js
CHANGED
|
@@ -7,9 +7,11 @@ const { addCounts } = require('../src/count')
|
|
|
7
7
|
const { stringAllInfo } = require('../src/print')
|
|
8
8
|
|
|
9
9
|
const fs = require('fs')
|
|
10
|
+
const path = require('path')
|
|
10
11
|
const { getTestNames, countTags } = require('find-test-names')
|
|
11
12
|
const consoleTable = require('console.table')
|
|
12
13
|
const debug = require('debug')('find-cypress-specs')
|
|
14
|
+
const { getDependsInFolder } = require('spec-change')
|
|
13
15
|
|
|
14
16
|
const args = arg({
|
|
15
17
|
'--names': Boolean,
|
|
@@ -25,6 +27,11 @@ const args = arg({
|
|
|
25
27
|
'--tagged': String,
|
|
26
28
|
// print only the "it.only" tests
|
|
27
29
|
'--skipped': Boolean,
|
|
30
|
+
// when finding specs changed against a given parent of the branch
|
|
31
|
+
// also look at the import and require statements to trace dependencies
|
|
32
|
+
// and consider specs that import a changes source file changed to
|
|
33
|
+
// The value of this argument is the subfolder with Cypress tests, like "cypress"
|
|
34
|
+
'--trace-imports': String,
|
|
28
35
|
|
|
29
36
|
// aliases
|
|
30
37
|
'-n': '--names',
|
|
@@ -33,6 +40,7 @@ const args = arg({
|
|
|
33
40
|
'--tag': '--tags',
|
|
34
41
|
'-j': '--json',
|
|
35
42
|
'-b': '--branch',
|
|
43
|
+
'--deps': '--trace-imports',
|
|
36
44
|
// Cypress test status (just like Mocha)
|
|
37
45
|
// calls "it.skip" pending tests
|
|
38
46
|
// https://glebbahmutov.com/blog/cypress-test-statuses/
|
|
@@ -124,11 +132,34 @@ if (args['--names'] || args['--tags']) {
|
|
|
124
132
|
}
|
|
125
133
|
} else if (args['--branch']) {
|
|
126
134
|
debug('determining specs changed against branch %s', args['--branch'])
|
|
127
|
-
|
|
135
|
+
let changedFiles = findChangedFiles(args['--branch'], args['--parent'])
|
|
128
136
|
debug('changed files %o', changedFiles)
|
|
129
137
|
debug('comparing against the specs %o', specs)
|
|
138
|
+
if (args['--trace-imports']) {
|
|
139
|
+
debug('tracing dependent changes in folder %s', args['--trace-imports'])
|
|
140
|
+
const absoluteFolder = path.join(process.cwd(), args['--trace-imports'])
|
|
141
|
+
const deps = getDependsInFolder(absoluteFolder)
|
|
142
|
+
debug('traced dependencies via imports and require')
|
|
143
|
+
debug(deps)
|
|
144
|
+
Object.entries(deps).forEach(([filename, fileDependents]) => {
|
|
145
|
+
const f = path.join(args['--trace-imports'], filename)
|
|
146
|
+
if (changedFiles.includes(f)) {
|
|
147
|
+
debug(
|
|
148
|
+
'the source file %s has changed, including its dependents %o in the list of changed files',
|
|
149
|
+
f,
|
|
150
|
+
fileDependents,
|
|
151
|
+
)
|
|
152
|
+
fileDependents.forEach((name) => {
|
|
153
|
+
const nameInCypressFolder = path.join(args['--trace-imports'], name)
|
|
154
|
+
if (!changedFiles.includes(nameInCypressFolder)) {
|
|
155
|
+
changedFiles.push(nameInCypressFolder)
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
}
|
|
130
161
|
let changedSpecs = specs.filter((file) => changedFiles.includes(file))
|
|
131
|
-
debug('changed specs %o', changedSpecs)
|
|
162
|
+
debug('changed %d specs %o', changedSpecs.length, changedSpecs)
|
|
132
163
|
|
|
133
164
|
if (args['--tagged']) {
|
|
134
165
|
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.21.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"demo-names-tagged": "node ./bin/find --names --tagged @user",
|
|
25
25
|
"print-changed-specs": "node ./bin/find --branch main",
|
|
26
26
|
"count-changed-specs": "node ./bin/find --branch main --count",
|
|
27
|
-
"semantic-release": "semantic-release"
|
|
27
|
+
"semantic-release": "semantic-release",
|
|
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"
|
|
28
30
|
},
|
|
29
31
|
"repository": {
|
|
30
32
|
"type": "git",
|
|
@@ -41,7 +43,7 @@
|
|
|
41
43
|
"homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"ava": "^4.0.0",
|
|
44
|
-
"cypress": "12.0
|
|
46
|
+
"cypress": "12.2.0",
|
|
45
47
|
"execa-wrap": "^1.4.0",
|
|
46
48
|
"prettier": "^2.5.1",
|
|
47
49
|
"really-need": "^1.9.2",
|
|
@@ -59,6 +61,7 @@
|
|
|
59
61
|
"pluralize": "^8.0.0",
|
|
60
62
|
"require-and-forget": "^1.0.0",
|
|
61
63
|
"shelljs": "^0.8.5",
|
|
64
|
+
"spec-change": "^1.4.0",
|
|
62
65
|
"ts-node": "^10.9.1"
|
|
63
66
|
}
|
|
64
67
|
}
|
package/src/index.js
CHANGED
|
@@ -240,8 +240,8 @@ function findChangedFiles(branch, useParent) {
|
|
|
240
240
|
|
|
241
241
|
const filenames = result.stdout
|
|
242
242
|
.split('\n')
|
|
243
|
-
.filter(Boolean)
|
|
244
243
|
.map((s) => s.trim())
|
|
244
|
+
.filter(Boolean)
|
|
245
245
|
return filenames
|
|
246
246
|
} else {
|
|
247
247
|
const command = `git diff --name-only --diff-filter=AMR origin/${branch}`
|
|
@@ -255,8 +255,8 @@ function findChangedFiles(branch, useParent) {
|
|
|
255
255
|
|
|
256
256
|
const filenames = result.stdout
|
|
257
257
|
.split('\n')
|
|
258
|
-
.filter(Boolean)
|
|
259
258
|
.map((s) => s.trim())
|
|
259
|
+
.filter(Boolean)
|
|
260
260
|
debug(
|
|
261
261
|
'found %d changed %s',
|
|
262
262
|
filenames.length,
|