diff --git a/graphqler/utils/stats.py b/graphqler/utils/stats.py index c86db7b..a1f0864 100644 --- a/graphqler/utils/stats.py +++ b/graphqler/utils/stats.py @@ -11,6 +11,8 @@ from .file_utils import initialize_file, intialize_file_if_not_exists, recreate_path, get_or_create_file from .singleton import singleton +import os +import re @singleton @@ -261,6 +263,9 @@ def save_endpoint_results(self): for node_name, results in self.results.items(): # If the node name has slashes, replace them with underscores node_name = node_name.replace("/", "_") + if os.name == "nt": + # Replace characters that are invalid in Windows filenames + node_name = re.sub(r'[\\/:*?"<>|]', "_", name) for result in results: result_type = "success" if result.success else "failure" result_file_path = Path(self.endpoint_results_dir) / node_name / result_type / f"{result.status_code}" diff --git a/tests/integration/test_food_delivery_api.py b/tests/integration/test_food_delivery_api.py index 0be25ad..6181b14 100644 --- a/tests/integration/test_food_delivery_api.py +++ b/tests/integration/test_food_delivery_api.py @@ -4,7 +4,7 @@ from tests.integration.utils.stats import get_percent_query_mutation_success from tests.integration.utils.run_api import run_node_project, wait_for_server import os - +import shutil class TestFoodDeliveryAPI(unittest.TestCase): PORT = 4000 @@ -18,7 +18,8 @@ class TestFoodDeliveryAPI(unittest.TestCase): @classmethod def setUpClass(cls): # Start the GrapQL server - cls.process = run_node_project(cls.API_PATH, ["node dbinitializer.js"], str(cls.PORT)) + node_cmd = shutil.which("node") + cls.process = run_node_project(cls.API_PATH, [f"{node_cmd} dbinitializer.js"], str(cls.PORT)) cls.process_pid = cls.process.pid # Parse the config @@ -33,7 +34,8 @@ def tearDownClass(cls): if cls.process and cls.process.pid == cls.process_pid: cls.process.kill() cls.process.wait() - os.system(f"rm -rf {cls.PATH}") + if os.path.exists(cls.PATH): + shutil.rmtree(cls.PATH) def test_run_compile_mode_generates_valid_introspection_file(self): __main__.run_compile_mode(self.PATH, self.URL) diff --git a/tests/integration/test_user_wallet_api.py b/tests/integration/test_user_wallet_api.py index cc28a0a..22a6188 100644 --- a/tests/integration/test_user_wallet_api.py +++ b/tests/integration/test_user_wallet_api.py @@ -4,6 +4,8 @@ from tests.integration.utils.stats import get_percent_query_mutation_success from tests.integration.utils.run_api import run_node_project, wait_for_server import os +import shutil + class TestUserWalletApi(unittest.TestCase): @@ -33,7 +35,11 @@ def tearDownClass(cls): if cls.process and cls.process.pid == cls.process_pid: cls.process.kill() cls.process.wait() - os.system(f"rm -rf {cls.PATH}") + if os.path.exists(cls.PATH): + try: + shutil.rmtree(cls.PATH) + except Exception as e: + pass def test_run_compile_mode_generates_valid_introspection_file(self): print(self.PATH, self.URL) diff --git a/tests/integration/utils/run_api.py b/tests/integration/utils/run_api.py index 6d38772..061d3e4 100644 --- a/tests/integration/utils/run_api.py +++ b/tests/integration/utils/run_api.py @@ -2,6 +2,7 @@ import os import requests import time +import shutil def run_node_project(path: str, commands: list[str], port: str) -> subprocess.Popen: @@ -18,16 +19,26 @@ def run_node_project(path: str, commands: list[str], port: str) -> subprocess.Po # Set the environment variable env = os.environ.copy() env["PORT"] = port + shell_flag = os.name == "nt" # True no Windows, False no Linux/macOS - # Run npm install - subprocess.run(["npm", "install"], cwd=path, check=True, env=env) + # Run npm install with proper handling + npm_cmd = shutil.which("npm") + node_cmd = shutil.which("node") + if npm_cmd is None: + raise RuntimeError("npm command not found. Please ensure Node.js is installed.") + + try: + subprocess.run([npm_cmd, "install"], cwd=path, check=True, env=env, shell=shell_flag) + except subprocess.CalledProcessError as e: + print(f"npm install failed: {e}") + raise # Run each command in the list for command in commands: - subprocess.run(command.split(), cwd=path, check=True, env=env) + subprocess.run(command.split(), cwd=path, check=True, env=env, shell=shell_flag) # Run node server.js - process = subprocess.Popen(["node", "server.js"], cwd=path, env=env) + process = subprocess.Popen([node_cmd, "server.js"], cwd=path, env=env, shell=shell_flag) return process