find-cypress-specs 1.0.1 → 1.1.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
@@ -8,11 +8,32 @@ $ npx find-cypress-specs
8
8
  cypress/e2e/spec.js,cypress/e2e/featureA/user.js
9
9
  ```
10
10
 
11
+ ## Test names
12
+
13
+ You can print each spec file with the suite and test names inside of it (found using [find-test-names](https://github.com/bahmutov/find-test-names))
14
+
15
+ ```bash
16
+ $ npx find-cypress-specs --names
17
+ # prints something like
18
+
19
+ cypress/e2e/spec.js
20
+ └─ parent suite [@main]
21
+ ├─ works
22
+ └─ inner suite
23
+ └─ shows something [@user]
24
+
25
+ cypress/e2e/featureA/user.js
26
+ ├─ works
27
+ └⊙ needs to be written
28
+ ```
29
+
30
+ 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
+
11
32
  ## Details
12
33
 
13
34
  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.
14
35
 
15
- You can see how Cypress finds the specs using `DEBUG=cypress:cli,cypress:server:specs` environment variable to see verbose logs.
36
+ You can see how Cypress finds the specs using `DEBUG=cypress:cli,cypress:server:specs` environment variable to see verbose logs. The logic should be in the file `packages/server/lib/util/specs.ts` in the repo [cypress-io/cypress](https://github.com/cypress-io/cypress)
16
37
 
17
38
  ## Debugging
18
39
 
package/bin/find.js CHANGED
@@ -1,6 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const arg = require('arg')
3
4
  const { getSpecs } = require('../src')
5
+ const fs = require('fs')
6
+ const { getTestNames, formatTestList } = require('find-test-names')
7
+
8
+ const args = arg({
9
+ '--names': Boolean,
10
+
11
+ // aliases
12
+ '-n': '--names',
13
+ })
4
14
 
5
15
  const specs = getSpecs()
6
- console.log(specs.join(','))
16
+ if (args['--names']) {
17
+ specs.forEach((filename) => {
18
+ const source = fs.readFileSync(filename, 'utf8')
19
+ const result = getTestNames(source, true)
20
+ // enable if need to debug the parsed test
21
+ // console.dir(result.structure, { depth: null })
22
+ console.log(filename)
23
+ console.log(formatTestList(result.structure))
24
+ console.log('')
25
+ })
26
+ } else {
27
+ console.log(specs.join(','))
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
@@ -14,6 +14,7 @@
14
14
  "test": "ava",
15
15
  "cy:run": "DEBUG=cypress:cli,cypress:server:specs cypress run",
16
16
  "demo": "DEBUG=find-cypress-specs node ./bin/find",
17
+ "demo-names": "node ./bin/find --names",
17
18
  "semantic-release": "semantic-release"
18
19
  },
19
20
  "repository": {
@@ -36,7 +37,10 @@
36
37
  "semantic-release": "^18.0.1"
37
38
  },
38
39
  "dependencies": {
40
+ "arg": "^5.0.1",
39
41
  "debug": "^4.3.3",
40
- "globby": "^11.0.4"
42
+ "find-test-names": "^1.9.2",
43
+ "globby": "^11.0.4",
44
+ "minimatch": "^3.0.4"
41
45
  }
42
46
  }
package/src/index.js CHANGED
@@ -2,6 +2,9 @@ const debug = require('debug')('find-cypress-specs')
2
2
  const fs = require('fs')
3
3
  const path = require('path')
4
4
  const globby = require('globby')
5
+ const minimatch = require('minimatch')
6
+
7
+ const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
5
8
 
6
9
  /**
7
10
  * Reads the cypress config file and returns the relevant properties
@@ -32,13 +35,35 @@ function findCypressSpecs(opts = {}) {
32
35
  debug('options %o', options)
33
36
 
34
37
  const files = globby.sync(options.testFiles, {
38
+ sort: true,
35
39
  cwd: options.integrationFolder,
36
40
  ignore: options.ignoreTestFiles,
37
41
  })
38
42
  debug('found %d file(s) %o', files.length, files)
39
43
 
44
+ // go through the files again and eliminate files that match
45
+ // the ignore patterns
46
+ const ignorePatterns = [].concat(options.ignoreTestFiles)
47
+ debug('ignore patterns %o', ignorePatterns)
48
+
49
+ // a function which returns true if the file does NOT match
50
+ // all of our ignored patterns
51
+ const doesNotMatchAllIgnoredPatterns = (file) => {
52
+ // using {dot: true} here so that folders with a '.' in them are matched
53
+ // as regular characters without needing an '.' in the
54
+ // using {matchBase: true} here so that patterns without a globstar **
55
+ // match against the basename of the file
56
+ return ignorePatterns.every((pattern) => {
57
+ return !minimatch(file, pattern, MINIMATCH_OPTIONS)
58
+ })
59
+ }
60
+
61
+ const filtered = files.filter(doesNotMatchAllIgnoredPatterns)
62
+ debug('filtered %d specs', filtered.length)
63
+ debug(filtered.join('\n'))
64
+
40
65
  // return spec files with the added integration folder prefix
41
- return files.map((file) => path.join(options.integrationFolder, file))
66
+ return filtered.map((file) => path.join(options.integrationFolder, file))
42
67
  }
43
68
 
44
69
  function getSpecs() {