find-cypress-specs 1.4.0 → 1.8.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 +20 -0
  2. package/bin/find.js +79 -26
  3. package/package.json +6 -2
package/README.md CHANGED
@@ -31,6 +31,22 @@ found 2 specs (4 tests, 1 pending)
31
31
 
32
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.
33
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
+
34
50
  ## Details
35
51
 
36
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.
@@ -41,6 +57,10 @@ You can see how Cypress finds the specs using `DEBUG=cypress:cli,cypress:server:
41
57
 
42
58
  Run the utility with environment variable `DEBUG=find-cypress-specs` to see the verbose logs
43
59
 
60
+ ## Videos
61
+
62
+ - [Use Ava Snapshots And Execa-wrap To Write End-to-End Tests For CLI Utilities](https://youtu.be/rsw17RqP0G0)
63
+
44
64
  ## Small print
45
65
 
46
66
  Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
package/bin/find.js CHANGED
@@ -4,24 +4,38 @@ 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,
13
+ '--json': Boolean,
11
14
 
12
15
  // aliases
13
16
  '-n': '--names',
17
+ '--name': '--names',
18
+ '-t': '--tags',
19
+ '--tag': '--tags',
20
+ '-j': '--json',
14
21
  })
15
22
 
16
23
  const specs = getSpecs()
17
- if (args['--names']) {
24
+ if (args['--names'] || args['--tags']) {
18
25
  if (!specs.length) {
19
26
  console.log('no specs found')
20
27
  } else {
21
28
  console.log('')
22
29
  let testsN = 0
23
30
  let pendingTestsN = 0
31
+
32
+ // counts the number of tests for each tag across all specs
33
+ const tagTestCounts = {}
34
+
35
+ const jsonResults = {}
36
+
24
37
  specs.forEach((filename) => {
38
+ jsonResults[filename] = []
25
39
  const source = fs.readFileSync(filename, 'utf8')
26
40
  const result = getTestNames(source, true)
27
41
  // enable if need to debug the parsed test
@@ -31,35 +45,74 @@ if (args['--names']) {
31
45
  const testCount = pluralize('test', result.testNames.length, true)
32
46
  pendingTestsN += result.pendingTestCount
33
47
 
34
- if (result.pendingTestCount) {
35
- console.log(
36
- '%s (%s, %d pending)',
37
- filename,
38
- testCount,
39
- result.pendingTestCount,
40
- )
48
+ if (args['--names']) {
49
+ if (args['--json']) {
50
+ result.structure.forEach((t) => {
51
+ if (t.type === 'test') {
52
+ jsonResults[filename].push(t.name)
53
+ } else if (t.type === 'suite') {
54
+ jsonResults[filename].push(t.name)
55
+ }
56
+ })
57
+ } else {
58
+ if (result.pendingTestCount) {
59
+ console.log(
60
+ '%s (%s, %d pending)',
61
+ filename,
62
+ testCount,
63
+ result.pendingTestCount,
64
+ )
65
+ } else {
66
+ console.log('%s (%s)', filename, testCount)
67
+ }
68
+ console.log(formatTestList(result.structure))
69
+ console.log('')
70
+ }
71
+ }
72
+
73
+ if (args['--tags']) {
74
+ const specTagCounts = countTags(result.structure)
75
+ Object.keys(specTagCounts).forEach((tag) => {
76
+ if (!(tag in tagTestCounts)) {
77
+ tagTestCounts[tag] = specTagCounts[tag]
78
+ } else {
79
+ tagTestCounts[tag] += specTagCounts[tag]
80
+ }
81
+ })
82
+ }
83
+ })
84
+
85
+ if (args['--names']) {
86
+ if (args['--json']) {
87
+ console.log(JSON.stringify(jsonResults, null, 2))
41
88
  } else {
42
- console.log('%s (%s)', filename, testCount)
89
+ if (pendingTestsN) {
90
+ console.log(
91
+ 'found %s (%s, %d pending)',
92
+ pluralize('spec', specs.length, true),
93
+ pluralize('test', testsN, true),
94
+ pendingTestsN,
95
+ )
96
+ } else {
97
+ console.log(
98
+ 'found %s (%s)',
99
+ pluralize('spec', specs.length, true),
100
+ pluralize('test', testsN, true),
101
+ )
102
+ }
43
103
  }
44
- console.log(formatTestList(result.structure))
45
104
  console.log('')
46
- })
105
+ }
47
106
 
48
- if (pendingTestsN) {
49
- console.log(
50
- 'found %s (%s, %d pending)',
51
- pluralize('spec', specs.length, true),
52
- pluralize('test', testsN, true),
53
- pendingTestsN,
54
- )
55
- } else {
56
- console.log(
57
- 'found %s (%s)',
58
- pluralize('spec', specs.length, true),
59
- pluralize('test', testsN, true),
60
- )
107
+ if (args['--tags']) {
108
+ const tagEntries = Object.entries(tagTestCounts)
109
+ const sortedTagEntries = tagEntries.sort((a, b) => {
110
+ // every entry is [tag, count], so compare the tags
111
+ return a[0].localeCompare(b[0])
112
+ })
113
+ const table = consoleTable.getTable(['Tag', 'Tests'], sortedTagEntries)
114
+ console.log(table)
61
115
  }
62
- console.log('')
63
116
  }
64
117
  } else {
65
118
  console.log(specs.join(','))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.4.0",
3
+ "version": "1.8.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": {
@@ -33,13 +35,15 @@
33
35
  "devDependencies": {
34
36
  "ava": "^4.0.0",
35
37
  "cypress": "^9.2.0",
38
+ "execa-wrap": "^1.4.0",
36
39
  "prettier": "^2.5.1",
37
40
  "semantic-release": "^18.0.1"
38
41
  },
39
42
  "dependencies": {
40
43
  "arg": "^5.0.1",
44
+ "console.table": "^0.10.0",
41
45
  "debug": "^4.3.3",
42
- "find-test-names": "^1.12.1",
46
+ "find-test-names": "^1.14.1",
43
47
  "globby": "^11.0.4",
44
48
  "minimatch": "^3.0.4",
45
49
  "pluralize": "^8.0.0"