find-cypress-specs 1.0.0 → 1.0.4
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 +9 -1
- package/package.json +3 -2
- package/src/index.js +29 -3
package/README.md
CHANGED
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
> Find Cypress spec files using the config settings
|
|
4
4
|
|
|
5
|
+
```bash
|
|
6
|
+
$ npx find-cypress-specs
|
|
7
|
+
# prints all spec files separated by a comma
|
|
8
|
+
cypress/e2e/spec.js,cypress/e2e/featureA/user.js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Details
|
|
12
|
+
|
|
5
13
|
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.
|
|
6
14
|
|
|
7
|
-
You can see how Cypress finds the specs using `DEBUG=cypress:cli,cypress:server:specs` environment variable to see verbose logs.
|
|
15
|
+
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)
|
|
8
16
|
|
|
9
17
|
## Debugging
|
|
10
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"debug": "^4.3.3",
|
|
40
|
-
"globby": "^11.0.4"
|
|
40
|
+
"globby": "^11.0.4",
|
|
41
|
+
"minimatch": "^3.0.4"
|
|
41
42
|
}
|
|
42
43
|
}
|
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
|
|
@@ -25,19 +28,42 @@ function findCypressSpecs(opts = {}) {
|
|
|
25
28
|
ignoreTestFiles: [],
|
|
26
29
|
}
|
|
27
30
|
const options = {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
integrationFolder: opts.integrationFolder || defaults.integrationFolder,
|
|
32
|
+
testFiles: opts.testFiles || defaults.testFiles,
|
|
33
|
+
ignoreTestFiles: opts.ignoreTestFiles || defaults.ignoreTestFiles,
|
|
30
34
|
}
|
|
31
35
|
debug('options %o', options)
|
|
32
36
|
|
|
33
37
|
const files = globby.sync(options.testFiles, {
|
|
38
|
+
sort: true,
|
|
34
39
|
cwd: options.integrationFolder,
|
|
35
40
|
ignore: options.ignoreTestFiles,
|
|
36
41
|
})
|
|
37
42
|
debug('found %d file(s) %o', files.length, files)
|
|
38
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
|
+
|
|
39
65
|
// return spec files with the added integration folder prefix
|
|
40
|
-
return
|
|
66
|
+
return filtered.map((file) => path.join(options.integrationFolder, file))
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
function getSpecs() {
|