find-cypress-specs 1.43.5 → 1.44.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
@@ -1,4 +1,4 @@
1
- # find-cypress-specs [![renovate-app badge][renovate-badge]][renovate-app] ![cypress version](https://img.shields.io/badge/cypress-13.11.0-brightgreen) [![ci](https://github.com/bahmutov/find-cypress-specs/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bahmutov/find-cypress-specs/actions/workflows/ci.yml)
1
+ # find-cypress-specs [![renovate-app badge][renovate-badge]][renovate-app] ![cypress version](https://img.shields.io/badge/cypress-13.13.0-brightgreen) [![ci](https://github.com/bahmutov/find-cypress-specs/actions/workflows/ci.yml/badge.svg?branch=main)](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
 
@@ -38,6 +38,16 @@ $ npx find-cypress-specs --branch main
38
38
  # prints only some specs, the ones that have changed against the "origin/main"
39
39
  ```
40
40
 
41
+ ## find specs by part of the test title
42
+
43
+ You can grep all test titles (only the test titles, not the suite names) and find the list of specs
44
+
45
+ ```bash
46
+ $ npx find-cypress-specs --grep "works, needs"
47
+ ```
48
+
49
+ This will find all specs with tests that have "works" in the title or "needs" in the title and output the list of specs. If you use `--set-gha-outputs` and GitHub Actions, it sets the outputs `grepSpecs` and `grepSpecsN`.
50
+
41
51
  ## find number of machines
42
52
 
43
53
  If we find all the changed specs to run, we might need to decide how many machines we need. We can do a rough job by specifying the number of specs per machine plus the max number.
package/bin/find.js CHANGED
@@ -5,6 +5,7 @@ const { getSpecs, findChangedFiles, getTests } = require('../src')
5
5
  const { getTestCounts } = require('../src/tests-counts')
6
6
  const { stringAllInfo, stringMarkdownTests } = require('../src/print')
7
7
  const { updateBadge } = require('../src/badge')
8
+ const { filterByGrep } = require('../src/grep')
8
9
 
9
10
  const fs = require('fs')
10
11
  const path = require('path')
@@ -56,6 +57,8 @@ const args = arg({
56
57
  // optional: output the number of machines needed to run the tests
57
58
  '--specs-per-machine': Number,
58
59
  '--max-machines': Number,
60
+ // find all specs and tests with part of the title
61
+ '--grep': String,
59
62
  //
60
63
  // aliases
61
64
  '-n': '--names',
@@ -328,6 +331,26 @@ if (args['--test-counts']) {
328
331
  }
329
332
  }
330
333
  }
334
+ } else if (args['--grep']) {
335
+ const grep = args['--grep']
336
+ // grep is a comma-separated string with parts of titles to find
337
+ debug('finding tests with title containing "%s"', grep)
338
+ const { jsonResults } = getTests(specs)
339
+ const filtered = filterByGrep(jsonResults, grep)
340
+ debug(filtered)
341
+ console.log(filtered.join(','))
342
+ if (args['--set-gha-outputs']) {
343
+ debug('printing the spec names list only')
344
+ const specNames = filtered.join(',')
345
+ console.log(specNames)
346
+
347
+ debug(
348
+ 'setting GitHub Actions outputs grepSpecsN to %d and grepSpecs',
349
+ specNames.length,
350
+ )
351
+ core.setOutput('grepSpecsN', filtered.length)
352
+ core.setOutput('grepSpecs', specNames)
353
+ }
331
354
  } else {
332
355
  if (args['--count']) {
333
356
  debug('printing the number of specs %d', specs.length)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.43.5",
3
+ "version": "1.44.0",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
@@ -58,7 +58,7 @@
58
58
  "homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
59
59
  "devDependencies": {
60
60
  "ava": "^4.0.0",
61
- "cypress": "13.11.0",
61
+ "cypress": "13.13.0",
62
62
  "dependency-version-badge": "^1.11.0",
63
63
  "execa-wrap": "^1.4.0",
64
64
  "prettier": "^2.5.1",
@@ -72,7 +72,7 @@
72
72
  "arg": "^5.0.1",
73
73
  "console.table": "^0.10.0",
74
74
  "debug": "^4.3.3",
75
- "find-test-names": "1.28.21",
75
+ "find-test-names": "1.28.22",
76
76
  "globby": "^11.1.0",
77
77
  "minimatch": "^3.0.4",
78
78
  "pluralize": "^8.0.0",
package/src/grep.js ADDED
@@ -0,0 +1,56 @@
1
+ const debug = require('debug')('find-cypress-specs')
2
+
3
+ /**
4
+ * Recursively checks the tests structure to see
5
+ * if any of the leaf test objects have a name that includes
6
+ * any of the given strings
7
+ */
8
+ function checkIncludesTestTitle(tests, greps) {
9
+ if (!tests) {
10
+ return false
11
+ }
12
+ debug('greps', greps)
13
+ return tests.some((test) => {
14
+ if (test.type === 'test' && test.name) {
15
+ debug('checking test "%s"', test.name)
16
+ return greps.some((grep) => test.name.includes(grep))
17
+ } else if (test.type === 'suite') {
18
+ debug('checking suite "%s"', test.name)
19
+ return (
20
+ checkIncludesTestTitle(test.tests, greps) ||
21
+ checkIncludesTestTitle(test.suites, greps)
22
+ )
23
+ } else if (Array.isArray(test.tests)) {
24
+ return checkIncludesTestTitle(test.tests, greps)
25
+ } else if (Array.isArray(test.suites)) {
26
+ return checkIncludesTestTitle(test.suites, greps)
27
+ }
28
+ })
29
+ }
30
+
31
+ /**
32
+ * returns a list of specs where any test title contains the given string.
33
+ * Leaves the original structure intact.
34
+ * @param {object} jsonResults - parsed JSON spec file structure
35
+ * @param {string} grep - comma-separated list of strings to filter by
36
+ * @returns {string[]} - list of spec filenames
37
+ */
38
+ function filterByGrep(jsonResults, grep) {
39
+ const result = []
40
+ const greps = grep
41
+ .split(',')
42
+ .map((s) => s.trim())
43
+ .filter(Boolean)
44
+
45
+ Object.keys(jsonResults).forEach((specFilename) => {
46
+ debug('checking spec "%s"', specFilename)
47
+ const spec = jsonResults[specFilename]
48
+ if (checkIncludesTestTitle(spec.tests, greps)) {
49
+ result.push(specFilename)
50
+ }
51
+ })
52
+
53
+ return result
54
+ }
55
+
56
+ module.exports = { filterByGrep }