test: add more tests
This commit is contained in:
59
tests/npm_compat_test/BUILD.bazel
Normal file
59
tests/npm_compat_test/BUILD.bazel
Normal file
@@ -0,0 +1,59 @@
|
||||
load("@rules_shell//shell:sh_test.bzl", "sh_test")
|
||||
|
||||
config_setting(
|
||||
name = "linux_x86_64",
|
||||
constraint_values = [
|
||||
"@platforms//os:linux",
|
||||
"@platforms//cpu:x86_64",
|
||||
],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "linux_aarch64",
|
||||
constraint_values = [
|
||||
"@platforms//os:linux",
|
||||
"@platforms//cpu:aarch64",
|
||||
],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "darwin_x86_64",
|
||||
constraint_values = [
|
||||
"@platforms//os:macos",
|
||||
"@platforms//cpu:x86_64",
|
||||
],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "darwin_aarch64",
|
||||
constraint_values = [
|
||||
"@platforms//os:macos",
|
||||
"@platforms//cpu:aarch64",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "npm_translate_lock_workspace_test",
|
||||
srcs = ["npm_translate_lock_workspace_test.sh"],
|
||||
env_inherit = ["PATH"],
|
||||
args = select({
|
||||
":linux_x86_64": ["$(location @bun_linux_x64//:bun)"],
|
||||
":linux_aarch64": ["$(location @bun_linux_aarch64//:bun)"],
|
||||
":darwin_x86_64": ["$(location @bun_darwin_x64//:bun)"],
|
||||
":darwin_aarch64": ["$(location @bun_darwin_aarch64//:bun)"],
|
||||
"//conditions:default": ["$(location @bun_linux_x64//:bun)"],
|
||||
}),
|
||||
data = select({
|
||||
":linux_x86_64": ["@bun_linux_x64//:bun"],
|
||||
":linux_aarch64": ["@bun_linux_aarch64//:bun"],
|
||||
":darwin_x86_64": ["@bun_darwin_x64//:bun"],
|
||||
":darwin_aarch64": ["@bun_darwin_aarch64//:bun"],
|
||||
"//conditions:default": ["@bun_linux_x64//:bun"],
|
||||
}) + [
|
||||
"//:repo_runtime_files",
|
||||
"//bun:repo_runtime_files",
|
||||
"//internal:repo_runtime_files",
|
||||
"//js:repo_runtime_files",
|
||||
"//npm:repo_runtime_files",
|
||||
],
|
||||
)
|
||||
@@ -1,15 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
nix_cmd="${NIX:-/nix/var/nix/profiles/default/bin/nix}"
|
||||
if [[ ! -x ${nix_cmd} ]]; then
|
||||
nix_cmd="$(command -v nix || true)"
|
||||
fi
|
||||
if [[ -z ${nix_cmd} || ! -x ${nix_cmd} ]]; then
|
||||
echo "nix is required to launch bazel from the repo dev shell" >&2
|
||||
if command -v bazel >/dev/null 2>&1; then
|
||||
bazel_bin="$(command -v bazel)"
|
||||
elif command -v bazelisk >/dev/null 2>&1; then
|
||||
bazel_bin="$(command -v bazelisk)"
|
||||
else
|
||||
echo "bazel or bazelisk is required on PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
bun_path="${1:-bun}"
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
rules_bun_root="$(cd "${script_dir}/../.." && pwd -P)"
|
||||
|
||||
@@ -35,10 +37,7 @@ import isNumber from "is-number";
|
||||
console.log(`compat:${isNumber(42)}`);
|
||||
JS
|
||||
|
||||
(
|
||||
cd "${rules_bun_root}" &&
|
||||
"${nix_cmd}" develop -c bash -lc 'bun install --cwd "$1" >/dev/null' bash "${fixture_dir}"
|
||||
)
|
||||
"${bun_path}" install --cwd "${fixture_dir}" >/dev/null
|
||||
rm -rf "${fixture_dir}/node_modules"
|
||||
|
||||
cat >"${fixture_dir}/MODULE.bazel" <<EOF
|
||||
@@ -100,8 +99,8 @@ js_binary(
|
||||
EOF
|
||||
|
||||
output="$(
|
||||
cd "${rules_bun_root}" &&
|
||||
"${nix_cmd}" develop -c bash -lc 'cd "$1" && bazel run //:app' bash "${fixture_dir}"
|
||||
cd "${fixture_dir}" &&
|
||||
"${bazel_bin}" run //:app
|
||||
)"
|
||||
|
||||
if [[ ${output} != *"compat:true"* ]]; then
|
||||
@@ -110,8 +109,8 @@ if [[ ${output} != *"compat:true"* ]]; then
|
||||
fi
|
||||
|
||||
query_output="$(
|
||||
cd "${rules_bun_root}" &&
|
||||
"${nix_cmd}" develop -c bash -lc 'cd "$1" && bazel query //:npm__is_number' bash "${fixture_dir}"
|
||||
cd "${fixture_dir}" &&
|
||||
"${bazel_bin}" query //:npm__is_number
|
||||
)"
|
||||
if ! grep -Fxq "//:npm__is_number" <<<"${query_output}"; then
|
||||
echo "expected npm_link_all_packages to create //:npm__is_number" >&2
|
||||
|
||||
Reference in New Issue
Block a user