diff --git a/core/api/BUCK b/core/api/BUCK index f47cda5d57..0d3a868a46 100644 --- a/core/api/BUCK +++ b/core/api/BUCK @@ -182,7 +182,7 @@ jest_test( name = "unit-tests", srcs = [":src"] + [":test_src"] + glob(["galoy.yaml"]), config_file = "test/unit/jest.config.js", - env_json_target = "//dev:env.json", + env_json = "//dev:env.json", env = { "LOGLEVEL": "warn", } @@ -194,7 +194,7 @@ jest_test( prod_deps_srcs = prod_deps_srcs, config_file = "test/integration/jest.config.js", run_serially = True, - env_json_target = "//dev:env.json", + env_json = "//dev:env.json", env = { "LOGLEVEL": "warn", } diff --git a/toolchains/workspace-pnpm/macros.bzl b/toolchains/workspace-pnpm/macros.bzl index 7031010bfd..dfe381bb71 100644 --- a/toolchains/workspace-pnpm/macros.bzl +++ b/toolchains/workspace-pnpm/macros.bzl @@ -634,9 +634,9 @@ def _npm_test_impl( cmd_args(program_run_info), ]) - if hasattr(ctx.attrs, 'env_json_target'): - run_cmd_args.add("--env-json-target") - run_cmd_args.add(ctx.attrs.env_json_target) + if hasattr(ctx.attrs, 'env_json'): + run_cmd_args.add("--env-json") + run_cmd_args.add(ctx.attrs.env_json) run_cmd_args.add("--") run_cmd_args.add(program_args) @@ -1165,8 +1165,8 @@ _jest_test = rule( default = False, doc = "Run all tests serially in the current process" ), - "env_json_target": attrs.option( - attrs.string(), + "env_json": attrs.option( + attrs.source(), doc = """buck2 target for json file with env variables required.""", default = None, ), diff --git a/toolchains/workspace-pnpm/run_npm_test.py b/toolchains/workspace-pnpm/run_npm_test.py index 4a9f06123e..d37acfa571 100644 --- a/toolchains/workspace-pnpm/run_npm_test.py +++ b/toolchains/workspace-pnpm/run_npm_test.py @@ -8,33 +8,6 @@ import subprocess import sys -def env_dict_from_target(target): - repo_root_cmd = ["git", "rev-parse", "--show-toplevel"] - repo_root_res = subprocess.run(repo_root_cmd, capture_output=True, text=True) - if repo_root_res.returncode != 0: - raise RuntimeError(repo_root_res.stderr) - repo_root = repo_root_res.stdout.strip() - - env_json_cmd = [ - "buck2", - "--isolation-dir", - "buck-out", - "uquery", - "inputs(deps('{}'))".format(target), - ] - env_json_res = subprocess.run(env_json_cmd, capture_output=True, text=True) - if env_json_res.returncode != 0: - raise RuntimeError(env_json_res.stderr) - env_json = env_json_res.stdout.strip() - - - abs_file_path = "{}/{}".format(repo_root, env_json) - with open(abs_file_path, 'r') as file: - env_dict = json.load(file) - - return env_dict - - if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( @@ -46,7 +19,7 @@ def env_dict_from_target(target): help="Binary to execute program with", ) parser.add_argument( - "--env-json-target", + "--env-json", help="Env file to load variables from", ) parser.add_argument( @@ -58,9 +31,10 @@ def env_dict_from_target(target): args = parser.parse_args() env = os.environ.copy() - if (args.env_json_target): - env_json = env_dict_from_target(args.env_json_target) - env = {**env, **env_json} + if (args.env_json): + with open(args.env_json, 'r') as file: + env_dict = json.load(file) + env = {**env, **env_dict} bin_args = args.args[1:] # ignore '--' separator if env.get("TEST"):