fix: harden bun_test launcher args and test metadata
This commit is contained in:
@@ -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 = []
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user