find-cypress-specs 1.19.0 → 1.19.2

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 +23 -0
  2. package/package.json +1 -1
  3. package/src/index.js +12 -4
package/README.md CHANGED
@@ -119,6 +119,29 @@ $ npx find-cypress-specs --names --tagged <tag1>,<tag2>,<tag3>,...
119
119
 
120
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
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
+
122
145
  **Tip:** read my blog post [Convert Cypress Specs from JavaScript to TypeScript](https://glebbahmutov.com/blog/cypress-js-to-ts/).
123
146
 
124
147
  ## Details
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.19.0",
3
+ "version": "1.19.2",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
package/src/index.js CHANGED
@@ -32,10 +32,16 @@ function getConfigJs(filename) {
32
32
  }
33
33
 
34
34
  function getConfigTs(filename) {
35
- require('ts-node/register')
36
- const jsFile = path.join(process.cwd(), filename)
37
- debug('loading Cypress config from %s', jsFile)
38
- const definedConfig = requireEveryTime(jsFile)
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
+ if (definedConfig && definedConfig.default) {
40
+ // due to TS / ES6 module transpile we got the default export
41
+ debug('returning default export as config from %s', filename)
42
+ return definedConfig.default
43
+ }
44
+
39
45
  return definedConfig
40
46
  }
41
47
 
@@ -156,10 +162,12 @@ function getSpecs() {
156
162
 
157
163
  function findCypressSpecs(options) {
158
164
  if (options.e2e) {
165
+ debug('config has "e2e" property, treating as Cypress v10+')
159
166
  const specs = findCypressSpecsV10(options)
160
167
  return specs
161
168
  }
162
169
 
170
+ debug('reading Cypress config < v10')
163
171
  const specs = findCypressSpecsV9(options)
164
172
  return specs
165
173
  }