fix(js): detect TypeScript transformers beyond ts-jest#2003
fix(js): detect TypeScript transformers beyond ts-jest#2003mohammedahmed18 wants to merge 2 commits intomainfrom
Conversation
**Problem:** When a TypeScript project uses transformers other than ts-jest (e.g., @swc/jest, babel-jest, esbuild-jest), Codeflash would generate a Jest config without a transform directive. This caused Jest to fail parsing TypeScript files with syntax errors like "Unexpected token" at type annotations. **Root Cause:** File: codeflash/languages/javascript/test_runner.py:282-295 The code only checked for ts-jest in package.json and skipped transform configuration when ts-jest was not found, even though other TypeScript transformers might be present. **Solution:** Added _detect_typescript_transformer() function that checks for common TypeScript transformers in order of preference: 1. ts-jest 2. @swc/jest 3. babel-jest (with @babel/preset-typescript) 4. esbuild-jest When detected, the appropriate transform directive is included in the generated Jest config, enabling Jest to parse TypeScript files. **Impact:** - Fixes optimization failures for TypeScript projects using @swc/jest (e.g., budibase) - Fixes optimization failures for TypeScript projects using babel-jest - Fixes optimization failures for TypeScript projects using esbuild-jest - Maintains backward compatibility with ts-jest projects **Testing:** - Added test_typescript_transform_extraction.py with two test cases - All existing test_javascript_test_runner.py tests pass (34 tests) **Trace IDs:** - 0acc4768-706a-4fe1-91e6-ec64983bd519 (budibase API.patch optimization) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Claude finished @mohammedahmed18's task in 4m 40s —— View job PR Review Summary
Prek ChecksPassed. ✅ Auto-fixed and pushed (
Code ReviewBug / Dead Code — must fix
The PR replaces all call sites of Design Issue — consider fixingTriplicate package.json parsing for ts-jest ( There are now three separate functions that each open
Minor — no action neededThe Duplicate Detection
Test CoverageTwo integration tests added covering Last updated: 2026-04-06T11:49Z |
- Use tmp_path fixture instead of tempfile.TemporaryDirectory (project convention) - Add -> None return type annotations to test methods - Add encoding="utf-8" to read_text/write_text calls in new code - Remove docstring from _detect_typescript_transformer (project style) - Remove unused import pytest from test file Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
Problem
When a TypeScript project uses transformers other than
ts-jest(e.g.,@swc/jest,babel-jest,esbuild-jest), Codeflash generates a Jest config without atransformdirective. This causes Jest to fail parsing TypeScript files with syntax errors like "Unexpected token" at type annotations.Example error:
Root Cause
File:
codeflash/languages/javascript/test_runner.py:282-295The code only checked for
ts-jestinpackage.jsonand skipped transform configuration whents-jestwas not found, even though other TypeScript transformers might be present:Solution
Added
_detect_typescript_transformer()function that checks for common TypeScript transformers in order of preference:ts-jest@swc/jestbabel-jest(with@babel/preset-typescript)esbuild-jestWhen detected, the appropriate transform directive is included in the generated Jest config.
Impact
✅ Fixes: TypeScript projects using
@swc/jest(e.g., budibase)✅ Fixes: TypeScript projects using
babel-jest✅ Fixes: TypeScript projects using
esbuild-jest✅ Maintains: Backward compatibility with
ts-jestprojectsTesting
test_typescript_transform_extraction.pywith two test casestest_javascript_test_runner.pytests pass (34 tests)0acc4768-706a-4fe1-91e6-ec64983bd519Trace IDs
0acc4768-706a-4fe1-91e6-ec64983bd519- budibaseAPI.patchoptimization failure