find-cypress-specs 1.35.2 → 1.36.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 +8 -0
- package/package.json +1 -1
- package/src/files.js +14 -0
- package/src/index.js +19 -11
package/README.md
CHANGED
|
@@ -300,6 +300,14 @@ If you want to use a custom Cypress config, pass it via the environment variable
|
|
|
300
300
|
$ CYPRESS_CONFIG_FILE=path/to/cypress.config.js npx find-cypres-specs ...
|
|
301
301
|
```
|
|
302
302
|
|
|
303
|
+
## Absolute spec filenames
|
|
304
|
+
|
|
305
|
+
You can return absolute filenames to the found specs
|
|
306
|
+
|
|
307
|
+
```js
|
|
308
|
+
getSpecs(config, 'e2e|component', true)
|
|
309
|
+
```
|
|
310
|
+
|
|
303
311
|
## Details
|
|
304
312
|
|
|
305
313
|
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
package/src/files.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { relative } = require('path')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts a list of absolute filenames to the list of relative filenames
|
|
6
|
+
* @param {string[]} filenames List of absolute filenames
|
|
7
|
+
* @returns {string[]} List of relative filenames to the current working directory
|
|
8
|
+
*/
|
|
9
|
+
function toRelative(filenames) {
|
|
10
|
+
const cwd = process.cwd()
|
|
11
|
+
return filenames.map((filename) => relative(cwd, filename))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = { toRelative }
|
package/src/index.js
CHANGED
|
@@ -54,16 +54,18 @@ function getConfig() {
|
|
|
54
54
|
if (typeof process.env.CYPRESS_CONFIG_FILE !== 'undefined') {
|
|
55
55
|
const configFile = process.env.CYPRESS_CONFIG_FILE
|
|
56
56
|
if (configFile.endsWith('.js')) {
|
|
57
|
-
debug(`found file ${configFile}`)
|
|
57
|
+
debug(`found file ${configFile}`)
|
|
58
58
|
return getConfigJs(`./${configFile}`)
|
|
59
59
|
} else if (configFile.endsWith('.ts')) {
|
|
60
|
-
debug(`found file ${configFile}`)
|
|
60
|
+
debug(`found file ${configFile}`)
|
|
61
61
|
return getConfigTs(`./${configFile}`)
|
|
62
62
|
} else if (configFile.endsWith('.json')) {
|
|
63
|
-
debug(`found file ${configFile}`)
|
|
63
|
+
debug(`found file ${configFile}`)
|
|
64
64
|
return getConfigJson(`./${configFile}`)
|
|
65
|
-
}
|
|
66
|
-
throw new Error(
|
|
65
|
+
}
|
|
66
|
+
throw new Error(
|
|
67
|
+
'Config file should be .ts, .js or .json file even when using CYPRESS_CONFIG_FILE env var',
|
|
68
|
+
)
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
if (fs.existsSync('./cypress.config.js')) {
|
|
@@ -129,7 +131,7 @@ function findCypressSpecsV9(opts = {}) {
|
|
|
129
131
|
return filtered.map((file) => path.join(options.integrationFolder, file))
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
function findCypressSpecsV10(opts = {}, type = 'e2e') {
|
|
134
|
+
function findCypressSpecsV10(opts = {}, type = 'e2e', returnAbsolute = false) {
|
|
133
135
|
debug('findCypressSpecsV10')
|
|
134
136
|
if (type !== 'e2e' && type !== 'component') {
|
|
135
137
|
throw new Error(`Unknown spec type ${type}`)
|
|
@@ -170,6 +172,7 @@ function findCypressSpecsV10(opts = {}, type = 'e2e') {
|
|
|
170
172
|
const globbyOptions = {
|
|
171
173
|
sort: true,
|
|
172
174
|
ignore,
|
|
175
|
+
absolute: returnAbsolute,
|
|
173
176
|
}
|
|
174
177
|
debug('globby options %s %o', options.specPattern, globbyOptions)
|
|
175
178
|
|
|
@@ -210,7 +213,7 @@ function findCypressSpecsV10(opts = {}, type = 'e2e') {
|
|
|
210
213
|
return filtered
|
|
211
214
|
}
|
|
212
215
|
|
|
213
|
-
function getSpecs(options, type) {
|
|
216
|
+
function getSpecs(options, type, returnAbsolute = false) {
|
|
214
217
|
if (typeof options === 'undefined') {
|
|
215
218
|
options = getConfig()
|
|
216
219
|
if (typeof type === 'undefined') {
|
|
@@ -231,10 +234,15 @@ function getSpecs(options, type) {
|
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
|
|
234
|
-
return findCypressSpecs(options, type)
|
|
237
|
+
return findCypressSpecs(options, type, returnAbsolute)
|
|
235
238
|
}
|
|
236
239
|
|
|
237
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Finds Cypress specs.
|
|
242
|
+
* @param {boolean} returnAbsolute Return the list of absolute spec filenames
|
|
243
|
+
* @returns {string[]} List of filenames
|
|
244
|
+
*/
|
|
245
|
+
function findCypressSpecs(options, type = 'e2e', returnAbsolute = false) {
|
|
238
246
|
debug('finding specs of type %s', type)
|
|
239
247
|
if (options.version) {
|
|
240
248
|
debug('Cypress version %s', options.version)
|
|
@@ -254,7 +262,7 @@ function findCypressSpecs(options, type = 'e2e') {
|
|
|
254
262
|
if (type === 'e2e') {
|
|
255
263
|
if (major >= 10) {
|
|
256
264
|
debug('config has "e2e" property, treating as Cypress v10+')
|
|
257
|
-
const specs = findCypressSpecsV10(options, type)
|
|
265
|
+
const specs = findCypressSpecsV10(options, type, returnAbsolute)
|
|
258
266
|
return specs
|
|
259
267
|
}
|
|
260
268
|
|
|
@@ -263,7 +271,7 @@ function findCypressSpecs(options, type = 'e2e') {
|
|
|
263
271
|
return specs
|
|
264
272
|
} else if (type === 'component') {
|
|
265
273
|
debug('finding component specs')
|
|
266
|
-
const specs = findCypressSpecsV10(options, type)
|
|
274
|
+
const specs = findCypressSpecsV10(options, type, returnAbsolute)
|
|
267
275
|
return specs
|
|
268
276
|
} else {
|
|
269
277
|
console.error('Do not know how to find specs of type "%s"', type)
|