feat: bun_script
This commit is contained in:
33
tests/script_test/BUILD.bazel
Normal file
33
tests/script_test/BUILD.bazel
Normal file
@@ -0,0 +1,33 @@
|
||||
load("//bun:defs.bzl", "bun_script")
|
||||
load("@rules_shell//shell:sh_test.bzl", "sh_test")
|
||||
|
||||
bun_script(
|
||||
name = "hello_script",
|
||||
script = "hello",
|
||||
package_json = "package.json",
|
||||
data = ["hello.ts"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_script_ts_test",
|
||||
srcs = ["run_script.sh"],
|
||||
args = ["$(location :hello_script)", "hello-script"],
|
||||
data = [":hello_script"],
|
||||
)
|
||||
|
||||
bun_script(
|
||||
name = "env_script",
|
||||
script = "print-env",
|
||||
package_json = "package.json",
|
||||
data = [
|
||||
".env",
|
||||
"env.ts",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_script_package_cwd_test",
|
||||
srcs = ["run_env_script.sh"],
|
||||
args = ["$(location :env_script)"],
|
||||
data = [":env_script"],
|
||||
)
|
||||
2
tests/script_test/env.ts
Normal file
2
tests/script_test/env.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
const value = process.env.BUN_SCRIPT_ENV_TEST ?? "missing";
|
||||
console.log(value);
|
||||
1
tests/script_test/hello.ts
Normal file
1
tests/script_test/hello.ts
Normal file
@@ -0,0 +1 @@
|
||||
console.log("hello-script");
|
||||
9
tests/script_test/package.json
Normal file
9
tests/script_test/package.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "script-test",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"hello": "bun ./hello.ts",
|
||||
"print-env": "bun ./env.ts"
|
||||
}
|
||||
}
|
||||
10
tests/script_test/run_env_script.sh
Executable file
10
tests/script_test/run_env_script.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
output="$(${binary})"
|
||||
|
||||
if [[ ${output} != "from-dotenv" ]]; then
|
||||
echo "Expected .env value from package directory, got: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
11
tests/script_test/run_script.sh
Executable file
11
tests/script_test/run_script.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
expected="$2"
|
||||
output="$(${binary})"
|
||||
|
||||
if [[ ${output} != "${expected}" ]]; then
|
||||
echo "Unexpected output from ${binary}: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user