blob: dcca4c1db37218b743b78bec7ff425f349196073 [file]
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary", "js_test")
load("@bazel_lib//lib:testing.bzl", "assert_contains")
load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages()
js_test(
name = "runfiles",
data = [
"test_fixture.md",
"test_fixture.md.generated_file_suffix",
":node_modules/@bazel/runfiles",
],
entry_point = "test.js",
tags = [
"skip-on-bazel8",
"skip-on-bazel9",
],
)
js_test(
name = "module_name_runfiles",
data = [
"test_fixture.md",
"test_fixture.md.generated_file_suffix",
":node_modules/@bazel/runfiles",
],
entry_point = "module_name_test.js",
)
# Path of file must start similar to `test_fixture.md` in order to regression-test a
# scenario where the runfile resolution would accidentally resolve the path to
# `test_fixture.md` through a runfile manifest entry that starts similarly.
genrule(
name = "gen-data",
outs = ["test_fixture.md.generated_file_suffix"],
cmd = """echo "Generated" > $@""",
)
js_binary(
name = "test_binary",
data = [
"test_fixture.md",
"test_fixture.md.generated_file_suffix",
":node_modules/@bazel/runfiles",
],
entry_point = "resolve-args.js",
)
js_run_binary(
name = "run_test_binary",
srcs = ["test_fixture.md"],
args = [
"test_fixture.md",
"test_fixture.md.generated_file_suffix",
],
stdout = "out1.txt",
tool = ":test_binary",
)
assert_contains(
name = "run_test_binary_asserts__direct_srcs",
actual = ":out1.txt",
expected = "test_fixture.md",
)
assert_contains(
name = "run_test_binary_asserts__transitive_data",
actual = ":out1.txt",
expected = "test_fixture.md.generated_file_suffix",
)
# Test that a js_binary wrapping another js_binary correctly propagates RUNFILES_DIR
# so the inner binary's @bazel/runfiles can locate its runfiles.
js_binary(
name = "outer_binary",
data = [
":node_modules/@bazel/runfiles",
":test_binary",
],
entry_point = "outer.js",
)
js_run_binary(
name = "run_outer_binary",
srcs = ["test_fixture.md"],
args = [
"test_fixture.md",
"test_fixture.md.generated_file_suffix",
],
stdout = "out2.txt",
tool = ":outer_binary",
)
assert_contains(
name = "run_outer_binary_asserts__direct_srcs",
actual = ":out2.txt",
expected = "test_fixture.md",
)
assert_contains(
name = "run_outer_binary_asserts__transitive_data",
actual = ":out2.txt",
expected = "test_fixture.md.generated_file_suffix",
)
js_test(
name = "outer_runfiles",
data = [
"test_fixture.md",
"test_fixture.md.generated_file_suffix",
":test_binary",
],
entry_point = "outer.js",
)