find-cypress-specs 1.17.0 → 1.18.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 +1 -1
- package/package.json +4 -3
- package/src/index.js +74 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# find-cypress-specs [![renovate-app badge][renovate-badge]][renovate-app]  [](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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"ava": "^4.0.0",
|
|
43
|
-
"cypress": "
|
|
43
|
+
"cypress": "10.3.0",
|
|
44
44
|
"execa-wrap": "^1.4.0",
|
|
45
45
|
"prettier": "^2.5.1",
|
|
46
46
|
"really-need": "^1.9.2",
|
|
47
|
-
"semantic-release": "19.0.
|
|
47
|
+
"semantic-release": "19.0.3",
|
|
48
48
|
"sinon": "^13.0.1",
|
|
49
49
|
"typescript": "^4.6.3"
|
|
50
50
|
},
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"globby": "^11.0.4",
|
|
57
57
|
"minimatch": "^3.0.4",
|
|
58
58
|
"pluralize": "^8.0.0",
|
|
59
|
+
"require-and-forget": "^1.0.0",
|
|
59
60
|
"shelljs": "^0.8.5"
|
|
60
61
|
}
|
|
61
62
|
}
|
package/src/index.js
CHANGED
|
@@ -5,13 +5,14 @@ const globby = require('globby')
|
|
|
5
5
|
const minimatch = require('minimatch')
|
|
6
6
|
const shell = require('shelljs')
|
|
7
7
|
const pluralize = require('pluralize')
|
|
8
|
+
const requireEveryTime = require('require-and-forget')
|
|
8
9
|
|
|
9
10
|
const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Reads the
|
|
13
|
+
* Reads the Cypress config JSON file (Cypress v9) and returns the relevant properties
|
|
13
14
|
*/
|
|
14
|
-
function
|
|
15
|
+
function getConfigJson(filename = 'cypress.json') {
|
|
15
16
|
const s = fs.readFileSync(filename, 'utf8')
|
|
16
17
|
const config = JSON.parse(s)
|
|
17
18
|
const options = {
|
|
@@ -23,7 +24,21 @@ function getConfig(filename = 'cypress.json') {
|
|
|
23
24
|
return options
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
function
|
|
27
|
+
function getConfigJs(filename) {
|
|
28
|
+
const jsFile = path.join(process.cwd(), filename)
|
|
29
|
+
debug('loading Cypress config from %s', jsFile)
|
|
30
|
+
const definedConfig = requireEveryTime(jsFile)
|
|
31
|
+
return definedConfig
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getConfig(filename = './cypress.config.js') {
|
|
35
|
+
if (filename.endsWith('.json')) {
|
|
36
|
+
return getConfigJson(filename)
|
|
37
|
+
}
|
|
38
|
+
return getConfigJs(filename)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function findCypressSpecsV9(opts = {}) {
|
|
27
42
|
const defaults = {
|
|
28
43
|
integrationFolder: 'cypress/integration',
|
|
29
44
|
testFiles: '**/*.{js,ts}',
|
|
@@ -68,9 +83,64 @@ function findCypressSpecs(opts = {}) {
|
|
|
68
83
|
return filtered.map((file) => path.join(options.integrationFolder, file))
|
|
69
84
|
}
|
|
70
85
|
|
|
86
|
+
function findCypressSpecsV10(opts = {}) {
|
|
87
|
+
if (!('e2e' in opts)) {
|
|
88
|
+
throw new Error('Missing e2e in the config object')
|
|
89
|
+
}
|
|
90
|
+
const defaults = {
|
|
91
|
+
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
|
|
92
|
+
excludeSpecPattern: [],
|
|
93
|
+
}
|
|
94
|
+
const options = {
|
|
95
|
+
specPattern: opts.e2e.specPattern || defaults.specPattern,
|
|
96
|
+
excludeSpecPattern:
|
|
97
|
+
opts.e2e.excludeSpecPattern || defaults.excludeSpecPattern,
|
|
98
|
+
}
|
|
99
|
+
debug('options v10 %o', options)
|
|
100
|
+
|
|
101
|
+
const files = globby.sync(options.specPattern, {
|
|
102
|
+
sort: true,
|
|
103
|
+
ignore: options.excludeSpecPattern,
|
|
104
|
+
})
|
|
105
|
+
debug('found %d file(s) %o', files.length, files)
|
|
106
|
+
|
|
107
|
+
// go through the files again and eliminate files that match
|
|
108
|
+
// the ignore patterns
|
|
109
|
+
const ignorePatterns = [].concat(options.excludeSpecPattern)
|
|
110
|
+
debug('ignore patterns %o', ignorePatterns)
|
|
111
|
+
|
|
112
|
+
// a function which returns true if the file does NOT match
|
|
113
|
+
// all of our ignored patterns
|
|
114
|
+
const doesNotMatchAllIgnoredPatterns = (file) => {
|
|
115
|
+
// using {dot: true} here so that folders with a '.' in them are matched
|
|
116
|
+
// as regular characters without needing an '.' in the
|
|
117
|
+
// using {matchBase: true} here so that patterns without a globstar **
|
|
118
|
+
// match against the basename of the file
|
|
119
|
+
const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
|
|
120
|
+
return ignorePatterns.every((pattern) => {
|
|
121
|
+
return !minimatch(file, pattern, MINIMATCH_OPTIONS)
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const filtered = files.filter(doesNotMatchAllIgnoredPatterns)
|
|
126
|
+
debug('filtered %d specs', filtered.length)
|
|
127
|
+
debug(filtered.join('\n'))
|
|
128
|
+
|
|
129
|
+
return filtered
|
|
130
|
+
}
|
|
131
|
+
|
|
71
132
|
function getSpecs() {
|
|
72
133
|
const options = getConfig()
|
|
73
|
-
|
|
134
|
+
return findCypressSpecs(options)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function findCypressSpecs(options) {
|
|
138
|
+
if (options.e2e) {
|
|
139
|
+
const specs = findCypressSpecsV10(options)
|
|
140
|
+
return specs
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const specs = findCypressSpecsV9(options)
|
|
74
144
|
return specs
|
|
75
145
|
}
|
|
76
146
|
|