Skip to content

Commit 5b84811

Browse files
small fixes
1 parent e1860a5 commit 5b84811

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

codeflash/languages/javascript/support.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,8 @@ def setup_test_config(self, test_cfg: TestConfig, file_path: Path, current_workt
19631963
from codeflash.languages.javascript.test_runner import find_node_project_root
19641964

19651965
test_cfg.js_project_root = find_node_project_root(file_path)
1966+
if test_cfg.js_project_root is None:
1967+
return False
19661968
if current_worktree is not None:
19671969
original_js_root = git_root_dir()
19681970
worktree_node_modules = test_cfg.js_project_root / "node_modules"
@@ -2248,7 +2250,7 @@ def verify_requirements(self, project_root: Path, test_framework: str = "jest")
22482250
Tuple of (success, list of error messages).
22492251
22502252
"""
2251-
errors: list[str] = []
2253+
errors: list[SetupError] = []
22522254

22532255
# Check Node.js
22542256
try:

tests/test_languages/test_javascript_requirements.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,44 @@ def test_verify_requirements_jest_not_installed(self, js_support, project_with_v
177177
assert errors[0].message == expected_message
178178

179179

180+
class TestSetupTestConfig:
181+
"""Tests for JavaScriptSupport.setup_test_config() early-exit behavior."""
182+
183+
@pytest.fixture
184+
def js_support(self):
185+
return JavaScriptSupport()
186+
187+
def test_setup_test_config_returns_false_on_abort_error(self, js_support, tmp_path):
188+
"""setup_test_config returns False when verify_js_requirements reports a should_abort error."""
189+
from codeflash.languages.base import SetupError
190+
191+
abort_error = SetupError("Node.js is not installed", should_abort=True)
192+
with (
193+
patch("codeflash.languages.javascript.test_runner.find_node_project_root", return_value=tmp_path.resolve()),
194+
patch("codeflash.languages.javascript.optimizer.verify_js_requirements", return_value=[abort_error]),
195+
):
196+
test_cfg = MagicMock()
197+
result = js_support.setup_test_config(test_cfg, tmp_path.resolve(), current_worktree=None)
198+
assert result is False
199+
200+
def test_setup_test_config_returns_true_on_no_errors(self, js_support, tmp_path):
201+
"""setup_test_config returns True when verify_js_requirements reports no errors."""
202+
with (
203+
patch("codeflash.languages.javascript.test_runner.find_node_project_root", return_value=tmp_path.resolve()),
204+
patch("codeflash.languages.javascript.optimizer.verify_js_requirements", return_value=[]),
205+
):
206+
test_cfg = MagicMock()
207+
result = js_support.setup_test_config(test_cfg, tmp_path.resolve(), current_worktree=None)
208+
assert result is True
209+
210+
def test_setup_test_config_returns_false_when_project_root_is_none(self, js_support, tmp_path):
211+
"""setup_test_config returns False when find_node_project_root returns None."""
212+
with patch("codeflash.languages.javascript.test_runner.find_node_project_root", return_value=None):
213+
test_cfg = MagicMock()
214+
result = js_support.setup_test_config(test_cfg, tmp_path.resolve(), current_worktree=None)
215+
assert result is False
216+
217+
180218
class TestVerifyRequirementsIntegration:
181219
"""Integration tests for verify_requirements with real filesystem."""
182220

0 commit comments

Comments
 (0)