find-cypress-specs 1.41.4 → 1.43.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 CHANGED
@@ -1,4 +1,4 @@
1
- # find-cypress-specs [![renovate-app badge][renovate-badge]][renovate-app] ![cypress version](https://img.shields.io/badge/cypress-13.6.3-brightgreen) [![ci](https://github.com/bahmutov/find-cypress-specs/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bahmutov/find-cypress-specs/actions/workflows/ci.yml)
1
+ # find-cypress-specs [![renovate-app badge][renovate-badge]][renovate-app] ![cypress version](https://img.shields.io/badge/cypress-13.6.4-brightgreen) [![ci](https://github.com/bahmutov/find-cypress-specs/actions/workflows/ci.yml/badge.svg?branch=main)](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
 
@@ -38,6 +38,16 @@ $ npx find-cypress-specs --branch main
38
38
  # prints only some specs, the ones that have changed against the "origin/main"
39
39
  ```
40
40
 
41
+ ## find number of machines
42
+
43
+ If we find all the changed specs to run, we might need to decide how many machines we need. We can do a rough job by specifying the number of specs per machine plus the max number.
44
+
45
+ ```
46
+ $ npx find-cypress-specs --branch main --specs-per-machine 4 --max-machines 5
47
+ ```
48
+
49
+ For now, it is only useful when setting the GHA outputs.
50
+
41
51
  ## set GitHub Actions outputs
42
52
 
43
53
  If you add `--set-gha-outputs` command line switch, then the number of changed specs and the comma-separated file list will be set as GH Actions outputs `changedSpecsN` and `changedSpecs`. See [pr.yml](./.github/workflows/pr.yml) for example
@@ -52,6 +62,8 @@ If you add `--set-gha-outputs` command line switch, then the number of changed s
52
62
  run: echo ${{ steps.step1.outputs.changedSpecsN }} ${{ steps.step1.outputs.changedSpecs }}
53
63
  ```
54
64
 
65
+ If you set the number of machines, it will set the output `machinesNeeded`
66
+
55
67
  ## Write GitHub Actions job summary
56
68
 
57
69
  You can output changes specs by using the parameter `--gha-summary`
@@ -290,7 +302,7 @@ $ npx find-cypress-specs --names --skipped --count
290
302
 
291
303
  ## cypress.config.ts
292
304
 
293
- 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.
305
+ If the project uses TypeScript and `cypress.config.ts` then this module uses [tsx](https://github.com/privatenumber/tsx) to load the config and fetch the spec pattern.
294
306
 
295
307
  If you are using `import` keyword in your `cypress.config.ts` you might get an error like this:
296
308
 
package/bin/find.js CHANGED
@@ -53,6 +53,9 @@ const args = arg({
53
53
  '--update-badge': Boolean,
54
54
  // output the list in Markdown format
55
55
  '--markdown': Boolean,
56
+ // optional: output the number of machines needed to run the tests
57
+ '--specs-per-machine': Number,
58
+ '--max-machines': Number,
56
59
  //
57
60
  // aliases
58
61
  '-n': '--names',
@@ -188,13 +191,35 @@ if (args['--test-counts']) {
188
191
  })
189
192
  }
190
193
 
194
+ let machinesNeeded
195
+ if (args['--specs-per-machine'] > 0 && args['--max-machines'] > 0) {
196
+ const specsPerMachine = args['--specs-per-machine']
197
+ const maxMachines = args['--max-machines']
198
+ machinesNeeded = Math.min(
199
+ Math.ceil(changedSpecs.length / specsPerMachine),
200
+ maxMachines,
201
+ )
202
+ debug(
203
+ 'specs per machine %d with max %d machines',
204
+ specsPerMachine,
205
+ maxMachines,
206
+ )
207
+ debug(
208
+ 'from %d specs, set %d output machinesNeeded',
209
+ changedSpecs.length,
210
+ machinesNeeded,
211
+ )
212
+ }
213
+
191
214
  if (args['--set-gha-outputs']) {
192
215
  debug('setting GitHub Actions outputs changedSpecsN and changedSpecs')
193
216
  debug('changedSpecsN %d', changedSpecs.length)
194
217
  debug('plus changedSpecs')
195
218
  core.setOutput('changedSpecsN', changedSpecs.length)
196
219
  core.setOutput('changedSpecs', changedSpecs.join(','))
220
+ core.setOutput('machinesNeeded', machinesNeeded)
197
221
  }
222
+
198
223
  if (args['--gha-summary']) {
199
224
  debug('writing GitHub Actions summary')
200
225
  const summary = changedSpecs.length
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.41.4",
3
+ "version": "1.43.0",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
@@ -55,12 +55,12 @@
55
55
  "homepage": "https://github.com/bahmutov/find-cypress-specs#readme",
56
56
  "devDependencies": {
57
57
  "ava": "^4.0.0",
58
- "cypress": "13.6.3",
58
+ "cypress": "13.6.4",
59
59
  "dependency-version-badge": "^1.11.0",
60
60
  "execa-wrap": "^1.4.0",
61
61
  "prettier": "^2.5.1",
62
62
  "really-need": "^1.9.2",
63
- "semantic-release": "23.0.0",
63
+ "semantic-release": "23.0.2",
64
64
  "sinon": "^13.0.1",
65
65
  "typescript": "^4.6.3"
66
66
  },
@@ -76,6 +76,6 @@
76
76
  "require-and-forget": "^1.0.1",
77
77
  "shelljs": "^0.8.5",
78
78
  "spec-change": "^1.10.0",
79
- "ts-node": "^10.9.1"
79
+ "tsx": "^4.7.1"
80
80
  }
81
81
  }
package/src/index.js CHANGED
@@ -12,6 +12,12 @@ const shell = require('shelljs')
12
12
  const pluralize = require('pluralize')
13
13
  const requireEveryTime = require('require-and-forget')
14
14
 
15
+ // Require CJS loader to resolve:
16
+ // https://github.com/bahmutov/find-cypress-specs/issues/228
17
+ // https://github.com/bahmutov/find-cypress-specs/issues/222
18
+ // https://github.com/privatenumber/tsx
19
+ require('tsx/cjs')
20
+
15
21
  const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
16
22
 
17
23
  /**
@@ -37,15 +43,6 @@ function getConfigJs(filename) {
37
43
  }
38
44
 
39
45
  function getConfigTs(filename) {
40
- // handle ts modules without "type: module"
41
- // https://github.com/bahmutov/find-cypress-specs/issues/222
42
- const tsNode = require('ts-node')
43
- tsNode.register({
44
- transpileOnly: true,
45
- compilerOptions: {
46
- module: 'commonjs',
47
- },
48
- })
49
46
  const configFilename = path.join(process.cwd(), filename)
50
47
  debug('loading Cypress config from %s', configFilename)
51
48
  const definedConfig = requireEveryTime(configFilename)
@@ -146,8 +143,13 @@ function findCypressSpecsV10(opts = {}, type = 'e2e', returnAbsolute = false) {
146
143
  if (type !== 'e2e' && type !== 'component') {
147
144
  throw new Error(`Unknown spec type ${type}`)
148
145
  }
146
+ // handle the interoperability loading of default export
147
+ if (Object.keys(opts).length === 1 && Object.keys(opts)[0] === 'default') {
148
+ opts = opts.default
149
+ }
149
150
 
150
151
  if (!(type in opts)) {
152
+ debug('options %o', opts)
151
153
  throw new Error(`Missing "${type}" object in the Cypress config object`)
152
154
  }
153
155
  const e2eDefaults = {