find-cypress-specs 1.19.4 → 1.20.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 CHANGED
@@ -115,6 +115,21 @@ $ npx find-cypress-specs --names --tagged <tag1>,<tag2>,<tag3>,...
115
115
  # tagged with tag1 or tag2 or tag3 or ...
116
116
  ```
117
117
 
118
+ ## Show only the pending tests
119
+
120
+ You can show only the tests marked with "it.skip" which are called "pending" according to Mocha / Cypress [terminology](https://glebbahmutov.com/blog/cypress-test-statuses/).
121
+
122
+ ```bash
123
+ $ npx find-cypress-specs --names --pending
124
+ # --skipped is an alias to --pending
125
+ $ npx find-cypress-specs --names --skipped
126
+ # prints and counts only the pending tests
127
+ cypress/e2e/featureA/user.cy.ts (1 test, 1 pending)
128
+ └⊙ needs to be written [@alpha]
129
+
130
+ found 1 spec (1 test, 1 pending)
131
+ ```
132
+
118
133
  ## cypress.config.ts
119
134
 
120
135
  If the project uses TypeScript and `cypress.config.ts` then this module uses [ts-node/register](https://github.com/TypeStrong/ts-node) to load the config and fetch the spec pattern.
package/bin/find.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const arg = require('arg')
4
4
  const { getSpecs, collectResults, findChangedFiles } = require('../src')
5
- const { pickTaggedTestsFrom } = require('../src/tagged')
5
+ const { pickTaggedTestsFrom, leavePendingTestsOnly } = require('../src/tagged')
6
6
  const { addCounts } = require('../src/count')
7
7
  const { stringAllInfo } = require('../src/print')
8
8
 
@@ -23,6 +23,8 @@ const args = arg({
23
23
  '--count': Boolean,
24
24
  // filter all tests to those that have the given tag
25
25
  '--tagged': String,
26
+ // print only the "it.only" tests
27
+ '--skipped': Boolean,
26
28
 
27
29
  // aliases
28
30
  '-n': '--names',
@@ -31,6 +33,10 @@ const args = arg({
31
33
  '--tag': '--tags',
32
34
  '-j': '--json',
33
35
  '-b': '--branch',
36
+ // Cypress test status (just like Mocha)
37
+ // calls "it.skip" pending tests
38
+ // https://glebbahmutov.com/blog/cypress-test-statuses/
39
+ '--pending': '--skipped',
34
40
  })
35
41
 
36
42
  debug('arguments %o', args)
@@ -84,6 +90,11 @@ if (args['--names'] || args['--tags']) {
84
90
  pickTaggedTestsFrom(jsonResults, splitTags)
85
91
  // recompute the number of tests
86
92
  addCounts(jsonResults)
93
+ } else if (args['--skipped']) {
94
+ debug('leaving only skipped (pending) tests')
95
+ leavePendingTestsOnly(jsonResults)
96
+ // recompute the number of tests
97
+ addCounts(jsonResults)
87
98
  }
88
99
 
89
100
  if (args['--json']) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.19.4",
3
+ "version": "1.20.0",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
@@ -15,6 +15,7 @@
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-skipped-tests": "node ./bin/find --names --skipped",
18
19
  "demo-tags": "node ./bin/find --tags",
19
20
  "demo-tags-json": "node ./bin/find --tags --json",
20
21
  "demo-names-and-tags": "node ./bin/find --names --tags",
package/src/tagged.js CHANGED
@@ -38,6 +38,25 @@ function pickTaggedTests(tests, tag) {
38
38
  return filteredTests.length > 0
39
39
  }
40
40
 
41
+ // note: modifies the tests in place
42
+ function leavePendingTests(tests) {
43
+ if (!Array.isArray(tests)) {
44
+ return false
45
+ }
46
+ const filteredTests = tests.filter((test) => {
47
+ if (test.type === 'test') {
48
+ return test.pending === true
49
+ } else if (test.type === 'suite') {
50
+ // maybe there is some test inside this suite
51
+ // with the tag? Filter all other tests
52
+ return leavePendingTests(test.tests) || leavePendingTests(test.suites)
53
+ }
54
+ })
55
+ tests.length = 0
56
+ tests.push(...filteredTests)
57
+ return filteredTests.length > 0
58
+ }
59
+
41
60
  function removeEmptyNodes(json) {
42
61
  Object.keys(json).forEach((filename) => {
43
62
  const fileTests = json[filename].tests
@@ -64,9 +83,26 @@ function pickTaggedTestsFrom(json, tag) {
64
83
  return result
65
84
  }
66
85
 
86
+ /**
87
+ * Takes an object of tests collected from all files,
88
+ * and leaves only the pending tests.
89
+ * Modifies the given object in place.
90
+ */
91
+ function leavePendingTestsOnly(json) {
92
+ Object.keys(json).forEach((filename) => {
93
+ const fileTests = json[filename].tests
94
+ leavePendingTests(fileTests)
95
+ })
96
+
97
+ const result = removeEmptyNodes(json)
98
+ addCounts(result)
99
+ return result
100
+ }
101
+
67
102
  module.exports = {
68
103
  arraysOverlap,
69
104
  pickTaggedTestsFrom,
70
105
  removeEmptyNodes,
71
106
  pickTaggedTests,
107
+ leavePendingTestsOnly,
72
108
  }