find-cypress-specs 1.26.0 → 1.27.1
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 +8 -0
- package/bin/find.js +5 -1
- package/package.json +3 -2
- package/src/index.js +70 -18
package/README.md
CHANGED
|
@@ -10,6 +10,14 @@ cypress/e2e/spec.js,cypress/e2e/featureA/user.js
|
|
|
10
10
|
|
|
11
11
|
Supports JS and TS specs
|
|
12
12
|
|
|
13
|
+
## Component specs
|
|
14
|
+
|
|
15
|
+
By default, it finds the E2E specs and tests. You can find component specs using `--component` CLI option
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ npx find-cypress-specs --component
|
|
19
|
+
```
|
|
20
|
+
|
|
13
21
|
## against branch
|
|
14
22
|
|
|
15
23
|
By default, this module simply prints all spec filenames. You can add `--branch` parameter to only print the specs changed against that `origin/branch`.
|
package/bin/find.js
CHANGED
|
@@ -40,6 +40,8 @@ const args = arg({
|
|
|
40
40
|
'--time-trace': Boolean,
|
|
41
41
|
// do not add more than this number of extra specs after tracing
|
|
42
42
|
'--max-added-traced-specs': Number,
|
|
43
|
+
// find component specs
|
|
44
|
+
'--component': Boolean,
|
|
43
45
|
// aliases
|
|
44
46
|
'-n': '--names',
|
|
45
47
|
'--name': '--names',
|
|
@@ -55,8 +57,10 @@ const args = arg({
|
|
|
55
57
|
})
|
|
56
58
|
|
|
57
59
|
debug('arguments %o', args)
|
|
60
|
+
const specType = args['--component'] ? 'component' : 'e2e'
|
|
61
|
+
|
|
62
|
+
const specs = getSpecs(undefined, specType)
|
|
58
63
|
|
|
59
|
-
const specs = getSpecs()
|
|
60
64
|
if (args['--names'] || args['--tags']) {
|
|
61
65
|
// counts the number of tests for each tag across all specs
|
|
62
66
|
const { jsonResults, tagTestCounts } = getTests(specs, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cypress-specs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.1",
|
|
4
4
|
"description": "Find Cypress spec files using the config settings",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"files": [
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"count-changed-specs": "node ./bin/find --branch main --count",
|
|
28
28
|
"semantic-release": "semantic-release",
|
|
29
29
|
"deps": "spec-change --folder . --mask 'cypress/**/*.{js,ts}'",
|
|
30
|
-
"deps-changed": "DEBUG=find-cypress-specs node ./bin/find --branch main --parent --trace-imports cypress --time-trace --cache-trace"
|
|
30
|
+
"deps-changed": "DEBUG=find-cypress-specs node ./bin/find --branch main --parent --trace-imports cypress --time-trace --cache-trace",
|
|
31
|
+
"demo-component": "DEBUG=find-cypress-specs node ./bin/find --component --names"
|
|
31
32
|
},
|
|
32
33
|
"repository": {
|
|
33
34
|
"type": "git",
|
package/src/index.js
CHANGED
|
@@ -113,19 +113,36 @@ function findCypressSpecsV9(opts = {}) {
|
|
|
113
113
|
return filtered.map((file) => path.join(options.integrationFolder, file))
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
function findCypressSpecsV10(opts = {}) {
|
|
117
|
-
if (
|
|
118
|
-
throw new Error(
|
|
116
|
+
function findCypressSpecsV10(opts = {}, type = 'e2e') {
|
|
117
|
+
if (type !== 'e2e' && type !== 'component') {
|
|
118
|
+
throw new Error(`Unknown spec type ${type}`)
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
|
|
121
|
+
if (!(type in opts)) {
|
|
122
|
+
throw new Error(`Missing "${type}" object in the Cypress config object`)
|
|
123
|
+
}
|
|
124
|
+
const e2eDefaults = {
|
|
121
125
|
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
|
|
122
126
|
excludeSpecPattern: [],
|
|
123
127
|
}
|
|
124
|
-
const
|
|
125
|
-
specPattern:
|
|
126
|
-
excludeSpecPattern:
|
|
127
|
-
|
|
128
|
+
const componentDefaults = {
|
|
129
|
+
specPattern: '**/*.cy.{js,jsx,ts,tsx}',
|
|
130
|
+
excludeSpecPattern: ['/snapshots/*', '/image_snapshots/*'],
|
|
131
|
+
}
|
|
132
|
+
// https://on.cypress.io/configuration
|
|
133
|
+
const options = {}
|
|
134
|
+
|
|
135
|
+
if (type === 'e2e') {
|
|
136
|
+
options.specPattern = opts.e2e.specPattern || e2eDefaults.specPattern
|
|
137
|
+
options.excludeSpecPattern =
|
|
138
|
+
opts.e2e.excludeSpecPattern || e2eDefaults.excludeSpecPattern
|
|
139
|
+
} else if (type === 'component') {
|
|
140
|
+
options.specPattern =
|
|
141
|
+
opts.component.specPattern || componentDefaults.specPattern
|
|
142
|
+
options.excludeSpecPattern =
|
|
143
|
+
opts.component.excludeSpecPattern || componentDefaults.excludeSpecPattern
|
|
128
144
|
}
|
|
145
|
+
|
|
129
146
|
debug('options v10 %o', options)
|
|
130
147
|
|
|
131
148
|
const files = globby.sync(options.specPattern, {
|
|
@@ -137,6 +154,13 @@ function findCypressSpecsV10(opts = {}) {
|
|
|
137
154
|
// go through the files again and eliminate files that match
|
|
138
155
|
// the ignore patterns
|
|
139
156
|
const ignorePatterns = [].concat(options.excludeSpecPattern)
|
|
157
|
+
|
|
158
|
+
// when using component spec pattern, ignore all E2E specs
|
|
159
|
+
if (type === 'component') {
|
|
160
|
+
const e2eIgnorePattern = options.e2e?.specPattern || e2eDefaults.specPattern
|
|
161
|
+
ignorePatterns.push(e2eIgnorePattern)
|
|
162
|
+
}
|
|
163
|
+
|
|
140
164
|
debug('ignore patterns %o', ignorePatterns)
|
|
141
165
|
|
|
142
166
|
// a function which returns true if the file does NOT match
|
|
@@ -159,23 +183,51 @@ function findCypressSpecsV10(opts = {}) {
|
|
|
159
183
|
return filtered
|
|
160
184
|
}
|
|
161
185
|
|
|
162
|
-
function getSpecs(options) {
|
|
186
|
+
function getSpecs(options, type) {
|
|
163
187
|
if (typeof options === 'undefined') {
|
|
164
188
|
options = getConfig()
|
|
189
|
+
if (typeof type === 'undefined') {
|
|
190
|
+
type = 'e2e'
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
// we might have resolved config object
|
|
194
|
+
// passed from the "setupNode..." callback
|
|
195
|
+
if ('testingType' in options) {
|
|
196
|
+
type = options.testingType
|
|
197
|
+
options = {
|
|
198
|
+
[type]: {
|
|
199
|
+
specPattern: options.specPattern,
|
|
200
|
+
excludeSpecPattern: options.excludeSpecPattern,
|
|
201
|
+
},
|
|
202
|
+
}
|
|
203
|
+
}
|
|
165
204
|
}
|
|
166
|
-
|
|
205
|
+
|
|
206
|
+
return findCypressSpecs(options, type)
|
|
167
207
|
}
|
|
168
208
|
|
|
169
|
-
function findCypressSpecs(options) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
209
|
+
function findCypressSpecs(options, type = 'e2e') {
|
|
210
|
+
debug('finding specs of type %s', type)
|
|
211
|
+
|
|
212
|
+
if (type === 'e2e') {
|
|
213
|
+
if (options.e2e) {
|
|
214
|
+
debug('config has "e2e" property, treating as Cypress v10+')
|
|
215
|
+
const specs = findCypressSpecsV10(options, type)
|
|
216
|
+
return specs
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
debug('reading Cypress config < v10')
|
|
220
|
+
const specs = findCypressSpecsV9(options)
|
|
221
|
+
return specs
|
|
222
|
+
} else if (type === 'component') {
|
|
223
|
+
debug('finding component specs')
|
|
224
|
+
const specs = findCypressSpecsV10(options, type)
|
|
173
225
|
return specs
|
|
226
|
+
} else {
|
|
227
|
+
console.error('Do not know how to find specs of type "%s"', type)
|
|
228
|
+
console.error('returning an empty list')
|
|
229
|
+
return []
|
|
174
230
|
}
|
|
175
|
-
|
|
176
|
-
debug('reading Cypress config < v10')
|
|
177
|
-
const specs = findCypressSpecsV9(options)
|
|
178
|
-
return specs
|
|
179
231
|
}
|
|
180
232
|
|
|
181
233
|
function collectResults(structure, results) {
|