Skip to content

Commit 17c733f

Browse files
github-actions[bot]mohammed ahmedclaude
committed
fix: correct runtime jest config bugs
- Add encoding="utf-8" to write_text (CLAUDE.md requirement) - Fix return type to Path | None and return None on write failure with no base config - Replace startswith path prefix check with Path.is_relative_to() Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ad0bc08 commit 17c733f

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

codeflash/languages/javascript/test_runner.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def _create_codeflash_jest_config(
339339
return None
340340

341341

342-
def _create_runtime_jest_config(base_config_path: Path | None, project_root: Path, test_dirs: set[str]) -> Path:
342+
def _create_runtime_jest_config(base_config_path: Path | None, project_root: Path, test_dirs: set[str]) -> Path | None:
343343
"""Create a runtime Jest config that includes test directories in roots and testMatch.
344344
345345
This is needed because test files generated by codeflash may be placed
@@ -393,16 +393,15 @@ def _create_runtime_jest_config(base_config_path: Path | None, project_root: Pat
393393
"""
394394

395395
try:
396-
runtime_config_path.write_text(config_content)
396+
runtime_config_path.write_text(config_content, encoding="utf-8")
397397
_created_config_files.add(runtime_config_path)
398398
logger.debug(f"Created runtime Jest config with test roots: {runtime_config_path}")
399399
except Exception as e:
400400
logger.warning(f"Failed to create runtime Jest config: {e}")
401401
# Fall back to base config
402402
if base_config_path:
403403
return base_config_path
404-
# Return a dummy path that won't be used (caller checks for None)
405-
return runtime_config_path
404+
return None
406405

407406
return runtime_config_path
408407

@@ -786,9 +785,9 @@ def run_jest_behavioral_tests(
786785
# This is necessary because Jest's testMatch patterns use <rootDir> which
787786
# resolves to the config file's directory, excluding external test files.
788787
if test_files:
788+
resolved_root = effective_cwd.resolve()
789789
test_dirs = {str(Path(f).resolve().parent) for f in test_files}
790-
project_root_str = str(effective_cwd.resolve())
791-
if any(not d.startswith(project_root_str) for d in test_dirs):
790+
if any(not Path(d).is_relative_to(resolved_root) for d in test_dirs):
792791
jest_config = _create_runtime_jest_config(jest_config, effective_cwd, test_dirs)
793792

794793
if jest_config:
@@ -1038,9 +1037,9 @@ def run_jest_benchmarking_tests(
10381037

10391038
# If test files are outside the project root, create a runtime wrapper config
10401039
if test_files:
1040+
resolved_root = effective_cwd.resolve()
10411041
test_dirs = {str(Path(f).resolve().parent) for f in test_files}
1042-
project_root_str = str(effective_cwd.resolve())
1043-
if any(not d.startswith(project_root_str) for d in test_dirs):
1042+
if any(not Path(d).is_relative_to(resolved_root) for d in test_dirs):
10441043
jest_config = _create_runtime_jest_config(jest_config, effective_cwd, test_dirs)
10451044

10461045
if jest_config:
@@ -1207,9 +1206,9 @@ def run_jest_line_profile_tests(
12071206

12081207
# If test files are outside the project root, create a runtime wrapper config
12091208
if test_files:
1209+
resolved_root = effective_cwd.resolve()
12101210
test_dirs = {str(Path(f).resolve().parent) for f in test_files}
1211-
project_root_str = str(effective_cwd.resolve())
1212-
if any(not d.startswith(project_root_str) for d in test_dirs):
1211+
if any(not Path(d).is_relative_to(resolved_root) for d in test_dirs):
12131212
jest_config = _create_runtime_jest_config(jest_config, effective_cwd, test_dirs)
12141213

12151214
if jest_config:

0 commit comments

Comments
 (0)