Skip to content

fix(js): pass project Jest config for TypeScript transformation#1244

Merged
Saga4 merged 3 commits intomainfrom
fix/jest-config-for-typescript
Feb 2, 2026
Merged

fix(js): pass project Jest config for TypeScript transformation#1244
Saga4 merged 3 commits intomainfrom
fix/jest-config-for-typescript

Conversation

@misrasaurabh1
Copy link
Contributor

Summary

  • Fixed Jest test failures on TypeScript projects by passing the project's Jest config file
  • Added _find_jest_config() function to locate Jest config in project and parent directories
  • Supports monorepos where Jest config is at repository root, not package root

Problem

When running codeflash on TypeScript projects like next.js, generated tests were failing with:

Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Root Cause

The Jest test runner functions (run_jest_behavioral_tests, run_jest_benchmarking_tests, run_jest_line_profile_tests) were not passing a --config flag to Jest, causing it to run without the project's TypeScript transformation configuration.

Solution

  1. Added _find_jest_config() function that:

    • Searches for common Jest config files (jest.config.ts/js/mjs/cjs/json)
    • Searches parent directories for monorepo support (up to 5 levels)
    • Stops at git root or monorepo root (package.json with workspaces)
  2. Updated all three Jest runner functions to pass --config={path} when a config is found

Test plan

  • Tested against next.js monorepo where jest.config.js is at repo root
  • Verified Jest config is found in parent directory for packages/next

🤖 Generated with Claude Code

misrasaurabh1 and others added 2 commits February 1, 2026 23:35
When running generated tests on TypeScript projects, Jest was failing
with "unexpected token" errors because it wasn't configured to transform
TypeScript files. The tests were being run without the project's Jest
config file.

This fix:
- Adds `_find_jest_config()` function to locate Jest config files
- Searches project root and parent directories (for monorepo support)
- Passes `--config` flag to Jest in all test runner functions
- Stops search at git root or monorepo root (package.json with workspaces)

Tested against next.js (monorepo) where jest.config.js is at repo root
but packages are in nested directories.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@misrasaurabh1 misrasaurabh1 requested a review from Saga4 February 2, 2026 01:30
@Saga4
Copy link
Contributor

Saga4 commented Feb 2, 2026

Can add test for finding the jest config with a tmp project.

@Saga4 Saga4 merged commit 7c4a194 into main Feb 2, 2026
23 of 27 checks passed
@Saga4 Saga4 deleted the fix/jest-config-for-typescript branch February 2, 2026 11:38
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.

2 participants