Fix SyntaxError when requiring TypeScript Jest configs#2005
Open
mohammedahmed18 wants to merge 1 commit intomainfrom
Open
Fix SyntaxError when requiring TypeScript Jest configs#2005mohammedahmed18 wants to merge 1 commit intomainfrom
mohammedahmed18 wants to merge 1 commit intomainfrom
Conversation
When a project uses jest.config.ts (TypeScript), the generated runtime
config was trying to require('./jest.config.ts'), which fails because
Node.js cannot directly require TypeScript files without a loader.
This caused a SyntaxError: Missing initializer in const declaration,
preventing optimization of any functions in projects with TypeScript
Jest configs.
**Root Cause:**
In _create_runtime_jest_config(), the code always attempted to require
the base config file regardless of its extension. TypeScript files need
a loader (like ts-node) to be required, which is not available in the
generated runtime config context.
**Fix:**
Check if base_config_path.suffix == ".ts" and skip requiring it if true.
Create a standalone config instead, which is functionally equivalent for
Codeflash's purposes (setting test roots and testMatch patterns).
**Testing:**
- Added comprehensive unit test covering both TypeScript and JavaScript
base configs
- All existing tests pass
- Verified fix works on actual budibase project with jest.config.ts
Fixes trace IDs: 27858c5b, 85b25ecc (and likely many 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 a project uses
jest.config.ts(TypeScript), the generated runtime config was trying torequire('./jest.config.ts'), which fails because Node.js cannot directly require TypeScript files without a loader.This caused:
This prevented optimization of any functions in projects with TypeScript Jest configs.
Root Cause
In
_create_runtime_jest_config(), the code always attempted to require the base config file regardless of its extension. TypeScript files need a loader (like ts-node) to be required, which is not available in the generated runtime config context.Solution
Check if
base_config_path.suffix == ".ts"and skip requiring it if true. Create a standalone config instead, which is functionally equivalent for Codeflash's purposes (setting test roots and testMatch patterns).Testing
Impact
jest.config.tsFiles Changed
codeflash/languages/javascript/test_runner.py- Skip TypeScript configs, create standalone configtests/test_languages/test_typescript_jest_config_require_bug.py- New test file🤖 Generated with autonomous debugging agent (autoresearch:debug)