From c43430d78b0f4f70fcc44688688b2ac781aac116 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 4 Mar 2026 08:44:11 +0100 Subject: [PATCH] fix: tests --- .gitlint | 8 ++++ bun/repositories.bzl | 2 +- internal/bun_binary.bzl | 11 ++++- internal/bun_test.bzl | 18 ++++--- tests/binary_test/BUILD.bazel | 16 ------- tests/bun_test_test/BUILD.bazel | 8 ---- tests/bundle_test/BUILD.bazel | 16 ------- tests/install_test/BUILD.bazel | 72 +++++++++++++++++++++++----- tests/install_test/stale_lockfile.sh | 25 +++++----- tests/library_test/BUILD.bazel | 17 +------ tests/toolchain_test/BUILD.bazel | 52 +++++++++++++++++--- 11 files changed, 151 insertions(+), 94 deletions(-) create mode 100644 .gitlint diff --git a/.gitlint b/.gitlint new file mode 100644 index 0000000..a76e65b --- /dev/null +++ b/.gitlint @@ -0,0 +1,8 @@ +[general] +ignore=B6 + +[title-max-length] +line-length=72 + +[title-match-regex] +regex=^(feat|fix|chore|docs|refactor|test|ci)(\(.+\))?: .+ \ No newline at end of file diff --git a/bun/repositories.bzl b/bun/repositories.bzl index 37ba294..b475d4a 100644 --- a/bun/repositories.bzl +++ b/bun/repositories.bzl @@ -63,7 +63,7 @@ def bun_repositories(version = BUN_VERSION): ) -def bun_register_toolchains(version = BUN_VERSION): +def bun_register_toolchains(name = "bun", version = BUN_VERSION): bun_repositories(version = version) native.register_toolchains( "//bun:darwin_aarch64_toolchain", diff --git a/internal/bun_binary.bzl b/internal/bun_binary.bzl index 0e2caf8..f5e76bb 100644 --- a/internal/bun_binary.bzl +++ b/internal/bun_binary.bzl @@ -13,8 +13,15 @@ def _bun_binary_impl(ctx): content = """#!/usr/bin/env bash set -euo pipefail -exec \"{}\" run \"{}\" \"$@\" -""".format(bun_bin.path, entry_point.path), +runfiles_dir="${{RUNFILES_DIR:-$0.runfiles}}" +bun_bin="${{runfiles_dir}}/_main/{bun_short_path}" +entry_point="${{runfiles_dir}}/_main/{entry_short_path}" + +exec "${{bun_bin}}" run "${{entry_point}}" "$@" +""".format( + bun_short_path = bun_bin.short_path, + entry_short_path = entry_point.short_path, + ), ) transitive_files = [] diff --git a/internal/bun_test.bzl b/internal/bun_test.bzl index 5e46a71..29d311e 100644 --- a/internal/bun_test.bzl +++ b/internal/bun_test.bzl @@ -11,7 +11,7 @@ def _bun_test_impl(ctx): toolchain = ctx.toolchains["//bun:toolchain_type"] bun_bin = toolchain.bun.bun_bin - src_args = " ".join([_shell_quote(src.path) for src in ctx.files.srcs]) + src_args = " ".join([_shell_quote(src.short_path) for src in ctx.files.srcs]) launcher = ctx.actions.declare_file(ctx.label.name) ctx.actions.write( output = launcher, @@ -19,16 +19,22 @@ def _bun_test_impl(ctx): content = """#!/usr/bin/env bash set -euo pipefail -extra_args=() +runfiles_dir="${{RUNFILES_DIR:-$0.runfiles}}" +bun_bin="${{runfiles_dir}}/_main/{bun_short_path}" +cd "${{runfiles_dir}}/_main" + +if [[ -n "${{TESTBRIDGE_TEST_ONLY:-}}" && -n "${{COVERAGE_DIR:-}}" ]]; then + exec "${{bun_bin}}" test {src_args} --test-name-pattern "${{TESTBRIDGE_TEST_ONLY}}" --coverage "$@" +fi if [[ -n "${{TESTBRIDGE_TEST_ONLY:-}}" ]]; then - extra_args+=("--test-name-pattern" "${{TESTBRIDGE_TEST_ONLY}}") + exec "${{bun_bin}}" test {src_args} --test-name-pattern "${{TESTBRIDGE_TEST_ONLY}}" "$@" fi if [[ -n "${{COVERAGE_DIR:-}}" ]]; then - extra_args+=("--coverage") + exec "${{bun_bin}}" test {src_args} --coverage "$@" fi -exec "{bun_bin}" test {src_args} "${{extra_args[@]}}" "$@" +exec "${{bun_bin}}" test {src_args} "$@" """.format( - bun_bin = bun_bin.path, + bun_short_path = bun_bin.short_path, src_args = src_args, ), ) diff --git a/tests/binary_test/BUILD.bazel b/tests/binary_test/BUILD.bazel index 7eef78e..ae4e371 100644 --- a/tests/binary_test/BUILD.bazel +++ b/tests/binary_test/BUILD.bazel @@ -4,10 +4,6 @@ load("@rules_shell//shell:sh_test.bzl", "sh_test") bun_binary( name = "hello_js_bin", entry_point = "hello.js", - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) sh_test( @@ -15,19 +11,11 @@ sh_test( srcs = ["run_binary.sh"], args = ["$(location :hello_js_bin)", "hello-js"], data = [":hello_js_bin"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) bun_binary( name = "hello_ts_bin", entry_point = "hello.ts", - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) sh_test( @@ -35,8 +23,4 @@ sh_test( srcs = ["run_binary.sh"], args = ["$(location :hello_ts_bin)", "hello-ts"], data = [":hello_ts_bin"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) diff --git a/tests/bun_test_test/BUILD.bazel b/tests/bun_test_test/BUILD.bazel index 9f67755..6ed38c2 100644 --- a/tests/bun_test_test/BUILD.bazel +++ b/tests/bun_test_test/BUILD.bazel @@ -3,18 +3,10 @@ load("//bun:defs.bzl", "bun_test") bun_test( name = "passing_suite", srcs = ["passing.test.ts"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) bun_test( name = "failing_suite", srcs = ["failing.test.ts"], tags = ["manual"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) diff --git a/tests/bundle_test/BUILD.bazel b/tests/bundle_test/BUILD.bazel index fc86b61..b2c97f0 100644 --- a/tests/bundle_test/BUILD.bazel +++ b/tests/bundle_test/BUILD.bazel @@ -4,20 +4,12 @@ load("@rules_shell//shell:sh_test.bzl", "sh_test") bun_bundle( name = "simple_bundle", entry_points = ["main.ts"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) bun_bundle( name = "minified_bundle", entry_points = ["main.ts"], minify = True, - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) sh_test( @@ -25,10 +17,6 @@ sh_test( srcs = ["verify_bundle.sh"], args = ["$(location :simple_bundle)"], data = [":simple_bundle"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) sh_test( @@ -42,8 +30,4 @@ sh_test( ":simple_bundle", ":minified_bundle", ], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) diff --git a/tests/install_test/BUILD.bazel b/tests/install_test/BUILD.bazel index 25d34d2..4560eef 100644 --- a/tests/install_test/BUILD.bazel +++ b/tests/install_test/BUILD.bazel @@ -1,23 +1,71 @@ 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 = "bun_install_clean_install_test", srcs = ["clean_install.sh"], - args = ["$(location @bun_linux_x64//:bun)"], - data = ["@bun_linux_x64//:bun"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], + 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"], + }), ) sh_test( name = "bun_install_stale_lockfile_test", srcs = ["stale_lockfile.sh"], - args = ["$(location @bun_linux_x64//:bun)"], - data = ["@bun_linux_x64//:bun"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], + 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"], + }), ) diff --git a/tests/install_test/stale_lockfile.sh b/tests/install_test/stale_lockfile.sh index e21cfd2..fbb0501 100755 --- a/tests/install_test/stale_lockfile.sh +++ b/tests/install_test/stale_lockfile.sh @@ -5,16 +5,7 @@ bun_path="$1" workdir="$(mktemp -d)" trap 'rm -rf "${workdir}"' EXIT -cat > "${workdir}/package.json" <<'JSON' -{ - "name": "stale-lockfile-test", - "version": "1.0.0" -} -JSON - -"${bun_path}" install --cwd "${workdir}" >/dev/null - -cat > "${workdir}/package.json" <<'JSON' +cat >"${workdir}/package.json" <<'JSON' { "name": "stale-lockfile-test", "version": "1.0.0", @@ -24,6 +15,18 @@ cat > "${workdir}/package.json" <<'JSON' } JSON +"${bun_path}" install --cwd "${workdir}" >/dev/null + +cat >"${workdir}/package.json" <<'JSON' +{ + "name": "stale-lockfile-test", + "version": "1.0.0", + "dependencies": { + "left-pad": "1.1.3" + } +} +JSON + set +e output="$(${bun_path} install --cwd "${workdir}" --frozen-lockfile 2>&1)" code=$? @@ -34,7 +37,7 @@ if [[ ${code} -eq 0 ]]; then exit 1 fi -if [[ "${output}" != *"lockfile"* && "${output}" != *"frozen"* ]]; then +if [[ ${output} != *"lockfile"* && ${output} != *"frozen"* ]]; then echo "Expected lockfile-related error, got:" >&2 echo "${output}" >&2 exit 1 diff --git a/tests/library_test/BUILD.bazel b/tests/library_test/BUILD.bazel index 2cfacac..8c423ce 100644 --- a/tests/library_test/BUILD.bazel +++ b/tests/library_test/BUILD.bazel @@ -1,22 +1,15 @@ load("//bun:defs.bzl", "bun_bundle", "bun_test", "ts_library") +load("@rules_shell//shell:sh_test.bzl", "sh_test") ts_library( name = "helper_lib", srcs = ["helper.ts"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) bun_bundle( name = "bundle_with_deps", entry_points = ["app.ts"], deps = [":helper_lib"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) sh_test( @@ -24,18 +17,10 @@ sh_test( srcs = ["verify_bundle.sh"], args = ["$(location :bundle_with_deps)"], data = [":bundle_with_deps"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) bun_test( name = "test_with_deps", srcs = ["app.test.ts"], deps = [":helper_lib"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], ) diff --git a/tests/toolchain_test/BUILD.bazel b/tests/toolchain_test/BUILD.bazel index eb7fce7..3527248 100644 --- a/tests/toolchain_test/BUILD.bazel +++ b/tests/toolchain_test/BUILD.bazel @@ -1,12 +1,52 @@ 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 = "bun_version_test", srcs = ["toolchain_version.sh"], - args = ["$(location @bun_linux_x64//:bun)"], - data = ["@bun_linux_x64//:bun"], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], + 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"], + }), )