find-cypress-specs 1.18.0 → 1.19.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.
Files changed (3) hide show
  1. package/README.md +30 -1
  2. package/package.json +5 -4
  3. package/src/index.js +24 -4
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-10.3.0-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-10.8.0-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
 
@@ -115,6 +115,35 @@ $ 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
+ If you are using `import` keyword in your `cypress.config.ts` you might get an error like this:
123
+
124
+ ```
125
+ import { defineConfig } from 'cypress';
126
+ ^^^^^^
127
+
128
+ SyntaxError: Cannot use import statement outside a module
129
+ ```
130
+
131
+ In that case, add to your `tsconfig.json` file the `ts-node` block:
132
+
133
+ ```json
134
+ {
135
+ "ts-node": {
136
+ "compilerOptions": {
137
+ "module": "commonjs"
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ See example in [bahmutov/test-todomvc-using-app-actions](https://github.com/bahmutov/test-todomvc-using-app-actions).
144
+
145
+ **Tip:** read my blog post [Convert Cypress Specs from JavaScript to TypeScript](https://glebbahmutov.com/blog/cypress-js-to-ts/).
146
+
118
147
  ## Details
119
148
 
120
149
  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.18.0",
3
+ "version": "1.19.1",
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": "10.3.0",
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.3",
47
+ "semantic-release": "19.0.5",
48
48
  "sinon": "^13.0.1",
49
49
  "typescript": "^4.6.3"
50
50
  },
@@ -57,6 +57,7 @@
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"
60
+ "shelljs": "^0.8.5",
61
+ "ts-node": "^10.9.1"
61
62
  }
62
63
  }
package/src/index.js CHANGED
@@ -31,11 +31,31 @@ function getConfigJs(filename) {
31
31
  return definedConfig
32
32
  }
33
33
 
34
- function getConfig(filename = './cypress.config.js') {
35
- if (filename.endsWith('.json')) {
36
- return getConfigJson(filename)
34
+ function getConfigTs(filename) {
35
+ require('ts-node/register/transpile-only')
36
+ const configFilename = path.join(process.cwd(), filename)
37
+ debug('loading Cypress config from %s', configFilename)
38
+ const definedConfig = requireEveryTime(configFilename)
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')
37
56
  }
38
- return getConfigJs(filename)
57
+
58
+ throw new Error('Do not know how to find and load Cypress config file')
39
59
  }
40
60
 
41
61
  function findCypressSpecsV9(opts = {}) {