feat: improve rules_js parity
This commit is contained in:
41
tests/js_compat_test/BUILD.bazel
Normal file
41
tests/js_compat_test/BUILD.bazel
Normal file
@@ -0,0 +1,41 @@
|
||||
load("//js:defs.bzl", "js_binary", "js_run_devserver", "js_test", "ts_library")
|
||||
load("@rules_shell//shell:sh_test.bzl", "sh_test")
|
||||
|
||||
ts_library(
|
||||
name = "helper_lib",
|
||||
srcs = ["helper.ts"],
|
||||
data = ["payload.txt"],
|
||||
)
|
||||
|
||||
js_binary(
|
||||
name = "compat_bin",
|
||||
entry_point = "main.ts",
|
||||
deps = [":helper_lib"],
|
||||
args = ["compat-mode"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "js_binary_compat_test",
|
||||
srcs = ["run_binary.sh"],
|
||||
args = ["$(location :compat_bin)"],
|
||||
data = [":compat_bin"],
|
||||
)
|
||||
|
||||
js_test(
|
||||
name = "compat_suite",
|
||||
entry_point = "app.test.ts",
|
||||
deps = [":helper_lib"],
|
||||
)
|
||||
|
||||
js_run_devserver(
|
||||
name = "compat_devserver",
|
||||
tool = ":compat_bin",
|
||||
args = ["devserver-mode"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "js_run_devserver_compat_test",
|
||||
srcs = ["run_devserver.sh"],
|
||||
args = ["$(location :compat_devserver)"],
|
||||
data = [":compat_devserver"],
|
||||
)
|
||||
7
tests/js_compat_test/app.test.ts
Normal file
7
tests/js_compat_test/app.test.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
import { helperMessage } from "./helper.ts";
|
||||
|
||||
test("js_test compatibility layer propagates deps and data", () => {
|
||||
expect(helperMessage()).toBe("helper:payload-from-lib");
|
||||
});
|
||||
6
tests/js_compat_test/helper.ts
Normal file
6
tests/js_compat_test/helper.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
export function helperMessage(): string {
|
||||
const payload = readFileSync(new URL("./payload.txt", import.meta.url), "utf8").trim();
|
||||
return `helper:${payload}`;
|
||||
}
|
||||
3
tests/js_compat_test/main.ts
Normal file
3
tests/js_compat_test/main.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { helperMessage } from "./helper.ts";
|
||||
|
||||
console.log(`${helperMessage()} ${Bun.argv.slice(2).join(" ")}`.trim());
|
||||
1
tests/js_compat_test/payload.txt
Normal file
1
tests/js_compat_test/payload.txt
Normal file
@@ -0,0 +1 @@
|
||||
payload-from-lib
|
||||
10
tests/js_compat_test/run_binary.sh
Executable file
10
tests/js_compat_test/run_binary.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
output="$("${binary}")"
|
||||
|
||||
if [[ ${output} != "helper:payload-from-lib compat-mode" ]]; then
|
||||
echo "unexpected output: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
10
tests/js_compat_test/run_devserver.sh
Executable file
10
tests/js_compat_test/run_devserver.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
output="$("${binary}")"
|
||||
|
||||
if [[ ${output} != "helper:payload-from-lib compat-mode devserver-mode" ]]; then
|
||||
echo "unexpected output: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user