fix(js): resolve Jest testMatch/testRegex configuration conflict#1978
fix(js): resolve Jest testMatch/testRegex configuration conflict#1978
Conversation
Fix Jest validation error that prevented all TypeScript/JavaScript optimizations
in projects using bundler moduleResolution.
## Problem
When optimizing JS/TS projects with bundler moduleResolution, Jest would fail with:
This blocked ALL optimizations for these projects since no tests could run.
## Root Cause
Two-stage Jest config generation caused conflicting options:
1. \_create_codeflash_jest_config() creates base config with `testRegex` (line 321)
2. \_create_runtime_jest_config() extends base config:
```javascript
module.exports = {
...baseConfig, // Spreads testRegex from base
testMatch: [...], // Adds testMatch - CONFLICT!
}
```
3. Jest sees both options and rejects the configuration
## Solution
Explicitly clear `testRegex` when setting `testMatch` in runtime config:
```javascript
testMatch: ['**/*.test.ts', ...],
testRegex: undefined, // Clear inherited testRegex
```
Jest config precedence allows explicit `undefined` to override inherited values.
## Testing
Before:
```
❌ Jest failed with returncode=1.
Validation Error: Configuration options testMatch and testRegex cannot be used together.
```
After:
```
✅ Jest runs without configuration errors
✅ Config validation passes
```
Tested on n8n packages/workflow which uses bundler moduleResolution.
## Impact
- Fixes all JS/TS projects that use:
- TypeScript with bundler moduleResolution (common in modern repos)
- Projects where Codeflash detects the need for ESM compatibility config
- Allows optimization to proceed past configuration stage
## Files Changed
- `codeflash/languages/javascript/test_runner.py` - _create_runtime_jest_config()
Fixes issue where TypeScript projects with bundler moduleResolution
would immediately fail Jest validation, preventing any optimizations.
|
Codeflash Bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Claude finished @mohammedahmed18's task in 2m 10s —— View job PR Review SummaryPrek ChecksPrek passes (ruff check + format). Mypy errors in Code ReviewSize: SMALL (1 line) The fix is correct and well-targeted. When One concern — missing test: Per the project's testing guidelines, bug fixes must include a test. The existing tests for A test should be added that:
Duplicate DetectionNo duplicates detected. The Last updated: 2026-04-02 |
Problem
When optimizing JavaScript/TypeScript projects with bundler moduleResolution, Jest would fail immediately with a configuration validation error:
This blocked ALL optimizations for affected projects since no tests could run to establish a behavioral baseline.
Root Cause
Two-stage Jest config generation caused conflicting options:
_create_codeflash_jest_config()creates a base config that includestestRegex(line 321)_create_runtime_jest_config()extends this base config using spread operator:testMatchandtestRegexSolution
Explicitly set
testRegex: undefinedin the runtime config to override the inherited value:Jest's config merging allows explicit
undefinedto override inherited values.Testing
Before fix:
After fix:
Tested on n8n
packages/workflowwhich uses bundler moduleResolution in TypeScript.Impact
Fixes JavaScript/TypeScript optimization for projects that:
moduleResolution: "bundler"(increasingly common in modern TypeScript projects)Without this fix, these projects cannot be optimized at all.
Files Changed
codeflash/languages/javascript/test_runner.py- AddedtestRegex: undefinedin_create_runtime_jest_config()Related
This fix resolves the configuration conflict, but there may be additional test result parsing issues to investigate separately (XML format compatibility).