Skip to content

fix(js): resolve Jest testMatch/testRegex configuration conflict#1978

Merged
Saga4 merged 1 commit intomainfrom
fix/jest-testmatch-testregex-conflict
Apr 3, 2026
Merged

fix(js): resolve Jest testMatch/testRegex configuration conflict#1978
Saga4 merged 1 commit intomainfrom
fix/jest-testmatch-testregex-conflict

Conversation

@mohammedahmed18
Copy link
Copy Markdown
Contributor

Problem

When optimizing JavaScript/TypeScript projects with bundler moduleResolution, Jest would fail immediately with a configuration validation error:

Validation Error: Configuration options testMatch and testRegex cannot be used together.

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:

  1. _create_codeflash_jest_config() creates a base config that includes testRegex (line 321)
  2. _create_runtime_jest_config() extends this base config using spread operator:
    module.exports = {
      ...baseConfig,  // This spreads all properties, including testRegex!
      testMatch: ['**/*.test.ts', ...],  // Then adds testMatch - CONFLICT!
    }
  3. Jest's validation rejects configs with both testMatch and testRegex

Solution

Explicitly set testRegex: undefined in the runtime config to override the inherited value:

module.exports = {
  ...baseConfig,
  testMatch: ['**/*.test.ts', ...],
  testRegex: undefined,  // Clear inherited testRegex to avoid conflict
}

Jest's config merging allows explicit undefined to override inherited values.

Testing

Before fix:

❌ Jest failed with returncode=1.
   Validation Error: Configuration options testMatch and testRegex cannot be used together.

After fix:

✅ Jest runs without configuration errors
✅ Validation passes
✅ Can proceed to test execution

Tested on n8n packages/workflow which uses bundler moduleResolution in TypeScript.

Impact

Fixes JavaScript/TypeScript optimization for projects that:

  • Use TypeScript with moduleResolution: "bundler" (increasingly common in modern TypeScript projects)
  • Trigger Codeflash's ESM compatibility config generation
  • Use Jest as the test framework

Without this fix, these projects cannot be optimized at all.

Files Changed

  • codeflash/languages/javascript/test_runner.py - Added testRegex: undefined in _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).

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.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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
Copy link
Copy Markdown
Contributor

claude bot commented Apr 2, 2026

Claude finished @mohammedahmed18's task in 2m 10s —— View job


PR Review Summary

Prek Checks

Prek passes (ruff check + format). Mypy errors in test_runner.py are pre-existing and unrelated to this change.

Code Review

Size: SMALL (1 line)

The fix is correct and well-targeted. When _create_runtime_jest_config() spreads baseConfig (which may contain testRegex from _create_codeflash_jest_config()), adding testRegex: undefined at test_runner.py:396 overrides the inherited key and prevents Jest from seeing both testMatch and testRegex set simultaneously.

One concern — missing test:

Per the project's testing guidelines, bug fixes must include a test. The existing tests for _create_runtime_jest_config (at tests/test_languages/test_javascript_test_runner.py:1061) check moduleDirectories behavior but none verify the testRegex: undefined override.

A test should be added that:

  1. Creates a base Jest config containing testRegex
  2. Calls _create_runtime_jest_config() with that base config
  3. Asserts the generated content includes testRegex: undefined

Fix this →

Duplicate Detection

No duplicates detected. The else branch (no base_config_path, line ~400) correctly omits testRegex entirely since there's no base config to inherit from — so the fix only needs to be in the if base_config_path branch.


Last updated: 2026-04-02

@Saga4 Saga4 merged commit 61a539f into main Apr 3, 2026
25 of 28 checks passed
@Saga4 Saga4 deleted the fix/jest-testmatch-testregex-conflict branch April 3, 2026 11:18
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.

3 participants