test: add more tests
This commit is contained in:
@@ -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}"
|
||||
Reference in New Issue
Block a user