""" Python Integration Tests for JavaScript Bridge Tests the Python-JavaScript bridge functionality to ensure JavaScript tests can be executed from Python test suite. """ import pytest from testdrive_jsui.testing import JavaScriptTestRunner, PythonJSBridge class TestJavaScriptBridge: """Test the JavaScript test execution bridge.""" def test_javascript_test_runner_initialization(self): """Test that JavaScriptTestRunner can be initialized properly.""" runner = JavaScriptTestRunner() assert runner is not None assert hasattr(runner, 'run_js_tests') assert hasattr(runner, 'check_node_environment') def test_node_environment_available(self): """Test that Node.js environment is properly detected.""" runner = JavaScriptTestRunner() node_available = runner.check_node_environment() assert node_available is True, "Node.js environment should be available" def test_get_test_info(self): """Test that test environment information can be retrieved.""" runner = JavaScriptTestRunner() info = runner.get_test_info() assert isinstance(info, dict) assert 'node_available' in info assert 'package_json_exists' in info assert 'available_tests' in info assert 'capability_root' in info assert info['node_available'] is True assert info['package_json_exists'] is True def test_list_available_tests(self): """Test that available JavaScript tests can be listed.""" runner = JavaScriptTestRunner() tests = runner.list_available_tests() assert isinstance(tests, list) # Should find at least our Jest test files test_files = [t for t in tests if t.endswith('.test.js')] assert len(test_files) > 0, f"Should find Jest test files, got: {tests}" @pytest.mark.javascript def test_run_javascript_tests(self): """Test that JavaScript tests can be executed successfully.""" runner = JavaScriptTestRunner() result = runner.run_js_tests(verbose=True) assert result is not None assert hasattr(result, 'success') assert hasattr(result, 'tests_passed') assert hasattr(result, 'tests_total') # Tests should pass assert result.success is True, f"JavaScript tests failed: {result.failures}" assert result.tests_passed > 0, "Should have passing tests" assert result.tests_total > 0, "Should have executed tests" @pytest.mark.javascript def test_run_specific_javascript_test(self): """Test running a specific JavaScript test file.""" runner = JavaScriptTestRunner() # Run the environment test specifically result = runner.run_specific_test("test-environment.test.js") assert result is not None assert result.success is True, f"Specific test failed: {result.failures}" def test_python_js_bridge_initialization(self): """Test that PythonJSBridge can be initialized.""" bridge = PythonJSBridge() assert bridge is not None assert hasattr(bridge, 'run_all_js_tests') assert hasattr(bridge, 'run_js_test_by_name') class TestJavaScriptComponents: """Test JavaScript component functionality through Python bridge.""" @pytest.mark.javascript def test_component_integration_via_bridge(self): """Test component integration through JavaScript bridge.""" bridge = PythonJSBridge() result = bridge.run_all_js_tests() assert result.success is True, f"Component integration tests failed: {result.failures}" assert result.tests_passed >= 7, f"Expected at least 7 passing tests, got {result.tests_passed}" @pytest.mark.javascript def test_environment_test_via_bridge(self): """Test environment setup through JavaScript bridge.""" bridge = PythonJSBridge() result = bridge.run_js_test_by_name("test-environment.test.js") assert result.success is True, f"Environment test failed: {result.failures}" class TestIntegrationEnvironment: """Test the integration environment setup.""" def test_pytest_markers_available(self): """Test that pytest markers are properly configured.""" # This test verifies that the @pytest.mark.javascript marker is available # The marker is configured in the integration.py file # The main test is that the decorator doesn't raise an error # We can test this by using the decorator itself try: @pytest.mark.javascript def dummy_test(): pass # If we get here without exception, markers are working assert True except AttributeError as e: pytest.fail(f"JavaScript marker not properly configured: {e}") def test_test_discovery_function(self): """Test the JavaScript test discovery function.""" from testdrive_jsui.testing.integration import discover_js_tests tests = discover_js_tests() assert isinstance(tests, list) assert len(tests) > 0, "Should discover JavaScript test files"