Fix Jest runtime config failing to load TypeScript base configs#1992
Fix Jest runtime config failing to load TypeScript base configs#1992
Conversation
**Problem**: When a project uses `jest.config.ts` (TypeScript config), the
generated runtime config tries to `require('./jest.config.ts')`, which fails
because Node.js CommonJS cannot parse TypeScript syntax without compilation.
**Error**: `SyntaxError: Missing initializer in const declaration` at the
TypeScript type annotation (e.g., `const config: Config = ...`).
**Impact**: Affected 18 out of 38 optimization runs (~47%) in initial testing.
All TypeScript projects using `jest.config.ts` were unable to run tests.
**Root Cause**: Line 386 in test_runner.py used `base_config_path.name`
directly without checking the extension. The generated runtime config is
always a `.js` file, so it cannot use `require()` on `.ts` files.
**Solution**: Check if `base_config_path` is a TypeScript file (.ts). If so,
create a standalone runtime config without trying to extend it via require().
Jest will still discover and use the original TypeScript config naturally.
**Testing**:
- Added comprehensive test in test_jest_typescript_config_bug.py
- Test creates a realistic TypeScript Jest config and verifies the generated
runtime config loads without syntax errors
- Existing 34 JavaScript test runner tests still pass
- No linting/type errors from `uv run prek`
**Trace IDs affected**: 0fd176bf-5c7f-4f41-8396-77c46be86412 and 17 others
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Claude finished @mohammedahmed18's task in 2m 29s —— View job PR Review SummaryPR size: SMALL — 5 lines of production code changed ( Prek Checks
Code ReviewThe core fix is correct. Adding Issues found: 1. Testing convention violation —
|
Problem
When a project uses
jest.config.ts(TypeScript config), the generated runtime config tries torequire('./jest.config.ts'), which fails because Node.js CommonJS cannot parse TypeScript syntax without compilation.Error message:
Impact
jest.config.tsRoot Cause
Line 386 in
codeflash/languages/javascript/test_runner.pyusedbase_config_path.namedirectly without checking the file extension. The generated runtime config is always a.jsfile (CommonJS), so it cannot userequire()on.tsfiles.Before:
After:
Solution
Check if
base_config_pathis a TypeScript file (.ts). If so, create a standalone runtime config without trying to extend it viarequire(). Jest will still discover and use the original TypeScript config naturally through its own resolution mechanism.Testing
✅ Added comprehensive test in
test_jest_typescript_config_bug.py✅ All existing tests pass:
uv run prekVerification
To reproduce the original issue and verify the fix:
cd /workspace/target codeflash --file packages/backend-core/src/users/utils.ts \ --function isCreatorSync \ --rerun 0fd176bf-5c7f-4f41-8396-77c46be86412Before fix: Tests fail with "SyntaxError: Missing initializer in const declaration"
After fix: Tests run successfully
🤖 Generated with autonomous debug loop (iteration 1/20)