copilot/add-bun-rules-package #1

Merged
eric merged 25 commits from copilot/add-bun-rules-package into main 2026-03-04 08:27:25 +00:00
4 changed files with 13 additions and 6 deletions
Showing only changes of commit 07b97a6e1e - Show all commits

View File

@@ -1,11 +1,15 @@
"""Rule for running test suites with Bun.""" """Rule for running test suites with Bun."""
def _shell_quote(value):
return "'" + value.replace("'", "'\"'\"'") + "'"
def _bun_test_impl(ctx): def _bun_test_impl(ctx):
toolchain = ctx.toolchains["//bun:toolchain_type"] toolchain = ctx.toolchains["//bun:toolchain_type"]
bun_bin = toolchain.bun.bun_bin bun_bin = toolchain.bun.bun_bin
src_args = " ".join(["\"{}\"".format(src.path) for src in ctx.files.srcs]) src_args = " ".join([_shell_quote(src.path) for src in ctx.files.srcs])
launcher = ctx.actions.declare_file(ctx.label.name) launcher = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write( ctx.actions.write(
output = launcher, output = launcher,
@@ -20,9 +24,11 @@ fi
if [[ -n "${{COVERAGE_DIR:-}}" ]]; then if [[ -n "${{COVERAGE_DIR:-}}" ]]; then
extra_args+=("--coverage") extra_args+=("--coverage")
fi fi
exec "{bun_bin}" test {src_args} "${{extra_args[@]}}" "$@"
exec "{}" test {} "${{extra_args[@]}}" "$@" """.format(
""".format(bun_bin.path, src_args), bun_bin = bun_bin.path,
src_args = src_args,
),
) )
transitive_files = [] transitive_files = []

View File

@@ -12,6 +12,7 @@ bun_test(
bun_test( bun_test(
name = "failing_suite", name = "failing_suite",
srcs = ["failing.test.ts"], srcs = ["failing.test.ts"],
tags = ["manual"],
target_compatible_with = [ target_compatible_with = [
"@platforms//cpu:x86_64", "@platforms//cpu:x86_64",
"@platforms//os:linux", "@platforms//os:linux",

View File

@@ -1,5 +1,5 @@
import { expect, test } from "bun:test"; import { expect, test } from "bun:test";
test("failing suite", () => { test("intentionally fails for manual validation", () => {
expect(1 + 1).toBe(3); expect(1 + 1).toBe(3);
}); });

View File

@@ -1,5 +1,5 @@
import { expect, test } from "bun:test"; import { expect, test } from "bun:test";
test("passing suite", () => { test("adds two numbers correctly", () => {
expect(1 + 1).toBe(2); expect(1 + 1).toBe(2);
}); });