Fix: Add TypeScript transformer to runtime Jest config#2011
Open
mohammedahmed18 wants to merge 1 commit intomainfrom
Open
Fix: Add TypeScript transformer to runtime Jest config#2011mohammedahmed18 wants to merge 1 commit intomainfrom
mohammedahmed18 wants to merge 1 commit intomainfrom
Conversation
**Problem:**
When Jest base config is TypeScript (.ts file), all TypeScript tests fail
with syntax errors like "Unexpected token, expected ','". This affects 23
out of 45 optimization runs (~51%).
**Root Cause:**
The _create_runtime_jest_config() function creates a standalone config when
base config is .ts (cannot be directly required by Node.js). This standalone
config was missing the TypeScript transformer configuration entirely, so Jest
tried to execute TypeScript code as plain JavaScript.
**Error:**
```
SyntaxError: Unexpected token, expected "," (37:45)
> 37 | export function addDatasourceFlags(datasource: Datasource) {
| ^
```
**Fix:**
Added TypeScript transformer detection to standalone config creation path:
- Call _detect_typescript_transformer() to find ts-jest/@swc/jest/babel
- Inject transform config into the standalone runtime Jest config
- Preserves existing behavior when transformer is not available
**Files Changed:**
- codeflash/languages/javascript/test_runner.py (12 lines added)
- tests/test_languages/test_typescript_runtime_config_transform.py (new, 137 lines)
**Testing:**
- 4 new unit tests for transform injection with ts-jest, @swc/jest, babel
- All 34 existing test_runner tests pass
- No linting/type errors
**Impact:** Fixes TypeScript optimizations for all projects using .ts Jest configs
**Trace IDs:** 1f944efe-bdab-4f1e-81cc-19189023c81a (and 22 others)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When Jest base config is TypeScript (
.tsfile), all TypeScript tests fail with syntax errors. This affects 23 out of 45 logs (~51%) - a systematic high-severity bug blocking all TypeScript optimizations.Error:
Root Cause
The
_create_runtime_jest_config()function creates a standalone config when the base config is.ts(cannot be directly required by Node.js). This standalone config was missing the TypeScript transformer configuration entirely.Bug location:
codeflash/languages/javascript/test_runner.py:668-696Flow:
jest.config.ts(TypeScript)_create_runtime_jest_config()detects.tsextension (line 642)roots,testMatch,moduleNameMappertransformconfiguration → Jest cannot parse TypeScript → Syntax errorsFix
Added TypeScript transformer detection to standalone config creation path:
_detect_typescript_transformer()to find ts-jest/@swc/jest/babelFiles Changed
codeflash/languages/javascript/test_runner.py(12 lines added at lines 688-699)tests/test_languages/test_typescript_runtime_config_transform.py(new file, 137 lines, 4 tests)Testing
✅ 4 new regression tests:
test_runtime_config_includes_typescript_transform_with_ts_jesttest_runtime_config_includes_typescript_transform_with_swctest_runtime_config_includes_typescript_transform_with_babel_fallbacktest_runtime_config_no_transform_when_no_typescript_transformer✅ All 34 existing
test_javascript_test_runner.pytests pass✅ No linting/type errors (
uv run prekpasses)Impact
Severity: HIGH
Fixes: 23 out of 45 failing optimization runs (~51%)
Trace IDs: 1f944efe-bdab-4f1e-81cc-19189023c81a (and 22 others)
Unblocks all TypeScript optimizations for projects using
.tsJest configs.Verification
Before fix (runtime config):
After fix (runtime config):