Fix: Skip .js extensions for TypeScript test imports#1994
Fix: Skip .js extensions for TypeScript test imports#1994mohammedahmed18 wants to merge 1 commit intomainfrom
Conversation
Issue #7: TypeScript test imports incorrectly had .js extensions added **Problem:** When processing generated tests for TypeScript ESM projects, the CLI added .js extensions to all relative imports. This caused 'Cannot find module' errors when ts-jest tried to import .ts files with .js extensions. Example error: Cannot find module '../../src/processors/index.js' from 'test/test_postprocessWithLogs.test.ts' (actual file is index.ts, not index.js) **Root Cause:** File: codeflash/languages/javascript/support.py (line 2073-2076) The code called add_js_extensions_to_relative_imports() for ALL ESM projects without checking if the test file was TypeScript. TypeScript tests with ts-jest run on TypeScript source directly, not compiled output. They expect imports without .js extensions. **Fix:** Skip adding .js extensions when the test file is TypeScript (.ts/.tsx): is_typescript_test = test_path.suffix in ('.ts', '.tsx') if project_module_system == ModuleSystem.ES_MODULE and not is_typescript_test: generated_test_source = add_js_extensions_to_relative_imports(...) **Impact:** - Affected 3 out of 44 logs (~7%) - Severity: MEDIUM - Systematic bug (reproducible on every TypeScript ESM file) **Trace IDs:** - 4267fb29-fbb7-4e9a-ac9b-b19f752d9d4f - 966be2b1-ccd9-49b2-95ba-a5ee69f4851c - f867b66e-6c8f-434f-a5a8-af91df67bba6 **Verification:** - 2 new regression tests pass - 317 existing JavaScript tests pass (no regressions) - Linting/type checks pass (uv run prek) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Claude finished @mohammedahmed18's task in 2m 14s —— View job PR Review SummaryPrek Checks✅ Ruff check: passed Code ReviewFix correctness ✅ Overly verbose comments Docstrings in test file Second test has no assertion Type error in test Duplicate DetectionNo duplicates detected. The check is localized and doesn't duplicate any existing logic. Last updated: 2026-04-04 |
|
wrong fix the correct one is here: #1999 |
Issue #7: TypeScript Test Import Extensions
Problem
TypeScript test imports incorrectly had
.jsextensions added, causing "Cannot find module" errors when ts-jest tried to import.tsfiles.Error:
(actual file is
index.ts, notindex.js)Root Cause
File:
codeflash/languages/javascript/support.py:2073-2076The code called
add_js_extensions_to_relative_imports()for ALL ESM projects without checking if the test file was TypeScript.TypeScript tests with ts-jest run on TypeScript source directly (not compiled output). They expect imports without
.jsextensions because:.ts, not.js.jscauses module resolution failuresFix
Skip adding
.jsextensions when the test file is TypeScript:Impact
Trace IDs
Verification
✅ 2 new regression tests pass
✅ 317 existing JavaScript tests pass (no regressions)
✅ Linting/type checks pass (
uv run prek)Files Changed
codeflash/languages/javascript/support.py(fix + documentation)tests/test_languages/test_typescript_esm_extension_bug.py(regression tests)