Skip to content

Fix SyntaxError when requiring TypeScript Jest configs#2005

Open
mohammedahmed18 wants to merge 1 commit intomainfrom
fix/typescript-jest-config-require
Open

Fix SyntaxError when requiring TypeScript Jest configs#2005
mohammedahmed18 wants to merge 1 commit intomainfrom
fix/typescript-jest-config-require

Conversation

@mohammedahmed18
Copy link
Copy Markdown
Contributor

Problem

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:

SyntaxError: Missing initializer in const declaration
    at Object.<anonymous> (/workspace/target/packages/server/jest.config.runtime.js:2:20)

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

  • ✅ Added comprehensive unit test covering both TypeScript and JavaScript base configs
  • ✅ All existing tests pass (34 tests in test_javascript_test_runner.py)
  • ✅ Linter and type checker pass
  • ✅ Verified fix works on actual budibase project with jest.config.ts

Impact

  • Severity: HIGH - Blocking issue for all TypeScript projects using jest.config.ts
  • Affected logs: Trace IDs 27858c5b, 85b25ecc (and likely many others in budibase run)
  • Projects affected: Any project with TypeScript Jest config (increasingly common)

Files Changed

  • codeflash/languages/javascript/test_runner.py - Skip TypeScript configs, create standalone config
  • tests/test_languages/test_typescript_jest_config_require_bug.py - New test file

🤖 Generated with autonomous debugging agent (autoresearch:debug)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant