(testFiles)
| 27 | * @returns {string|null} Error message or null if no TypeScript files |
| 28 | */ |
| 29 | export function getTypeScriptLoaderError(testFiles) { |
| 30 | const tsFiles = testFiles.filter(f => f.endsWith('.ts')) |
| 31 | |
| 32 | if (tsFiles.length === 0) return null |
| 33 | |
| 34 | return ` |
| 35 | ╔═════════════════════════════════════════════════════════════════════════════╗ |
| 36 | ║ ║ |
| 37 | ║ ⚠️ TypeScript Test Files Detected but No Loader Configured ║ |
| 38 | ║ ║ |
| 39 | ╚═════════════════════════════════════════════════════════════════════════════╝ |
| 40 | |
| 41 | Found ${tsFiles.length} TypeScript test file(s) but no TypeScript loader is configured. |
| 42 | |
| 43 | CodeceptJS 4.x uses ES Modules (ESM) and requires a loader to run TypeScript tests. |
| 44 | |
| 45 | ┌─────────────────────────────────────────────────────────────────────────────┐ |
| 46 | │ Option 1: tsx (Recommended - Fast, Zero Config) │ |
| 47 | └─────────────────────────────────────────────────────────────────────────────┘ |
| 48 | |
| 49 | Installation: |
| 50 | npm install --save-dev tsx |
| 51 | |
| 52 | Configuration: |
| 53 | Add to your codecept.conf.ts or codecept.conf.js: |
| 54 | |
| 55 | export const config = { |
| 56 | tests: './**/*_test.ts', |
| 57 | require: ['tsx/cjs'], // ← Add this line |
| 58 | helpers: { /* ... */ } |
| 59 | } |
| 60 | |
| 61 | Why tsx? |
| 62 | ⚡ Fast: Built on esbuild |
| 63 | 🎯 Zero config: No tsconfig.json required |
| 64 | ✅ Works with Mocha: Uses CommonJS hooks |
| 65 | ✅ Complete: Handles all TypeScript features |
| 66 | |
| 67 | ┌─────────────────────────────────────────────────────────────────────────────┐ |
| 68 | │ Option 2: ts-node/esm (Not Recommended - Has Module Resolution Issues) │ |
| 69 | └─────────────────────────────────────────────────────────────────────────────┘ |
| 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 | |
| 80 | Installation: |
| 81 | npm install --save-dev ts-node |
| 82 | |
| 83 | Configuration: |
| 84 | 1. Add to your codecept.conf.ts: |
| 85 | require: ['ts-node/esm'] |
| 86 |
no test coverage detected