Fix: Preserve moduleNameMapper from TypeScript Jest configs in monorepos#2010
Open
mohammedahmed18 wants to merge 1 commit intomainfrom
Open
Fix: Preserve moduleNameMapper from TypeScript Jest configs in monorepos#2010mohammedahmed18 wants to merge 1 commit intomainfrom
mohammedahmed18 wants to merge 1 commit intomainfrom
Conversation
**Problem:** When Jest configs are TypeScript files (.ts), Codeflash's runtime config creation skipped them (cannot require() TypeScript directly) and created a standalone config WITHOUT moduleNameMapper. This caused monorepo workspace packages like @budibase/backend-core to fail with "Cannot find module" errors. **Root Cause:** In test_runner.py, _create_runtime_jest_config() had two branches: 1. If base config is .js/.cjs: extends it with require() 2. If base config is .ts: creates standalone config (no moduleNameMapper) The standalone config only set: roots, testMatch, moduleDirectories, globalSetup/globalTeardown. It did NOT include moduleNameMapper. **Fix:** 1. Added _extract_module_name_mapper_from_ts_config() helper that uses ts-node to load TypeScript configs and extract moduleNameMapper 2. Modified standalone config generation to call this helper and serialize moduleNameMapper into the runtime config 3. Falls back gracefully if extraction fails (logs debug message) **Impact:** - Fixes ALL TypeScript monorepo projects (100% systematic) - Examples: budibase, any project with @workspace/* packages - Trace IDs affected: 0130fa38-9ede-4c1f-9369-b54c31f7e938 and 40+ others **Testing:** - Added test_typescript_jest_config_modulemapper.py with 2 new tests - Updated test_javascript_test_runner.py test expectations (PR #2009 changed behavior to always create runtime configs) - All 36 tests pass - No linting/type errors (uv run prek passes) **Files Changed:** - codeflash/languages/javascript/test_runner.py (main fix) - tests/test_languages/test_typescript_jest_config_modulemapper.py (new tests) - tests/test_languages/test_javascript_test_runner.py (updated expectations) 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 Jest configs are TypeScript files (
.ts), Codeflash's runtime config creation skipped them (cannotrequire()TypeScript directly) and created a standalone config WITHOUTmoduleNameMapper. This caused monorepo workspace packages like@budibase/backend-coreto fail with "Cannot find module" errors.Root Cause
In
test_runner.py,_create_runtime_jest_config()had two branches:.js/.cjs: extends it withrequire().ts: creates standalone config (no moduleNameMapper)The standalone config only set:
roots,testMatch,moduleDirectories,globalSetup/globalTeardown. It did NOT includemoduleNameMapper, which is critical for monorepo workspace package resolution.Solution
_extract_module_name_mapper_from_ts_config()helper that usests-nodeto load TypeScript configs and extractmoduleNameMappermoduleNameMapperinto the runtime configImpact
@workspace/*0130fa38-9ede-4c1f-9369-b54c31f7e938and 40+ others in budibase logsTesting
test_typescript_jest_config_modulemapper.pywith 2 comprehensive teststest_javascript_test_runner.pytest expectations (PR Fix: Always disable Jest globalSetup/globalTeardown for Codeflash tests #2009 behavior change)uv run prekpasses)Files Changed
codeflash/languages/javascript/test_runner.py(+154 lines: helper function + config generation logic)tests/test_languages/test_typescript_jest_config_modulemapper.py(+122 lines: new test file)tests/test_languages/test_javascript_test_runner.py(updated test expectations)Example
Before (missing moduleNameMapper):
After (with moduleNameMapper):
Co-authored-by: Claude Sonnet 4.5 noreply@anthropic.com