codeceptjs 4.0.2-beta.18 → 4.0.2-beta.19

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/lib/config.js CHANGED
@@ -156,27 +156,32 @@ async function loadConfigFile(configFile) {
156
156
  try {
157
157
  // For .ts files, try to compile and load as JavaScript
158
158
  if (extensionName === '.ts') {
159
+ let transpileError = null
160
+ let tempFile = null
161
+ let allTempFiles = null
162
+ let fileMapping = null
163
+
159
164
  try {
160
165
  // Use the TypeScript transpilation utility
161
166
  const typescript = require('typescript')
162
- const { tempFile, allTempFiles, fileMapping } = await transpileTypeScript(configFile, typescript)
163
-
164
- try {
165
- configModule = await import(tempFile)
166
- cleanupTempFiles(allTempFiles)
167
- } catch (err) {
167
+ const result = await transpileTypeScript(configFile, typescript)
168
+ tempFile = result.tempFile
169
+ allTempFiles = result.allTempFiles
170
+ fileMapping = result.fileMapping
171
+
172
+ configModule = await import(tempFile)
173
+ cleanupTempFiles(allTempFiles)
174
+ } catch (err) {
175
+ transpileError = err
176
+ if (fileMapping) {
168
177
  fixErrorStack(err, fileMapping)
169
- cleanupTempFiles(allTempFiles)
170
- throw err
171
178
  }
172
- } catch (tsError) {
173
- // If TypeScript compilation fails, fallback to ts-node
174
- try {
175
- require('ts-node/register')
176
- configModule = require(configFile)
177
- } catch (tsNodeError) {
178
- throw new Error(`Failed to load TypeScript config: ${tsError.message}`)
179
+ if (allTempFiles) {
180
+ cleanupTempFiles(allTempFiles)
179
181
  }
182
+ // Throw immediately with the actual error - don't fall back to ts-node
183
+ // as it will mask the real error with "Unexpected token 'export'"
184
+ throw err
180
185
  }
181
186
  } else {
182
187
  // Try ESM import first for JS files
@@ -158,11 +158,17 @@ const __dirname = __dirname_fn(__filename);
158
158
  if (fs.existsSync(tsPath)) {
159
159
  importedPath = tsPath
160
160
  } else {
161
- // Try .js extension as well
162
- const jsPath = importedPath + '.js'
163
- if (fs.existsSync(jsPath)) {
164
- // Skip .js files, they don't need transpilation
165
- continue
161
+ // Try index.ts for directory imports
162
+ const indexTsPath = path.join(importedPath, 'index.ts')
163
+ if (fs.existsSync(indexTsPath)) {
164
+ importedPath = indexTsPath
165
+ } else {
166
+ // Try .js extension as well
167
+ const jsPath = importedPath + '.js'
168
+ if (fs.existsSync(jsPath)) {
169
+ // Skip .js files, they don't need transpilation
170
+ continue
171
+ }
166
172
  }
167
173
  }
168
174
  }
@@ -186,13 +192,11 @@ const __dirname = __dirname_fn(__filename);
186
192
  if (transpiledFiles.has(tsVersion)) {
187
193
  const tempFile = transpiledFiles.get(tsVersion)
188
194
  const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
189
- // Ensure the path starts with ./
190
195
  if (!relPath.startsWith('.')) {
191
196
  return `from './${relPath}'`
192
197
  }
193
198
  return `from '${relPath}'`
194
199
  }
195
- // Keep .js extension as-is (might be a real .js file)
196
200
  return match
197
201
  }
198
202
 
@@ -203,18 +207,24 @@ const __dirname = __dirname_fn(__filename);
203
207
  if (transpiledFiles.has(tsPath)) {
204
208
  const tempFile = transpiledFiles.get(tsPath)
205
209
  const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
206
- // Ensure the path starts with ./
207
210
  if (!relPath.startsWith('.')) {
208
211
  return `from './${relPath}'`
209
212
  }
210
213
  return `from '${relPath}'`
211
214
  }
212
215
 
213
- // If the import doesn't have a standard module extension (.js, .mjs, .cjs, .json)
214
- // add .js for ESM compatibility
215
- // This handles cases where:
216
- // 1. Import has no real extension (e.g., "./utils" or "./helper")
217
- // 2. Import has a non-standard extension that's part of the name (e.g., "./abstract.helper")
216
+ // Try index.ts for directory imports
217
+ const indexTsPath = path.join(resolvedPath, 'index.ts')
218
+ if (transpiledFiles.has(indexTsPath)) {
219
+ const tempFile = transpiledFiles.get(indexTsPath)
220
+ const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
221
+ if (!relPath.startsWith('.')) {
222
+ return `from './${relPath}'`
223
+ }
224
+ return `from '${relPath}'`
225
+ }
226
+
227
+ // If the import doesn't have a standard module extension, add .js for ESM compatibility
218
228
  const standardExtensions = ['.js', '.mjs', '.cjs', '.json', '.node']
219
229
  const hasStandardExtension = standardExtensions.includes(originalExt.toLowerCase())
220
230
 
@@ -222,7 +232,6 @@ const __dirname = __dirname_fn(__filename);
222
232
  return match.replace(importPath, importPath + '.js')
223
233
  }
224
234
 
225
- // Otherwise, keep the import as-is
226
235
  return match
227
236
  }
228
237
  )
@@ -232,7 +241,6 @@ const __dirname = __dirname_fn(__filename);
232
241
  /require\s*\(\s*['"](\.[^'"]+?)(?:\.ts)?['"]\s*\)/g,
233
242
  (match, requirePath) => {
234
243
  let resolvedPath = path.resolve(fileBaseDir, requirePath)
235
- const originalExt = path.extname(requirePath)
236
244
 
237
245
  // Handle .js extension that might be .ts
238
246
  if (resolvedPath.endsWith('.js')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "4.0.2-beta.18",
3
+ "version": "4.0.2-beta.19",
4
4
  "type": "module",
5
5
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
6
6
  "keywords": [