codeceptjs 4.0.1-beta.14 → 4.0.1-beta.16

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.
@@ -239,8 +239,13 @@ function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue)
239
239
  }
240
240
 
241
241
  for (const name in pathsToValue) {
242
- const relativePath = getPath(pathsToValue[name], targetFolderPath, testsPath)
243
- importStrings.push(`type ${name} = import('${relativePath}');`)
242
+ const originalPath = pathsToValue[name]
243
+ const relativePath = getPath(originalPath, targetFolderPath, testsPath)
244
+ if (originalPath.endsWith('.js') || originalPath.endsWith('.ts')) {
245
+ importStrings.push(`type ${name} = InstanceType<typeof import('${relativePath}').default>;`)
246
+ } else {
247
+ importStrings.push(`type ${name} = import('${relativePath}');`)
248
+ }
244
249
  }
245
250
 
246
251
  return importStrings
@@ -62,34 +62,9 @@ class MochaFactory {
62
62
  const jsFiles = this.files.filter(file => !file.match(/\.feature$/))
63
63
  this.files = this.files.filter(file => !file.match(/\.feature$/))
64
64
 
65
- // Load JavaScript test files using ESM imports
65
+ // Load JavaScript test files using original loadFiles
66
66
  if (jsFiles.length > 0) {
67
- try {
68
- // Try original loadFiles first for compatibility
69
- originalLoadFiles.call(this, fn)
70
- } catch (e) {
71
- // If original loadFiles fails, load ESM files manually
72
- if (e.message.includes('not in cache') || e.message.includes('ESM') || e.message.includes('getStatus')) {
73
- // Load ESM files by importing them synchronously using top-level await workaround
74
- for (const file of jsFiles) {
75
- try {
76
- // Convert file path to file:// URL for dynamic import
77
- const fileUrl = `file://${file}`
78
- // Use import() but don't await it - let it load in the background
79
- import(fileUrl).catch(importErr => {
80
- // If dynamic import fails, the file may have syntax errors or other issues
81
- console.error(`Failed to load test file ${file}:`, importErr.message)
82
- })
83
- if (fn) fn()
84
- } catch (fileErr) {
85
- console.error(`Error processing test file ${file}:`, fileErr.message)
86
- if (fn) fn(fileErr)
87
- }
88
- }
89
- } else {
90
- throw e
91
- }
92
- }
67
+ originalLoadFiles.call(this, fn)
93
68
  }
94
69
 
95
70
  // add ids for each test and check uniqueness
@@ -65,9 +65,18 @@ CodeceptJS 4.x uses ES Modules (ESM) and requires a loader to run TypeScript tes
65
65
  ✅ Complete: Handles all TypeScript features
66
66
 
67
67
  ┌─────────────────────────────────────────────────────────────────────────────┐
68
- │ Option 2: ts-node/esm (Alternative - Established, Requires Config)
68
+ │ Option 2: ts-node/esm (Not Recommended - Has Module Resolution Issues)
69
69
  └─────────────────────────────────────────────────────────────────────────────┘
70
70
 
71
+ ⚠️ ts-node/esm has significant limitations and is not recommended:
72
+ - Doesn't work with "type": "module" in package.json
73
+ - Module resolution doesn't work like standard TypeScript ESM
74
+ - Import statements must use explicit file paths
75
+
76
+ We strongly recommend using tsx/cjs instead.
77
+
78
+ If you still want to use ts-node/esm:
79
+
71
80
  Installation:
72
81
  npm install --save-dev ts-node
73
82
 
@@ -84,11 +93,12 @@ CodeceptJS 4.x uses ES Modules (ESM) and requires a loader to run TypeScript tes
84
93
  "esModuleInterop": true
85
94
  },
86
95
  "ts-node": {
87
- "esm": true,
88
- "experimentalSpecifierResolution": "node"
96
+ "esm": true
89
97
  }
90
98
  }
91
99
 
100
+ 3. Do NOT use "type": "module" in package.json
101
+
92
102
  📚 Documentation: https://codecept.io/typescript
93
103
 
94
104
  Note: TypeScript config files (codecept.conf.ts) and helpers are automatically
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "4.0.1-beta.14",
3
+ "version": "4.0.1-beta.16",
4
4
  "type": "module",
5
5
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
6
6
  "keywords": [