test: add more tests
This commit is contained in:
@@ -93,3 +93,27 @@ sh_test(
|
||||
args = ["$(location :runtime_flag_bin)"],
|
||||
data = [":runtime_flag_bin"],
|
||||
)
|
||||
|
||||
bun_binary(
|
||||
name = "configured_launcher_bin",
|
||||
entry_point = "hello.ts",
|
||||
node_modules = "@script_test_vite_node_modules//:node_modules",
|
||||
smol = True,
|
||||
conditions = [
|
||||
"browser",
|
||||
"development",
|
||||
],
|
||||
install_mode = "force",
|
||||
run_flags = [
|
||||
"--hot",
|
||||
"--console-depth",
|
||||
"4",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_binary_configured_launcher_shape_test",
|
||||
srcs = ["verify_configured_launcher_shape.sh"],
|
||||
args = ["$(location :configured_launcher_bin)"],
|
||||
data = [":configured_launcher_bin"],
|
||||
)
|
||||
|
||||
16
tests/binary_test/verify_configured_launcher_shape.sh
Executable file
16
tests/binary_test/verify_configured_launcher_shape.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
|
||||
grep -Fq -- 'install_metadata="${runfiles_dir}/_main/' "${binary}"
|
||||
grep -Fq -- 'node_modules/.rules_bun/install.json' "${binary}"
|
||||
grep -Fq -- "--smol" "${binary}"
|
||||
grep -Fq -- "--conditions" "${binary}"
|
||||
grep -Fq -- "'browser'" "${binary}"
|
||||
grep -Fq -- "'development'" "${binary}"
|
||||
grep -Fq -- "--install" "${binary}"
|
||||
grep -Fq -- "'force'" "${binary}"
|
||||
grep -Fq -- "'--hot'" "${binary}"
|
||||
grep -Fq -- "'--console-depth'" "${binary}"
|
||||
grep -Fq -- "'4'" "${binary}"
|
||||
@@ -4,6 +4,6 @@ set -euo pipefail
|
||||
rule_file="$1"
|
||||
build_file="$2"
|
||||
|
||||
grep -Eq 'files = \[bun_bin, entry_point\] \+ ctx\.files\.data' "${rule_file}"
|
||||
grep -Eq 'extra_files = ctx\.files\.data \+ ctx\.files\.preload \+ ctx\.files\.env_files \+ \[bun_bin\]' "${rule_file}"
|
||||
grep -Eq 'name = "hello_js_with_data_bin"' "${build_file}"
|
||||
grep -Eq 'data = \["payload\.txt"\]' "${build_file}"
|
||||
|
||||
@@ -20,7 +20,6 @@ bun_test(
|
||||
timeout_ms = 250,
|
||||
update_snapshots = True,
|
||||
rerun_each = 2,
|
||||
retry = 3,
|
||||
concurrent = True,
|
||||
randomize = True,
|
||||
seed = 7,
|
||||
@@ -32,6 +31,12 @@ bun_test(
|
||||
test_flags = ["--only-failures"],
|
||||
)
|
||||
|
||||
bun_test(
|
||||
name = "configured_retry_suite",
|
||||
srcs = ["passing.test.ts"],
|
||||
retry = 3,
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_test_failing_suite_test",
|
||||
srcs = ["failing_suite_shape.sh"],
|
||||
@@ -63,6 +68,12 @@ sh_test(
|
||||
sh_test(
|
||||
name = "bun_test_configured_suite_shape_test",
|
||||
srcs = ["configured_suite_shape.sh"],
|
||||
args = ["$(location :configured_suite)"],
|
||||
data = [":configured_suite"],
|
||||
args = [
|
||||
"$(location :configured_suite)",
|
||||
"$(location :configured_retry_suite)",
|
||||
],
|
||||
data = [
|
||||
":configured_suite",
|
||||
":configured_retry_suite",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
launcher="$1"
|
||||
retry_launcher="$2"
|
||||
|
||||
grep -Fq -- '--no-install' "${launcher}"
|
||||
grep -Fq -- '--preload' "${launcher}"
|
||||
@@ -10,7 +11,6 @@ grep -Fq -- '--no-env-file' "${launcher}"
|
||||
grep -Fq -- '--timeout' "${launcher}"
|
||||
grep -Fq -- '--update-snapshots' "${launcher}"
|
||||
grep -Fq -- '--rerun-each' "${launcher}"
|
||||
grep -Fq -- '--retry' "${launcher}"
|
||||
grep -Fq -- '--concurrent' "${launcher}"
|
||||
grep -Fq -- '--randomize' "${launcher}"
|
||||
grep -Fq -- '--seed' "${launcher}"
|
||||
@@ -21,3 +21,4 @@ grep -Fq -- '--reporter-outfile' "${launcher}"
|
||||
grep -Fq -- '--coverage' "${launcher}"
|
||||
grep -Fq -- '--coverage-dir' "${launcher}"
|
||||
grep -Fq -- '--coverage-reporter' "${launcher}"
|
||||
grep -Fq -- '--retry' "${retry_launcher}"
|
||||
|
||||
@@ -39,11 +39,101 @@ bun_build(
|
||||
metafile_md = True,
|
||||
)
|
||||
|
||||
bun_build(
|
||||
name = "advanced_site_build",
|
||||
tags = ["manual"],
|
||||
entry_points = ["site/index.html"],
|
||||
data = [
|
||||
"site/main.ts",
|
||||
"site/styles.css",
|
||||
],
|
||||
install_mode = "fallback",
|
||||
target = "node",
|
||||
format = "cjs",
|
||||
production = True,
|
||||
splitting = True,
|
||||
root = "tests/bundle_test/site",
|
||||
sourcemap = "linked",
|
||||
banner = "/* bundle banner */",
|
||||
footer = "// bundle footer",
|
||||
public_path = "/static/",
|
||||
packages = "external",
|
||||
external = [
|
||||
"left-pad",
|
||||
"react",
|
||||
],
|
||||
entry_naming = "entries/[name]-[hash].[ext]",
|
||||
chunk_naming = "chunks/[name]-[hash].[ext]",
|
||||
asset_naming = "assets/[name]-[hash].[ext]",
|
||||
minify = True,
|
||||
minify_syntax = True,
|
||||
minify_whitespace = True,
|
||||
minify_identifiers = True,
|
||||
keep_names = True,
|
||||
css_chunking = True,
|
||||
conditions = [
|
||||
"browser",
|
||||
"custom",
|
||||
],
|
||||
env = "PUBLIC_*",
|
||||
define = [
|
||||
"process.env.NODE_ENV:\"production\"",
|
||||
"__DEV__:false",
|
||||
],
|
||||
drop = [
|
||||
"console",
|
||||
"debugger",
|
||||
],
|
||||
feature = [
|
||||
"react_fast_refresh",
|
||||
"server_components",
|
||||
],
|
||||
loader = [
|
||||
".svg:file",
|
||||
".txt:text",
|
||||
],
|
||||
jsx_factory = "h",
|
||||
jsx_fragment = "Fragment",
|
||||
jsx_import_source = "preact",
|
||||
jsx_runtime = "automatic",
|
||||
jsx_side_effects = True,
|
||||
react_fast_refresh = True,
|
||||
emit_dce_annotations = True,
|
||||
no_bundle = True,
|
||||
build_flags = [
|
||||
"--app",
|
||||
"--server-components",
|
||||
],
|
||||
)
|
||||
|
||||
bun_compile(
|
||||
name = "compiled_cli",
|
||||
entry_point = "cli.ts",
|
||||
)
|
||||
|
||||
bun_compile(
|
||||
name = "compiled_cli_with_flags",
|
||||
tags = ["manual"],
|
||||
entry_point = "cli.ts",
|
||||
bytecode = True,
|
||||
compile_exec_argv = [
|
||||
"--smol",
|
||||
"--inspect-wait",
|
||||
],
|
||||
compile_executable = "fake_cross_bun.bin",
|
||||
compile_autoload_dotenv = False,
|
||||
compile_autoload_bunfig = False,
|
||||
compile_autoload_tsconfig = True,
|
||||
compile_autoload_package_json = True,
|
||||
windows_hide_console = True,
|
||||
windows_icon = "branding/icon.ico",
|
||||
windows_title = "Rules Bun Test App",
|
||||
windows_publisher = "rules_bun",
|
||||
windows_version = "1.2.3.4",
|
||||
windows_description = "compile flag coverage",
|
||||
windows_copyright = "(c) rules_bun",
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bundle_output_test",
|
||||
srcs = ["verify_bundle.sh"],
|
||||
@@ -84,6 +174,20 @@ sh_test(
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bundle_sourcemap_shape_test",
|
||||
srcs = ["verify_sourcemap_shape.sh"],
|
||||
env_inherit = ["PATH"],
|
||||
data = [
|
||||
"//:repo_runtime_files",
|
||||
"//bun:repo_runtime_files",
|
||||
"//internal:repo_runtime_files",
|
||||
"BUILD.bazel",
|
||||
"//tests/bundle_test/sourcemap_case:BUILD.bazel",
|
||||
"//tests/bundle_test/sourcemap_case:entry.ts",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_build_site_output_test",
|
||||
srcs = ["verify_site_build.sh"],
|
||||
@@ -104,3 +208,20 @@ sh_test(
|
||||
args = ["$(location :compiled_cli)"],
|
||||
data = [":compiled_cli"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_build_compile_flag_shape_test",
|
||||
srcs = ["verify_flag_aquery.sh"],
|
||||
env_inherit = ["PATH"],
|
||||
data = [
|
||||
"//:repo_runtime_files",
|
||||
"//bun:repo_runtime_files",
|
||||
"//internal:repo_runtime_files",
|
||||
"BUILD.bazel",
|
||||
"cli.ts",
|
||||
"fake_cross_bun.bin",
|
||||
"site/index.html",
|
||||
"site/main.ts",
|
||||
"site/styles.css",
|
||||
],
|
||||
)
|
||||
|
||||
1
tests/bundle_test/fake_cross_bun.bin
Normal file
1
tests/bundle_test/fake_cross_bun.bin
Normal file
@@ -0,0 +1 @@
|
||||
placeholder
|
||||
11
tests/bundle_test/out.js
Normal file
11
tests/bundle_test/out.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// tests/bundle_test/main.ts
|
||||
function greet(name) {
|
||||
return `Hello ${name}`;
|
||||
}
|
||||
console.log(greet("bundle"));
|
||||
export {
|
||||
greet
|
||||
};
|
||||
|
||||
//# debugId=A86FEBA7FCC390B664756E2164756E21
|
||||
//# sourceMappingURL=out.js.map
|
||||
10
tests/bundle_test/out.js.map
Normal file
10
tests/bundle_test/out.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": ["tests/bundle_test/main.ts"],
|
||||
"sourcesContent": [
|
||||
"export function greet(name: string): string {\n return `Hello ${name}`;\n}\n\nconsole.log(greet(\"bundle\"));\n"
|
||||
],
|
||||
"mappings": ";AAAO,SAAS,KAAK,CAAC,MAAsB;AAAA,EAC1C,OAAO,SAAS;AAAA;AAGlB,QAAQ,IAAI,MAAM,QAAQ,CAAC;",
|
||||
"debugId": "A86FEBA7FCC390B664756E2164756E21",
|
||||
"names": []
|
||||
}
|
||||
11
tests/bundle_test/sourcemap_bundle__main.js
Normal file
11
tests/bundle_test/sourcemap_bundle__main.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// ../../../../../../../Projects/rules_bun/tests/bundle_test/main.ts
|
||||
function greet(name) {
|
||||
return `Hello ${name}`;
|
||||
}
|
||||
console.log(greet("bundle"));
|
||||
export {
|
||||
greet
|
||||
};
|
||||
|
||||
//# debugId=D8717FECBBDCEC7764756E2164756E21
|
||||
//# sourceMappingURL=sourcemap_bundle__main.js.map
|
||||
10
tests/bundle_test/sourcemap_bundle__main.js.map
Normal file
10
tests/bundle_test/sourcemap_bundle__main.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": ["../../../../../../../Projects/rules_bun/tests/bundle_test/main.ts"],
|
||||
"sourcesContent": [
|
||||
"export function greet(name: string): string {\n return `Hello ${name}`;\n}\n\nconsole.log(greet(\"bundle\"));\n"
|
||||
],
|
||||
"mappings": ";AAAO,SAAS,KAAK,CAAC,MAAsB;AAAA,EAC1C,OAAO,SAAS;AAAA;AAGlB,QAAQ,IAAI,MAAM,QAAQ,CAAC;",
|
||||
"debugId": "D8717FECBBDCEC7764756E2164756E21",
|
||||
"names": []
|
||||
}
|
||||
13
tests/bundle_test/sourcemap_case/BUILD.bazel
Normal file
13
tests/bundle_test/sourcemap_case/BUILD.bazel
Normal file
@@ -0,0 +1,13 @@
|
||||
load("//bun:defs.bzl", "bun_bundle")
|
||||
|
||||
exports_files([
|
||||
"BUILD.bazel",
|
||||
"entry.ts",
|
||||
])
|
||||
|
||||
bun_bundle(
|
||||
name = "sourcemap_bundle",
|
||||
tags = ["manual"],
|
||||
entry_points = ["entry.ts"],
|
||||
sourcemap = True,
|
||||
)
|
||||
3
tests/bundle_test/sourcemap_case/entry.ts
Normal file
3
tests/bundle_test/sourcemap_case/entry.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
const message: string = "sourcemap coverage";
|
||||
|
||||
console.log(message);
|
||||
@@ -4,7 +4,7 @@ set -euo pipefail
|
||||
rule_file="$1"
|
||||
build_file="$2"
|
||||
|
||||
grep -Eq 'for package in ctx\.attr\.external:' "${rule_file}"
|
||||
grep -Eq 'args\.add\("--external"\)' "${rule_file}"
|
||||
grep -Eq 'add_bun_build_common_flags\(args, ctx\.attr\)' "${rule_file}"
|
||||
grep -Eq '"external": attr\.string_list\(' "${rule_file}"
|
||||
grep -Eq 'name = "external_bundle"' "${build_file}"
|
||||
grep -Eq 'external = \["left-pad"\]' "${build_file}"
|
||||
|
||||
162
tests/bundle_test/verify_flag_aquery.sh
Executable file
162
tests/bundle_test/verify_flag_aquery.sh
Executable file
@@ -0,0 +1,162 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if command -v bazel >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazel)
|
||||
elif command -v bazelisk >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazelisk)
|
||||
else
|
||||
echo "bazel or bazelisk is required on PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
find_workspace_root() {
|
||||
local candidate
|
||||
local module_path
|
||||
local script_dir
|
||||
|
||||
for candidate in \
|
||||
"${TEST_SRCDIR:-}/${TEST_WORKSPACE:-}" \
|
||||
"${TEST_SRCDIR:-}/_main"; do
|
||||
if [[ -n ${candidate} && -f "${candidate}/MODULE.bazel" ]]; then
|
||||
printf '%s\n' "${candidate}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -n ${TEST_SRCDIR:-} ]]; then
|
||||
module_path="$(find "${TEST_SRCDIR}" -maxdepth 3 -name MODULE.bazel -print -quit 2>/dev/null || true)"
|
||||
if [[ -n ${module_path} ]]; then
|
||||
dirname "${module_path}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
candidate="$(cd "${script_dir}/../.." && pwd -P)"
|
||||
if [[ -f "${candidate}/MODULE.bazel" ]]; then
|
||||
printf '%s\n' "${candidate}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Unable to locate rules_bun workspace root" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
rules_bun_root="$(find_workspace_root)"
|
||||
|
||||
run_aquery() {
|
||||
local mnemonic="$1"
|
||||
local target="$2"
|
||||
|
||||
(
|
||||
cd "${rules_bun_root}" &&
|
||||
"${bazel_cmd[@]}" aquery "mnemonic(\"${mnemonic}\", ${target})" --output=textproto
|
||||
)
|
||||
}
|
||||
|
||||
expect_line() {
|
||||
local output="$1"
|
||||
local expected="$2"
|
||||
|
||||
if ! grep -Fq -- "${expected}" <<<"${output}"; then
|
||||
echo "Expected aquery output to contain: ${expected}" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
build_output="$(run_aquery "BunBuild" "//tests/bundle_test:advanced_site_build")"
|
||||
|
||||
for expected in \
|
||||
'arguments: "--install"' \
|
||||
'arguments: "fallback"' \
|
||||
'arguments: "--target"' \
|
||||
'arguments: "node"' \
|
||||
'arguments: "--format"' \
|
||||
'arguments: "cjs"' \
|
||||
'arguments: "--production"' \
|
||||
'arguments: "--splitting"' \
|
||||
'arguments: "--root"' \
|
||||
'arguments: "tests/bundle_test/site"' \
|
||||
'arguments: "--sourcemap"' \
|
||||
'arguments: "linked"' \
|
||||
'arguments: "--banner"' \
|
||||
'arguments: "/* bundle banner */"' \
|
||||
'arguments: "--footer"' \
|
||||
'arguments: "// bundle footer"' \
|
||||
'arguments: "--public-path"' \
|
||||
'arguments: "/static/"' \
|
||||
'arguments: "--packages"' \
|
||||
'arguments: "external"' \
|
||||
'arguments: "left-pad"' \
|
||||
'arguments: "react"' \
|
||||
'arguments: "--entry-naming"' \
|
||||
'arguments: "entries/[name]-[hash].[ext]"' \
|
||||
'arguments: "--chunk-naming"' \
|
||||
'arguments: "chunks/[name]-[hash].[ext]"' \
|
||||
'arguments: "--asset-naming"' \
|
||||
'arguments: "assets/[name]-[hash].[ext]"' \
|
||||
'arguments: "--minify"' \
|
||||
'arguments: "--minify-syntax"' \
|
||||
'arguments: "--minify-whitespace"' \
|
||||
'arguments: "--minify-identifiers"' \
|
||||
'arguments: "--keep-names"' \
|
||||
'arguments: "--css-chunking"' \
|
||||
'arguments: "--conditions"' \
|
||||
'arguments: "browser"' \
|
||||
'arguments: "custom"' \
|
||||
'arguments: "--env"' \
|
||||
'arguments: "PUBLIC_*"' \
|
||||
'arguments: "process.env.NODE_ENV:\"production\""' \
|
||||
'arguments: "__DEV__:false"' \
|
||||
'arguments: "console"' \
|
||||
'arguments: "debugger"' \
|
||||
'arguments: "react_fast_refresh"' \
|
||||
'arguments: "server_components"' \
|
||||
'arguments: ".svg:file"' \
|
||||
'arguments: ".txt:text"' \
|
||||
'arguments: "--jsx-factory"' \
|
||||
'arguments: "h"' \
|
||||
'arguments: "--jsx-fragment"' \
|
||||
'arguments: "Fragment"' \
|
||||
'arguments: "--jsx-import-source"' \
|
||||
'arguments: "preact"' \
|
||||
'arguments: "--jsx-runtime"' \
|
||||
'arguments: "automatic"' \
|
||||
'arguments: "--jsx-side-effects"' \
|
||||
'arguments: "--react-fast-refresh"' \
|
||||
'arguments: "--emit-dce-annotations"' \
|
||||
'arguments: "--no-bundle"' \
|
||||
'arguments: "--app"' \
|
||||
'arguments: "--server-components"'; do
|
||||
expect_line "${build_output}" "${expected}"
|
||||
done
|
||||
|
||||
compile_output="$(run_aquery "BunCompile" "//tests/bundle_test:compiled_cli_with_flags")"
|
||||
|
||||
for expected in \
|
||||
'arguments: "--bytecode"' \
|
||||
'arguments: "--compile-exec-argv"' \
|
||||
'arguments: "--smol"' \
|
||||
'arguments: "--inspect-wait"' \
|
||||
'arguments: "--no-compile-autoload-dotenv"' \
|
||||
'arguments: "--no-compile-autoload-bunfig"' \
|
||||
'arguments: "--compile-autoload-tsconfig"' \
|
||||
'arguments: "--compile-autoload-package-json"' \
|
||||
'arguments: "--compile-executable-path"' \
|
||||
'arguments: "tests/bundle_test/fake_cross_bun.bin"' \
|
||||
'arguments: "--windows-hide-console"' \
|
||||
'arguments: "--windows-icon"' \
|
||||
'arguments: "branding/icon.ico"' \
|
||||
'arguments: "--windows-title"' \
|
||||
'arguments: "Rules Bun Test App"' \
|
||||
'arguments: "--windows-publisher"' \
|
||||
'arguments: "rules_bun"' \
|
||||
'arguments: "--windows-version"' \
|
||||
'arguments: "1.2.3.4"' \
|
||||
'arguments: "--windows-description"' \
|
||||
'arguments: "compile flag coverage"' \
|
||||
'arguments: "--windows-copyright"' \
|
||||
'arguments: "(c) rules_bun"'; do
|
||||
expect_line "${compile_output}" "${expected}"
|
||||
done
|
||||
60
tests/bundle_test/verify_sourcemap_shape.sh
Executable file
60
tests/bundle_test/verify_sourcemap_shape.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if command -v bazel >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazel)
|
||||
elif command -v bazelisk >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazelisk)
|
||||
else
|
||||
echo "bazel or bazelisk is required on PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
find_workspace_root() {
|
||||
local candidate
|
||||
local module_path
|
||||
local script_dir
|
||||
|
||||
for candidate in \
|
||||
"${TEST_SRCDIR:-}/${TEST_WORKSPACE:-}" \
|
||||
"${TEST_SRCDIR:-}/_main"; do
|
||||
if [[ -n ${candidate} && -f "${candidate}/MODULE.bazel" ]]; then
|
||||
printf '%s\n' "${candidate}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -n ${TEST_SRCDIR:-} ]]; then
|
||||
module_path="$(find "${TEST_SRCDIR}" -maxdepth 3 -name MODULE.bazel -print -quit 2>/dev/null || true)"
|
||||
if [[ -n ${module_path} ]]; then
|
||||
dirname "${module_path}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
candidate="$(cd "${script_dir}/../.." && pwd -P)"
|
||||
if [[ -f "${candidate}/MODULE.bazel" ]]; then
|
||||
printf '%s\n' "${candidate}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Unable to locate rules_bun workspace root" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
rules_bun_root="$(find_workspace_root)"
|
||||
|
||||
bundle_output="$(
|
||||
cd "${rules_bun_root}" &&
|
||||
"${bazel_cmd[@]}" aquery 'mnemonic("BunBundle", //tests/bundle_test/sourcemap_case:sourcemap_bundle)' --output=textproto
|
||||
)"
|
||||
|
||||
count="$(grep -Fc 'arguments: "--sourcemap"' <<<"${bundle_output}")"
|
||||
if [[ ${count} != "1" ]]; then
|
||||
echo "Expected bun_bundle(sourcemap = True) to emit exactly one --sourcemap flag, got ${count}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grep -Fq 'arguments: "--outfile"' <<<"${bundle_output}"
|
||||
grep -Fq 'arguments: "tests/bundle_test/sourcemap_case/entry.ts"' <<<"${bundle_output}"
|
||||
@@ -122,6 +122,30 @@ sh_test(
|
||||
}),
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_workspace_parity_test",
|
||||
srcs = ["workspace_parity.sh"],
|
||||
env_inherit = ["PATH"],
|
||||
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"],
|
||||
}) + [
|
||||
"//:repo_runtime_files",
|
||||
"//bun:repo_runtime_files",
|
||||
"//internal:repo_runtime_files",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_install_flags_shape_test",
|
||||
srcs = ["install_flags_shape.sh"],
|
||||
|
||||
@@ -4,10 +4,11 @@ set -euo pipefail
|
||||
rule_file="$1"
|
||||
|
||||
grep -Eq 'install", "--frozen-lockfile", "--no-progress"' "${rule_file}"
|
||||
grep -Eq 'repository_ctx\.file\("package\.json", repository_ctx\.read\(package_json\)\)' "${rule_file}"
|
||||
grep -Eq 'repository_ctx\.file\("package\.json", _normalized_root_manifest\(repository_ctx, package_json\)\)' "${rule_file}"
|
||||
grep -Eq 'lockfile_name = bun_lockfile\.basename' "${rule_file}"
|
||||
grep -Eq 'if lockfile_name not in \["bun\.lock", "bun\.lockb"\]:' "${rule_file}"
|
||||
grep -Eq 'repository_ctx\.symlink\(bun_lockfile, lockfile_name\)' "${rule_file}"
|
||||
grep -Eq 'glob\(\["\*\*/node_modules/\*\*"\]' "${rule_file}"
|
||||
grep -Eq '_DEFAULT_INSTALL_INPUTS = \[' "${rule_file}"
|
||||
grep -Eq '"install_inputs": attr\.label_list\(allow_files = True\)' "${rule_file}"
|
||||
grep -Eq '_materialize_install_inputs\(repository_ctx, package_json\)' "${rule_file}"
|
||||
|
||||
@@ -3,8 +3,12 @@ set -euo pipefail
|
||||
|
||||
bun_path="${1:-bun}"
|
||||
|
||||
if ! command -v bazel >/dev/null 2>&1; then
|
||||
echo "bazel is required on PATH" >&2
|
||||
if command -v bazel >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazel)
|
||||
elif command -v bazelisk >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazelisk)
|
||||
else
|
||||
echo "bazel or bazelisk is required on PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -199,12 +203,12 @@ chmod +x "${bazel_dir}/node_modules_smoke_test.sh"
|
||||
|
||||
(
|
||||
cd "${bazel_dir}"
|
||||
bazel build @node_modules//:node_modules >/dev/null
|
||||
bazel test //:node_modules_smoke_test >/dev/null
|
||||
bazel run //:web_build -- --emptyOutDir >/dev/null
|
||||
"${bazel_cmd[@]}" build @node_modules//:node_modules >/dev/null
|
||||
"${bazel_cmd[@]}" test //:node_modules_smoke_test >/dev/null
|
||||
"${bazel_cmd[@]}" run //:web_build -- --emptyOutDir >/dev/null
|
||||
)
|
||||
|
||||
output_base="$(cd "${bazel_dir}" && bazel info output_base)"
|
||||
output_base="$(cd "${bazel_dir}" && "${bazel_cmd[@]}" info output_base)"
|
||||
bazel_repo_dir="$(find "${output_base}/external" -maxdepth 1 -type d -name '*+node_modules' | head -n 1)"
|
||||
|
||||
if [[ -z ${bazel_repo_dir} ]]; then
|
||||
@@ -238,6 +242,8 @@ root = sys.argv[1]
|
||||
|
||||
def include(rel):
|
||||
if rel == "node_modules" or rel.startswith("node_modules/"):
|
||||
if rel == "node_modules/.rules_bun" or rel.startswith("node_modules/.rules_bun/"):
|
||||
return False
|
||||
return True
|
||||
if rel.startswith("packages/") and "/node_modules" in rel:
|
||||
return True
|
||||
@@ -283,6 +289,8 @@ root = sys.argv[1]
|
||||
|
||||
def include(rel):
|
||||
if rel == "node_modules" or rel.startswith("node_modules/"):
|
||||
if rel == "node_modules/.rules_bun" or rel.startswith("node_modules/.rules_bun/"):
|
||||
return False
|
||||
return True
|
||||
if rel.startswith("packages/") and "/node_modules" in rel:
|
||||
return True
|
||||
@@ -343,6 +351,8 @@ for dirpath, dirnames, filenames in os.walk(root, topdown=True, followlinks=Fals
|
||||
for name in dirnames + filenames:
|
||||
full = os.path.join(dirpath, name)
|
||||
rel = os.path.join(rel_dir, name) if rel_dir else name
|
||||
if rel == ".rules_bun" or rel.startswith(".rules_bun/"):
|
||||
continue
|
||||
st = os.lstat(full)
|
||||
mode = st.st_mode
|
||||
if stat.S_ISLNK(mode):
|
||||
@@ -379,6 +389,8 @@ for dirpath, dirnames, filenames in os.walk(root, topdown=True, followlinks=Fals
|
||||
for name in dirnames + filenames:
|
||||
full = os.path.join(dirpath, name)
|
||||
rel = os.path.join(rel_dir, name) if rel_dir else name
|
||||
if rel == ".rules_bun" or rel.startswith(".rules_bun/"):
|
||||
continue
|
||||
st = os.lstat(full)
|
||||
mode = st.st_mode
|
||||
if stat.S_ISLNK(mode):
|
||||
@@ -411,7 +423,7 @@ rm -rf "${plain_dist_dir}" "${bazel_dist_dir}"
|
||||
|
||||
(
|
||||
cd "${bazel_dir}"
|
||||
bazel run //:web_build -- --emptyOutDir --outDir "${bazel_dist_dir}" >/dev/null
|
||||
"${bazel_cmd[@]}" run //:web_build -- --emptyOutDir --outDir "${bazel_dist_dir}" >/dev/null
|
||||
)
|
||||
|
||||
if [[ ! -d ${plain_dist_dir} ]]; then
|
||||
|
||||
@@ -4,6 +4,7 @@ test_suite(
|
||||
name = "examples_test",
|
||||
tests = [
|
||||
":examples_basic_run_e2e_test",
|
||||
":examples_basic_hot_restart_shape_test",
|
||||
":examples_workspace_bundle_e2e_test",
|
||||
":examples_workspace_catalog_shape_test",
|
||||
":examples_vite_monorepo_catalog_shape_test",
|
||||
@@ -31,6 +32,13 @@ sh_test(
|
||||
data = ["//examples/basic:web_dev"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "examples_basic_hot_restart_shape_test",
|
||||
srcs = ["examples_basic_hot_restart_shape_test.sh"],
|
||||
args = ["$(location //examples/basic:web_dev_hot_restart)"],
|
||||
data = ["//examples/basic:web_dev_hot_restart"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "examples_workspace_bundle_e2e_test",
|
||||
srcs = ["examples_workspace_bundle_e2e_test.sh"],
|
||||
|
||||
11
tests/integration_test/examples_basic_hot_restart_shape_test.sh
Executable file
11
tests/integration_test/examples_basic_hot_restart_shape_test.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
|
||||
grep -Fq -- 'watch_mode="hot"' "${binary}"
|
||||
grep -Fq -- 'bun_args+=("--hot")' "${binary}"
|
||||
grep -Fq -- '--no-clear-screen' "${binary}"
|
||||
grep -Fq -- 'if [[ 1 -eq 0 ]]; then' "${binary}"
|
||||
grep -Fq -- 'readarray -t restart_paths' "${binary}"
|
||||
grep -Fq -- 'examples/basic/README.md' "${binary}"
|
||||
@@ -39,3 +39,30 @@ sh_test(
|
||||
args = ["$(location :compat_devserver)"],
|
||||
data = [":compat_devserver"],
|
||||
)
|
||||
|
||||
js_run_devserver(
|
||||
name = "compat_devserver_with_package_json",
|
||||
tool = ":compat_bin",
|
||||
package_json = "app/package.json",
|
||||
working_dir = "package",
|
||||
)
|
||||
|
||||
js_run_devserver(
|
||||
name = "compat_devserver_with_package_dir_hint",
|
||||
tool = ":compat_bin",
|
||||
package_dir_hint = "app",
|
||||
working_dir = "package",
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "js_run_devserver_workspace_shape_test",
|
||||
srcs = ["verify_workspace_shape.sh"],
|
||||
args = [
|
||||
"$(location :compat_devserver_with_package_json)",
|
||||
"$(location :compat_devserver_with_package_dir_hint)",
|
||||
],
|
||||
data = [
|
||||
":compat_devserver_with_package_json",
|
||||
":compat_devserver_with_package_dir_hint",
|
||||
],
|
||||
)
|
||||
|
||||
4
tests/js_compat_test/app/package.json
Normal file
4
tests/js_compat_test/app/package.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "js-compat-app",
|
||||
"private": true
|
||||
}
|
||||
13
tests/js_compat_test/verify_workspace_shape.sh
Executable file
13
tests/js_compat_test/verify_workspace_shape.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
package_json_launcher="$1"
|
||||
package_dir_hint_launcher="$2"
|
||||
|
||||
grep -Fq -- 'package_json="${runfiles_dir}/_main/tests/js_compat_test/app/package.json"' "${package_json_launcher}"
|
||||
grep -Fq -- 'package_rel_dir_hint="."' "${package_json_launcher}"
|
||||
grep -Fq -- 'working_dir_mode="package"' "${package_json_launcher}"
|
||||
|
||||
grep -Fq -- 'package_json=""' "${package_dir_hint_launcher}"
|
||||
grep -Fq -- 'package_rel_dir_hint="app"' "${package_dir_hint_launcher}"
|
||||
grep -Fq -- 'working_dir_mode="package"' "${package_dir_hint_launcher}"
|
||||
59
tests/npm_compat_test/BUILD.bazel
Normal file
59
tests/npm_compat_test/BUILD.bazel
Normal file
@@ -0,0 +1,59 @@
|
||||
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 = "npm_translate_lock_workspace_test",
|
||||
srcs = ["npm_translate_lock_workspace_test.sh"],
|
||||
env_inherit = ["PATH"],
|
||||
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"],
|
||||
}) + [
|
||||
"//:repo_runtime_files",
|
||||
"//bun:repo_runtime_files",
|
||||
"//internal:repo_runtime_files",
|
||||
"//js:repo_runtime_files",
|
||||
"//npm:repo_runtime_files",
|
||||
],
|
||||
)
|
||||
@@ -1,15 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
nix_cmd="${NIX:-/nix/var/nix/profiles/default/bin/nix}"
|
||||
if [[ ! -x ${nix_cmd} ]]; then
|
||||
nix_cmd="$(command -v nix || true)"
|
||||
fi
|
||||
if [[ -z ${nix_cmd} || ! -x ${nix_cmd} ]]; then
|
||||
echo "nix is required to launch bazel from the repo dev shell" >&2
|
||||
if command -v bazel >/dev/null 2>&1; then
|
||||
bazel_bin="$(command -v bazel)"
|
||||
elif command -v bazelisk >/dev/null 2>&1; then
|
||||
bazel_bin="$(command -v bazelisk)"
|
||||
else
|
||||
echo "bazel or bazelisk is required on PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
bun_path="${1:-bun}"
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
rules_bun_root="$(cd "${script_dir}/../.." && pwd -P)"
|
||||
|
||||
@@ -35,10 +37,7 @@ import isNumber from "is-number";
|
||||
console.log(`compat:${isNumber(42)}`);
|
||||
JS
|
||||
|
||||
(
|
||||
cd "${rules_bun_root}" &&
|
||||
"${nix_cmd}" develop -c bash -lc 'bun install --cwd "$1" >/dev/null' bash "${fixture_dir}"
|
||||
)
|
||||
"${bun_path}" install --cwd "${fixture_dir}" >/dev/null
|
||||
rm -rf "${fixture_dir}/node_modules"
|
||||
|
||||
cat >"${fixture_dir}/MODULE.bazel" <<EOF
|
||||
@@ -100,8 +99,8 @@ js_binary(
|
||||
EOF
|
||||
|
||||
output="$(
|
||||
cd "${rules_bun_root}" &&
|
||||
"${nix_cmd}" develop -c bash -lc 'cd "$1" && bazel run //:app' bash "${fixture_dir}"
|
||||
cd "${fixture_dir}" &&
|
||||
"${bazel_bin}" run //:app
|
||||
)"
|
||||
|
||||
if [[ ${output} != *"compat:true"* ]]; then
|
||||
@@ -110,8 +109,8 @@ if [[ ${output} != *"compat:true"* ]]; then
|
||||
fi
|
||||
|
||||
query_output="$(
|
||||
cd "${rules_bun_root}" &&
|
||||
"${nix_cmd}" develop -c bash -lc 'cd "$1" && bazel query //:npm__is_number' bash "${fixture_dir}"
|
||||
cd "${fixture_dir}" &&
|
||||
"${bazel_bin}" query //:npm__is_number
|
||||
)"
|
||||
if ! grep -Fxq "//:npm__is_number" <<<"${query_output}"; then
|
||||
echo "expected npm_link_all_packages to create //:npm__is_number" >&2
|
||||
|
||||
@@ -165,3 +165,54 @@ sh_test(
|
||||
args = ["$(location :workspace_filtered_script)"],
|
||||
data = [":workspace_filtered_script"],
|
||||
)
|
||||
|
||||
bun_script(
|
||||
name = "workspace_parallel_script",
|
||||
script = "say",
|
||||
package_json = "workspace_run/package.json",
|
||||
data = [
|
||||
"workspace_run/packages/pkg-a/package.json",
|
||||
"workspace_run/packages/pkg-a/say.ts",
|
||||
"workspace_run/packages/pkg-b/package.json",
|
||||
"workspace_run/packages/pkg-b/say.ts",
|
||||
],
|
||||
workspaces = True,
|
||||
execution_mode = "parallel",
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_script_workspace_parallel_test",
|
||||
srcs = ["run_workspace_parallel.sh"],
|
||||
args = ["$(location :workspace_parallel_script)"],
|
||||
data = [":workspace_parallel_script"],
|
||||
)
|
||||
|
||||
bun_script(
|
||||
name = "workspace_flagged_script",
|
||||
script = "say",
|
||||
package_json = "workspace_run/package.json",
|
||||
data = [
|
||||
"workspace_run/packages/pkg-a/package.json",
|
||||
"workspace_run/packages/pkg-a/say.ts",
|
||||
"workspace_run/packages/pkg-b/package.json",
|
||||
"workspace_run/packages/pkg-b/say.ts",
|
||||
],
|
||||
workspaces = True,
|
||||
execution_mode = "parallel",
|
||||
no_exit_on_error = True,
|
||||
shell = "system",
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_script_workspace_flag_shape_test",
|
||||
srcs = ["verify_launcher_flags.sh"],
|
||||
args = [
|
||||
"$(location :workspace_flagged_script)",
|
||||
"--workspaces",
|
||||
"--parallel",
|
||||
"--no-exit-on-error",
|
||||
"--shell",
|
||||
"system",
|
||||
],
|
||||
data = [":workspace_flagged_script"],
|
||||
)
|
||||
|
||||
15
tests/script_test/run_workspace_parallel.sh
Executable file
15
tests/script_test/run_workspace_parallel.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
script_bin="$1"
|
||||
output="$(${script_bin})"
|
||||
|
||||
if [[ ${output} != *"pkg-a"* ]]; then
|
||||
echo "Expected workspace parallel run output to include pkg-a: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ${output} != *"pkg-b"* ]]; then
|
||||
echo "Expected workspace parallel run output to include pkg-b: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
12
tests/script_test/verify_launcher_flags.sh
Executable file
12
tests/script_test/verify_launcher_flags.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
shift
|
||||
|
||||
for expected in "$@"; do
|
||||
if ! grep -Fq -- "${expected}" "${binary}"; then
|
||||
echo "Expected ${binary} to contain ${expected}" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user