Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ActorFactory from './actor.js'
import output from './output.js'
import { emptyFolder } from './utils.js'
import { initCodeceptGlobals } from './globals.js'
import { validateTypeScriptSetup } from './utils/loaderCheck.js'
import { validateTypeScriptSetup, getTSNodeESMWarning } from './utils/loaderCheck.js'
import recorder from './recorder.js'

import storeListener from './listener/store.js'
Expand Down Expand Up @@ -270,6 +270,12 @@ class Codecept {
process.exit(1)
}

// Show warning if ts-node/esm is being used
const tsWarning = getTSNodeESMWarning(this.requiringModules || [])
if (tsWarning) {
output.print(output.colors.yellow(tsWarning))
}

// Ensure translations are loaded for Gherkin features
try {
const { loadTranslations } = await import('./mocha/gherkin.js')
Expand Down
20 changes: 20 additions & 0 deletions lib/utils/loaderCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ Note: TypeScript config files (codecept.conf.ts) and helpers are automatically
`
}

/**
* Get warning message if ts-node/esm is being used
* @param {string[]} requiredModules - Array of required modules from config
* @returns {string|null} Warning message or null
*/
export function getTSNodeESMWarning(requiredModules = []) {
if (!requiredModules.includes('ts-node/esm')) {
return null
}

return `
⚠️ Warning: ts-node/esm with "module": "esnext" requires explicit file extensions in all imports.

This is a known limitation. Use tsx/cjs instead to write imports without extensions.

📚 Documentation: https://codecept.io/typescript

`
}

/**
* Check if user is trying to run TypeScript tests without proper loader
* @param {string[]} testFiles - Array of test file paths
Expand Down