find-cypress-specs 1.35.2 → 1.36.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Find Cypress spec files using the config settings
4
4
 
5
- ![Cypress tests](https://img.shields.io/badge/cy%20tests-E2E%204%20%7C%20component%202-blue)
5
+ ![Cypress tests](https://img.shields.io/badge/cy%20tests-E2E%205%20%7C%20component%202-blue)
6
6
 
7
7
  ```bash
8
8
  $ npx find-cypress-specs
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.35.2",
3
+ "version": "1.36.1",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
@@ -25,6 +25,7 @@
25
25
  "demo-names-and-tags-json": "node ./bin/find --names --tags --json",
26
26
  "demo-names-json": "node ./bin/find --names --json",
27
27
  "demo-names-tagged": "node ./bin/find --names --tagged @user",
28
+ "demo-subfolder": "DEBUG=find-cypress-specs CYPRESS_CONFIG_FILE=mocks/my-app/e2e/cypress.config.js node ./bin/find --names",
28
29
  "print-changed-specs": "node ./bin/find --branch main",
29
30
  "count-changed-specs": "node ./bin/find --branch main --count",
30
31
  "demo-test-counts": "node ./bin/find --test-counts",
@@ -52,7 +53,7 @@
52
53
  "homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
53
54
  "devDependencies": {
54
55
  "ava": "^4.0.0",
55
- "cypress": "13.3.0",
56
+ "cypress": "13.3.1",
56
57
  "dependency-version-badge": "^1.11.0",
57
58
  "execa-wrap": "^1.4.0",
58
59
  "prettier": "^2.5.1",
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('Config file should be .ts, .js or .json file even when using CYPRESS_CONFIG_FILE env var')
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,10 @@ function findCypressSpecsV10(opts = {}, type = 'e2e') {
170
172
  const globbyOptions = {
171
173
  sort: true,
172
174
  ignore,
175
+ absolute: returnAbsolute,
176
+ }
177
+ if (opts.projectRoot) {
178
+ globbyOptions.cwd = opts.projectRoot
173
179
  }
174
180
  debug('globby options %s %o', options.specPattern, globbyOptions)
175
181
 
@@ -210,7 +216,7 @@ function findCypressSpecsV10(opts = {}, type = 'e2e') {
210
216
  return filtered
211
217
  }
212
218
 
213
- function getSpecs(options, type) {
219
+ function getSpecs(options, type, returnAbsolute = false) {
214
220
  if (typeof options === 'undefined') {
215
221
  options = getConfig()
216
222
  if (typeof type === 'undefined') {
@@ -231,10 +237,15 @@ function getSpecs(options, type) {
231
237
  }
232
238
  }
233
239
 
234
- return findCypressSpecs(options, type)
240
+ return findCypressSpecs(options, type, returnAbsolute)
235
241
  }
236
242
 
237
- function findCypressSpecs(options, type = 'e2e') {
243
+ /**
244
+ * Finds Cypress specs.
245
+ * @param {boolean} returnAbsolute Return the list of absolute spec filenames
246
+ * @returns {string[]} List of filenames
247
+ */
248
+ function findCypressSpecs(options, type = 'e2e', returnAbsolute = false) {
238
249
  debug('finding specs of type %s', type)
239
250
  if (options.version) {
240
251
  debug('Cypress version %s', options.version)
@@ -254,7 +265,7 @@ function findCypressSpecs(options, type = 'e2e') {
254
265
  if (type === 'e2e') {
255
266
  if (major >= 10) {
256
267
  debug('config has "e2e" property, treating as Cypress v10+')
257
- const specs = findCypressSpecsV10(options, type)
268
+ const specs = findCypressSpecsV10(options, type, returnAbsolute)
258
269
  return specs
259
270
  }
260
271
 
@@ -263,7 +274,7 @@ function findCypressSpecs(options, type = 'e2e') {
263
274
  return specs
264
275
  } else if (type === 'component') {
265
276
  debug('finding component specs')
266
- const specs = findCypressSpecsV10(options, type)
277
+ const specs = findCypressSpecsV10(options, type, returnAbsolute)
267
278
  return specs
268
279
  } else {
269
280
  console.error('Do not know how to find specs of type "%s"', type)