find-cypress-specs 1.17.0 → 1.19.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 +7 -1
- package/package.json +6 -4
- package/src/index.js +94 -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
|
|
|
@@ -115,6 +115,12 @@ $ npx find-cypress-specs --names --tagged <tag1>,<tag2>,<tag3>,...
|
|
|
115
115
|
# tagged with tag1 or tag2 or tag3 or ...
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
+
## cypress.config.ts
|
|
119
|
+
|
|
120
|
+
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.
|
|
121
|
+
|
|
122
|
+
**Tip:** read my blog post [Convert Cypress Specs from JavaScript to TypeScript](https://glebbahmutov.com/blog/cypress-js-to-ts/).
|
|
123
|
+
|
|
118
124
|
## Details
|
|
119
125
|
|
|
120
126
|
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.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.8.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.5",
|
|
48
48
|
"sinon": "^13.0.1",
|
|
49
49
|
"typescript": "^4.6.3"
|
|
50
50
|
},
|
|
@@ -56,6 +56,8 @@
|
|
|
56
56
|
"globby": "^11.0.4",
|
|
57
57
|
"minimatch": "^3.0.4",
|
|
58
58
|
"pluralize": "^8.0.0",
|
|
59
|
-
"
|
|
59
|
+
"require-and-forget": "^1.0.0",
|
|
60
|
+
"shelljs": "^0.8.5",
|
|
61
|
+
"ts-node": "^10.9.1"
|
|
60
62
|
}
|
|
61
63
|
}
|
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,41 @@ 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 getConfigTs(filename) {
|
|
35
|
+
require('ts-node/register')
|
|
36
|
+
const jsFile = path.join(process.cwd(), filename)
|
|
37
|
+
debug('loading Cypress config from %s', jsFile)
|
|
38
|
+
const definedConfig = requireEveryTime(jsFile)
|
|
39
|
+
return definedConfig
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getConfig() {
|
|
43
|
+
if (fs.existsSync('./cypress.config.js')) {
|
|
44
|
+
debug('found file cypress.config.js')
|
|
45
|
+
return getConfigJs('./cypress.config.js')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (fs.existsSync('./cypress.config.ts')) {
|
|
49
|
+
debug('found file cypress.config.ts')
|
|
50
|
+
return getConfigTs('./cypress.config.ts')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (fs.existsSync('./cypress.json')) {
|
|
54
|
+
debug('found file cypress.json')
|
|
55
|
+
return getConfigJson('./cypress.config.js')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw new Error('Do not know how to find and load Cypress config file')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function findCypressSpecsV9(opts = {}) {
|
|
27
62
|
const defaults = {
|
|
28
63
|
integrationFolder: 'cypress/integration',
|
|
29
64
|
testFiles: '**/*.{js,ts}',
|
|
@@ -68,9 +103,64 @@ function findCypressSpecs(opts = {}) {
|
|
|
68
103
|
return filtered.map((file) => path.join(options.integrationFolder, file))
|
|
69
104
|
}
|
|
70
105
|
|
|
106
|
+
function findCypressSpecsV10(opts = {}) {
|
|
107
|
+
if (!('e2e' in opts)) {
|
|
108
|
+
throw new Error('Missing e2e in the config object')
|
|
109
|
+
}
|
|
110
|
+
const defaults = {
|
|
111
|
+
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
|
|
112
|
+
excludeSpecPattern: [],
|
|
113
|
+
}
|
|
114
|
+
const options = {
|
|
115
|
+
specPattern: opts.e2e.specPattern || defaults.specPattern,
|
|
116
|
+
excludeSpecPattern:
|
|
117
|
+
opts.e2e.excludeSpecPattern || defaults.excludeSpecPattern,
|
|
118
|
+
}
|
|
119
|
+
debug('options v10 %o', options)
|
|
120
|
+
|
|
121
|
+
const files = globby.sync(options.specPattern, {
|
|
122
|
+
sort: true,
|
|
123
|
+
ignore: options.excludeSpecPattern,
|
|
124
|
+
})
|
|
125
|
+
debug('found %d file(s) %o', files.length, files)
|
|
126
|
+
|
|
127
|
+
// go through the files again and eliminate files that match
|
|
128
|
+
// the ignore patterns
|
|
129
|
+
const ignorePatterns = [].concat(options.excludeSpecPattern)
|
|
130
|
+
debug('ignore patterns %o', ignorePatterns)
|
|
131
|
+
|
|
132
|
+
// a function which returns true if the file does NOT match
|
|
133
|
+
// all of our ignored patterns
|
|
134
|
+
const doesNotMatchAllIgnoredPatterns = (file) => {
|
|
135
|
+
// using {dot: true} here so that folders with a '.' in them are matched
|
|
136
|
+
// as regular characters without needing an '.' in the
|
|
137
|
+
// using {matchBase: true} here so that patterns without a globstar **
|
|
138
|
+
// match against the basename of the file
|
|
139
|
+
const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
|
|
140
|
+
return ignorePatterns.every((pattern) => {
|
|
141
|
+
return !minimatch(file, pattern, MINIMATCH_OPTIONS)
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const filtered = files.filter(doesNotMatchAllIgnoredPatterns)
|
|
146
|
+
debug('filtered %d specs', filtered.length)
|
|
147
|
+
debug(filtered.join('\n'))
|
|
148
|
+
|
|
149
|
+
return filtered
|
|
150
|
+
}
|
|
151
|
+
|
|
71
152
|
function getSpecs() {
|
|
72
153
|
const options = getConfig()
|
|
73
|
-
|
|
154
|
+
return findCypressSpecs(options)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function findCypressSpecs(options) {
|
|
158
|
+
if (options.e2e) {
|
|
159
|
+
const specs = findCypressSpecsV10(options)
|
|
160
|
+
return specs
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const specs = findCypressSpecsV9(options)
|
|
74
164
|
return specs
|
|
75
165
|
}
|
|
76
166
|
|