Skip to content

Commit 4766daa

Browse files
Saga4claude
andcommitted
fix: regenerate stale vitest config and add .js extension for ESM imports
Two fixes discovered during end-to-end testing: 1. _ensure_codeflash_vitest_config() reused existing configs that lacked pool: 'forks', causing benchmarking to fall back to wall-clock timing on re-runs. Now checks for the required setting and regenerates if missing. 2. ESM projects require explicit .js file extensions in import specifiers (e.g., `import foo from './lib/foo.js'`). The verifier stripped the extension but never added .js back for ESM, causing ERR_MODULE_NOT_FOUND in Mocha ESM projects like axios. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e8a4f96 commit 4766daa

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

codeflash/languages/javascript/vitest_runner.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,13 @@ def _ensure_codeflash_vitest_config(project_root: Path) -> Path | None:
194194

195195
codeflash_config_path = project_root / "codeflash.vitest.config.mjs"
196196

197-
# If already exists, use it
197+
# Regenerate if existing config is missing required settings (e.g., pool: 'forks')
198198
if codeflash_config_path.exists():
199-
logger.debug(f"Using existing Codeflash Vitest config: {codeflash_config_path}")
200-
return codeflash_config_path
199+
existing_content = codeflash_config_path.read_text(encoding="utf-8")
200+
if "pool: 'forks'" in existing_content:
201+
logger.debug(f"Using existing Codeflash Vitest config: {codeflash_config_path}")
202+
return codeflash_config_path
203+
logger.debug("Regenerating Codeflash Vitest config (missing pool: 'forks')")
201204

202205
# Find the original vitest config to extend
203206
original_config = None

codeflash/verification/verifier.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def generate_tests(
5252
# Ensure path starts with ./ or ../ for JavaScript/TypeScript imports
5353
if not rel_import_path.startswith("../"):
5454
rel_import_path = f"./{rel_import_path}"
55+
# ESM requires explicit file extensions in import specifiers.
56+
# TypeScript ESM also uses .js extensions (TS resolves .js → .ts).
57+
if project_module_system == "esm":
58+
rel_import_path += ".js"
5559
# Keep as string since Path() normalizes away the ./ prefix
5660
module_path = rel_import_path
5761

0 commit comments

Comments
 (0)