find-cypress-specs 1.32.0 → 1.33.1
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 +17 -1
- package/bin/find.js +10 -26
- package/package.json +8 -5
- package/src/badge.js +22 -1
- package/src/tests-counts.js +38 -0
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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
|
|
|
5
|
+

|
|
6
|
+
|
|
5
7
|
```bash
|
|
6
8
|
$ npx find-cypress-specs
|
|
7
9
|
# prints all spec files separated by a comma
|
|
@@ -235,6 +237,20 @@ $ npx find-cypress-specs --test-counts
|
|
|
235
237
|
4 e2e tests, 2 component tests
|
|
236
238
|
```
|
|
237
239
|
|
|
240
|
+
### Update README badge
|
|
241
|
+
|
|
242
|
+
You can set or update a badge in README with test counts by adding the `--update-badge` argument
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
$ npx find-cypress-specs --test-counts --update-badge
|
|
246
|
+
4 e2e tests, 2 component tests
|
|
247
|
+
⚠️ Could not find test count badge
|
|
248
|
+
Insert new badge on the first line
|
|
249
|
+
saving updated readme with new test counts
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
See the [badges.yml workflow](./.github/workflows/badges.yml)
|
|
253
|
+
|
|
238
254
|
## Count skipped tests
|
|
239
255
|
|
|
240
256
|
Prints the single number with the count of skipped tests
|
package/bin/find.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const arg = require('arg')
|
|
4
4
|
const { getSpecs, findChangedFiles, getTests } = require('../src')
|
|
5
|
+
const { getTestCounts } = require('../src/tests-counts')
|
|
5
6
|
const { stringAllInfo } = require('../src/print')
|
|
7
|
+
const { updateBadge } = require('../src/badge')
|
|
6
8
|
|
|
7
9
|
const fs = require('fs')
|
|
8
10
|
const path = require('path')
|
|
@@ -45,6 +47,8 @@ const args = arg({
|
|
|
45
47
|
'--component': Boolean,
|
|
46
48
|
// count total number of E2E and component tests
|
|
47
49
|
'--test-counts': Boolean,
|
|
50
|
+
// if we count the tests, we can update the README badge
|
|
51
|
+
'--update-badge': Boolean,
|
|
48
52
|
// aliases
|
|
49
53
|
'-n': '--names',
|
|
50
54
|
'--name': '--names',
|
|
@@ -63,32 +67,8 @@ const args = arg({
|
|
|
63
67
|
debug('arguments %o', args)
|
|
64
68
|
|
|
65
69
|
if (args['--test-counts']) {
|
|
66
|
-
debug('finding
|
|
67
|
-
const
|
|
68
|
-
debug('found %d e2e specs', e2eSpecs.length)
|
|
69
|
-
debug('finding all component specs')
|
|
70
|
-
const componentSpecs = getSpecs(undefined, 'component')
|
|
71
|
-
debug('found %d component specs', componentSpecs.length)
|
|
72
|
-
|
|
73
|
-
debug('counting all e2e tests')
|
|
74
|
-
const { jsonResults: e2eResults } = getTests(e2eSpecs)
|
|
75
|
-
debug(e2eResults)
|
|
76
|
-
let nE2E = 0
|
|
77
|
-
Object.keys(e2eResults).forEach((filename) => {
|
|
78
|
-
const n = e2eResults[filename].counts.tests
|
|
79
|
-
nE2E += n
|
|
80
|
-
})
|
|
81
|
-
debug('found %d E2E tests', nE2E)
|
|
82
|
-
|
|
83
|
-
debug('counting all component tests')
|
|
84
|
-
const { jsonResults: componentResults } = getTests(componentSpecs)
|
|
85
|
-
debug(componentResults)
|
|
86
|
-
let nComponent = 0
|
|
87
|
-
Object.keys(componentResults).forEach((filename) => {
|
|
88
|
-
const n = componentResults[filename].counts.tests
|
|
89
|
-
nComponent += n
|
|
90
|
-
})
|
|
91
|
-
debug('found %d component tests', nComponent)
|
|
70
|
+
debug('finding test counts')
|
|
71
|
+
const { nE2E, nComponent } = getTestCounts()
|
|
92
72
|
console.log(
|
|
93
73
|
'%d e2e %s, %d component %s',
|
|
94
74
|
nE2E,
|
|
@@ -96,6 +76,10 @@ if (args['--test-counts']) {
|
|
|
96
76
|
nComponent,
|
|
97
77
|
pluralize('test', nComponent),
|
|
98
78
|
)
|
|
79
|
+
if (args['--update-badge']) {
|
|
80
|
+
debug('updating the README test count badge')
|
|
81
|
+
updateBadge({ nE2E, nComponent })
|
|
82
|
+
}
|
|
99
83
|
} else {
|
|
100
84
|
const specType = args['--component'] ? 'component' : 'e2e'
|
|
101
85
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.1",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -27,11 +27,13 @@
|
|
|
27
27
|
"print-changed-specs": "node ./bin/find --branch main",
|
|
28
28
|
"count-changed-specs": "node ./bin/find --branch main --count",
|
|
29
29
|
"demo-test-counts": "node ./bin/find --test-counts",
|
|
30
|
+
"demo-test-counts-badge": "node ./bin/find --test-counts --update-badge",
|
|
30
31
|
"semantic-release": "semantic-release",
|
|
31
32
|
"deps": "spec-change --folder . --mask 'cypress/**/*.{js,ts}'",
|
|
32
33
|
"deps-changed": "DEBUG=find-cypress-specs node ./bin/find --branch main --parent --trace-imports cypress --time-trace --cache-trace",
|
|
33
34
|
"demo-component": "DEBUG=find-cypress-specs node ./bin/find --component --names",
|
|
34
|
-
"demo-exclusive": "npm run test-names --prefix test-exclusive --silent"
|
|
35
|
+
"demo-exclusive": "npm run test-names --prefix test-exclusive --silent",
|
|
36
|
+
"version-badge": "update-badge cypress"
|
|
35
37
|
},
|
|
36
38
|
"repository": {
|
|
37
39
|
"type": "git",
|
|
@@ -48,11 +50,12 @@
|
|
|
48
50
|
"homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
|
|
49
51
|
"devDependencies": {
|
|
50
52
|
"ava": "^4.0.0",
|
|
51
|
-
"cypress": "12.
|
|
53
|
+
"cypress": "12.11.0",
|
|
54
|
+
"dependency-version-badge": "^1.11.0",
|
|
52
55
|
"execa-wrap": "^1.4.0",
|
|
53
56
|
"prettier": "^2.5.1",
|
|
54
57
|
"really-need": "^1.9.2",
|
|
55
|
-
"semantic-release": "21.0.
|
|
58
|
+
"semantic-release": "21.0.2",
|
|
56
59
|
"sinon": "^13.0.1",
|
|
57
60
|
"typescript": "^4.6.3"
|
|
58
61
|
},
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
"arg": "^5.0.1",
|
|
62
65
|
"console.table": "^0.10.0",
|
|
63
66
|
"debug": "^4.3.3",
|
|
64
|
-
"find-test-names": "1.28.
|
|
67
|
+
"find-test-names": "1.28.5",
|
|
65
68
|
"globby": "^11.0.4",
|
|
66
69
|
"minimatch": "^3.0.4",
|
|
67
70
|
"pluralize": "^8.0.0",
|
package/src/badge.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
const debug = require('debug')('find-cypress-specs')
|
|
2
4
|
const os = require('os')
|
|
5
|
+
const fs = require('fs')
|
|
3
6
|
|
|
4
7
|
function isNumber(n) {
|
|
5
8
|
return typeof n === 'number' && !isNaN(n)
|
|
@@ -74,4 +77,22 @@ function replaceBadge({
|
|
|
74
77
|
return updatedReadmeText
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
function updateBadge({ nE2E, nComponent }) {
|
|
81
|
+
debug('reading in README file')
|
|
82
|
+
// TODO: make the filename a parameter
|
|
83
|
+
const filename = 'README.md'
|
|
84
|
+
const readmeText = fs.readFileSync(filename, 'utf8')
|
|
85
|
+
const maybeChangedText = replaceBadge({
|
|
86
|
+
markdown: readmeText,
|
|
87
|
+
nE2E,
|
|
88
|
+
nComponent,
|
|
89
|
+
})
|
|
90
|
+
if (maybeChangedText !== readmeText) {
|
|
91
|
+
console.log('saving updated readme with new test counts')
|
|
92
|
+
fs.writeFileSync(filename, maybeChangedText, 'utf8')
|
|
93
|
+
} else {
|
|
94
|
+
debug('no updates to test counts')
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = { getBadgeMarkdown, replaceBadge, updateBadge }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const debug = require('debug')('find-cypress-specs')
|
|
3
|
+
const { getSpecs, getTests } = require('.')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Finds all E2E and component tests and returns totals
|
|
7
|
+
*/
|
|
8
|
+
function getTestCounts() {
|
|
9
|
+
debug('finding all e2e specs')
|
|
10
|
+
const e2eSpecs = getSpecs(undefined, 'e2e')
|
|
11
|
+
debug('found %d e2e specs', e2eSpecs.length)
|
|
12
|
+
debug('finding all component specs')
|
|
13
|
+
const componentSpecs = getSpecs(undefined, 'component')
|
|
14
|
+
debug('found %d component specs', componentSpecs.length)
|
|
15
|
+
|
|
16
|
+
debug('counting all e2e tests')
|
|
17
|
+
const { jsonResults: e2eResults } = getTests(e2eSpecs)
|
|
18
|
+
debug(e2eResults)
|
|
19
|
+
let nE2E = 0
|
|
20
|
+
Object.keys(e2eResults).forEach((filename) => {
|
|
21
|
+
const n = e2eResults[filename].counts.tests
|
|
22
|
+
nE2E += n
|
|
23
|
+
})
|
|
24
|
+
debug('found %d E2E tests', nE2E)
|
|
25
|
+
|
|
26
|
+
debug('counting all component tests')
|
|
27
|
+
const { jsonResults: componentResults } = getTests(componentSpecs)
|
|
28
|
+
debug(componentResults)
|
|
29
|
+
let nComponent = 0
|
|
30
|
+
Object.keys(componentResults).forEach((filename) => {
|
|
31
|
+
const n = componentResults[filename].counts.tests
|
|
32
|
+
nComponent += n
|
|
33
|
+
})
|
|
34
|
+
debug('found %d component tests', nComponent)
|
|
35
|
+
return { nE2E, nComponent }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { getTestCounts }
|