Skip to content

Commit 4803f26

Browse files
Merge pull request #1231 from codeflash-ai/js-tests-root
Accept tests root in package.json config
2 parents 6f49b2c + d247ba8 commit 4803f26

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

codeflash/cli_cmds/init_javascript.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from codeflash.code_utils.git_utils import get_git_remotes
2727
from codeflash.code_utils.shell_utils import get_shell_rc_path, is_powershell
2828
from codeflash.telemetry.posthog_cf import ph
29+
from rich.prompt import Confirm
2930

3031

3132
class ProjectLanguage(Enum):
@@ -208,9 +209,7 @@ def init_js_project(language: ProjectLanguage) -> None:
208209

209210
def should_modify_package_json_config() -> tuple[bool, dict[str, Any] | None]:
210211
"""Check if package.json has valid codeflash config for JS/TS projects."""
211-
from rich.prompt import Confirm
212-
213-
package_json_path = Path.cwd() / "package.json"
212+
package_json_path = Path("package.json")
214213

215214
if not package_json_path.exists():
216215
click.echo("❌ No package.json found. Please run 'npm init' first.")
@@ -230,6 +229,10 @@ def should_modify_package_json_config() -> tuple[bool, dict[str, Any] | None]:
230229
if not Path(module_root).is_dir():
231230
return True, None
232231

232+
tests_root = config.get("testsRoot", None)
233+
if tests_root and not Path(tests_root).is_dir():
234+
return True, None
235+
233236
# Config is valid - ask if user wants to reconfigure
234237
return Confirm.ask(
235238
"✅ A valid Codeflash config already exists in package.json. Do you want to re-configure it?",

codeflash/code_utils/config_js.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ def parse_package_json_config(package_json_path: Path) -> tuple[dict[str, Any],
251251
detected_module_root = detect_module_root(project_root, package_data)
252252
config["module_root"] = str((project_root / Path(detected_module_root)).resolve())
253253

254+
if codeflash_config.get("testsRoot"):
255+
config["tests_root"] = str(project_root / Path(codeflash_config["testsRoot"]).resolve())
256+
254257
# Auto-detect test runner
255258
config["test_runner"] = detect_test_runner(project_root, package_data)
256259
# Keep pytest_cmd for backwards compatibility with existing code

codeflash/setup/config_schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def to_package_json_dict(self) -> dict[str, Any]:
103103
if self.module_root and self.module_root not in (".", "src"):
104104
config["moduleRoot"] = self.module_root
105105

106+
if self.tests_root:
107+
config["testsRoot"] = self.tests_root
108+
106109
# Formatter (only if explicitly set)
107110
if self.formatter_cmds:
108111
config["formatterCmds"] = self.formatter_cmds

0 commit comments

Comments
 (0)