find-cypress-specs 1.3.0 → 1.7.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 +21 -3
  2. package/bin/find.js +66 -12
  3. package/package.json +5 -2
package/README.md CHANGED
@@ -16,19 +16,37 @@ You can print each spec file with the suite and test names inside of it (found u
16
16
  $ npx find-cypress-specs --names
17
17
  # prints something like
18
18
 
19
- cypress/e2e/spec.js
19
+ cypress/e2e/spec.js (2 tests)
20
20
  └─ parent suite [@main]
21
- ├─ works
21
+ ├─ works well enough
22
22
  └─ inner suite
23
23
  └─ shows something [@user]
24
24
 
25
- cypress/e2e/featureA/user.js
25
+ cypress/e2e/featureA/user.js (2 tests, 1 pending)
26
26
  ├─ works
27
27
  └⊙ needs to be written
28
+
29
+ found 2 specs (4 tests, 1 pending)
28
30
  ```
29
31
 
30
32
  Where the tags are listed inside `[ ... ]` (see [cypress-grep](https://github.com/cypress-io/cypress-grep)) and the [pending tests](https://glebbahmutov.com/blog/cypress-test-statuses/) are marked with `⊙` character.
31
33
 
34
+ ## Test tags
35
+
36
+ You can count tags attached to the individual tests using `--tags` arguments
37
+
38
+ ```
39
+ $ npx find-cypress-specs --tags
40
+ # prints the tags table sorted by tag
41
+
42
+ Tag Tests
43
+ ----- ----------
44
+ @sign 1
45
+ @user 2
46
+ ```
47
+
48
+ Each tag count includes the tests that use the tag directly, and the _effective_ tags applied from the parent suites.
49
+
32
50
  ## Details
33
51
 
34
52
  Cypress uses the resolved [configuration values](https://on.cypress.io/configuration) to find the spec files to run. It searches the `integrationFolder` for all patterns listed in `testFiles` and removes any files matching the `ignoreTestFiles` patterns.
package/bin/find.js CHANGED
@@ -4,42 +4,96 @@ const arg = require('arg')
4
4
  const { getSpecs } = require('../src')
5
5
  const fs = require('fs')
6
6
  const pluralize = require('pluralize')
7
- const { getTestNames, formatTestList } = require('find-test-names')
7
+ const { getTestNames, formatTestList, countTags } = require('find-test-names')
8
+ const consoleTable = require('console.table')
8
9
 
9
10
  const args = arg({
10
11
  '--names': Boolean,
12
+ '--tags': Boolean,
11
13
 
12
14
  // aliases
13
15
  '-n': '--names',
16
+ '--name': '--names',
17
+ '-t': '--tags',
18
+ '--tag': '--tags',
14
19
  })
15
20
 
16
21
  const specs = getSpecs()
17
- if (args['--names']) {
22
+ if (args['--names'] || args['--tags']) {
18
23
  if (!specs.length) {
19
24
  console.log('no specs found')
20
25
  } else {
21
26
  console.log('')
22
27
  let testsN = 0
28
+ let pendingTestsN = 0
29
+
30
+ // counts the number of tests for each tag across all specs
31
+ const tagTestCounts = {}
32
+
23
33
  specs.forEach((filename) => {
24
34
  const source = fs.readFileSync(filename, 'utf8')
25
35
  const result = getTestNames(source, true)
26
36
  // enable if need to debug the parsed test
27
37
  // console.dir(result.structure, { depth: null })
28
38
 
29
- testsN += result.testNames.length
39
+ testsN += result.testCount
30
40
  const testCount = pluralize('test', result.testNames.length, true)
41
+ pendingTestsN += result.pendingTestCount
31
42
 
32
- console.log('%s (%s)', filename, testCount)
33
- console.log(formatTestList(result.structure))
34
- console.log('')
43
+ if (args['--names']) {
44
+ if (result.pendingTestCount) {
45
+ console.log(
46
+ '%s (%s, %d pending)',
47
+ filename,
48
+ testCount,
49
+ result.pendingTestCount,
50
+ )
51
+ } else {
52
+ console.log('%s (%s)', filename, testCount)
53
+ }
54
+ console.log(formatTestList(result.structure))
55
+ console.log('')
56
+ }
57
+
58
+ if (args['--tags']) {
59
+ const specTagCounts = countTags(result.structure)
60
+ Object.keys(specTagCounts).forEach((tag) => {
61
+ if (!(tag in tagTestCounts)) {
62
+ tagTestCounts[tag] = specTagCounts[tag]
63
+ } else {
64
+ tagTestCounts[tag] += specTagCounts[tag]
65
+ }
66
+ })
67
+ }
35
68
  })
36
69
 
37
- console.log(
38
- 'found %s and %s',
39
- pluralize('spec', specs.length, true),
40
- pluralize('test', testsN, true),
41
- )
42
- console.log('')
70
+ if (args['--names']) {
71
+ if (pendingTestsN) {
72
+ console.log(
73
+ 'found %s (%s, %d pending)',
74
+ pluralize('spec', specs.length, true),
75
+ pluralize('test', testsN, true),
76
+ pendingTestsN,
77
+ )
78
+ } else {
79
+ console.log(
80
+ 'found %s (%s)',
81
+ pluralize('spec', specs.length, true),
82
+ pluralize('test', testsN, true),
83
+ )
84
+ }
85
+ console.log('')
86
+ }
87
+
88
+ if (args['--tags']) {
89
+ const tagEntries = Object.entries(tagTestCounts)
90
+ const sortedTagEntries = tagEntries.sort((a, b) => {
91
+ // every entry is [tag, count], so compare the tags
92
+ return a[0].localeCompare(b[0])
93
+ })
94
+ const table = consoleTable.getTable(['Tag', 'Tests'], sortedTagEntries)
95
+ console.log(table)
96
+ }
43
97
  }
44
98
  } else {
45
99
  console.log(specs.join(','))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.3.0",
3
+ "version": "1.7.0",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
@@ -15,6 +15,8 @@
15
15
  "cy:run": "DEBUG=cypress:cli,cypress:server:specs cypress run",
16
16
  "demo": "DEBUG=find-cypress-specs node ./bin/find",
17
17
  "demo-names": "node ./bin/find --names",
18
+ "demo-tags": "node ./bin/find --tags",
19
+ "demo-names-and-tags": "node ./bin/find --names --tags",
18
20
  "semantic-release": "semantic-release"
19
21
  },
20
22
  "repository": {
@@ -38,8 +40,9 @@
38
40
  },
39
41
  "dependencies": {
40
42
  "arg": "^5.0.1",
43
+ "console.table": "^0.10.0",
41
44
  "debug": "^4.3.3",
42
- "find-test-names": "^1.9.4",
45
+ "find-test-names": "^1.14.1",
43
46
  "globby": "^11.0.4",
44
47
  "minimatch": "^3.0.4",
45
48
  "pluralize": "^8.0.0"