| load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test") |
| load(":rule.bzl", "linked") |
| |
| # Use the node binary supplied by the bazel toolchain |
| # Normally the nodejs_binary rule would do this, |
| # but we want to have a more minimal test fixture |
| genrule( |
| name = "replace_node_path", |
| srcs = [":run_program.sh"], |
| outs = ["run_program_with_node.sh"], |
| cmd = "sed s#NODE_PATH#$(NODE_PATH)# $< > $@", |
| toolchains = ["@build_bazel_rules_nodejs//toolchains/node:toolchain"], |
| ) |
| |
| # A program from a *_test rule with a module mapped package that will |
| # by linked as "runfiles" mapping by downstream rules |
| sh_test( |
| name = "some_program", |
| srcs = ["some_program.sh"], |
| data = [ |
| "//internal/linker/test/integration/transitive_static_linked_pkg", |
| ], |
| ) |
| |
| # Make our program executable and include the linker |
| # The runfiles here are only the ones included with the program itself |
| sh_binary( |
| name = "run_program", |
| testonly = True, |
| srcs = ["run_program_with_node.sh"], |
| data = [ |
| ":program.js", |
| # Include `:some_program` as a data dep so we get the |
| # transitive_static_linked_pkg "runfiles" mapping transitively. This test verifies that |
| # `bazel-out/darwin-fastbuild/bin/internal/linker/test/integration/run_program.runfiles` |
| # also contains the runfiles from |
| # `bazel-out/darwin-fastbuild/bin/internal/linker/test/integration/some_program.runfiles` |
| # as it has `:some_program` as a data dep and that the linker will correctly link |
| # "runfiles" module mappings from `:some_program` in `:run_program` under the |
| ":some_program", |
| "//internal/linker:index.js", |
| "//internal/linker/test/integration/static_linked_pkg", |
| "//internal/linker/test/integration/static_linked_scoped_pkg", |
| "@bazel_tools//tools/bash/runfiles", |
| "@build_bazel_rules_nodejs//toolchains/node:node_bin", |
| ], |
| ) |
| |
| # How a users rule might want to run a node program |
| linked( |
| name = "example", |
| testonly = True, |
| out = "actual", |
| program = ":run_program", |
| deps = [ |
| # NB: reference the copy of index.js in the output folder |
| "//%s/absolute_import:copy_to_bin" % package_name(), |
| ":run_program", |
| # NB: Verify that a direct dep on :some_program and a transitive dep on |
| # the same via :run_program works with the linker. These should both |
| # bring in the transitive_static_linked mapping to |
| # ["runfiles", "build_bazel_rules_nodejs/internal/linker/test/integration/transitive_static_linked_pkg"]. |
| # This tests that the linker does "runfiles" mappings for both *_binary target |
| # and *_test targets. |
| ":some_program", |
| "//internal/linker/test/integration/dynamic_linked_pkg", |
| "//internal/linker/test/integration/dynamic_linked_scoped_pkg", |
| "@npm//semver", |
| ], |
| ) |
| |
| # Test that the linker can handle duplicate module mappings. "src" and "bin" |
| # mappings will win over the "runfiles" mapping that comes from a dep on a |
| # *_binary or *_test rule. |
| linked( |
| name = "example_with_conflicts", |
| testonly = True, |
| out = "actual_with_conflicts", |
| program = ":run_program", |
| deps = [ |
| # NB: reference the copy of index.js in the output folder |
| "//%s/absolute_import:copy_to_bin" % package_name(), |
| ":run_program", |
| # NB: static_linked maps to both |
| # ["runfiles", "build_bazel_rules_nodejs/internal/linker/test/integration/static_linked_pkg"] and |
| # ["bin", "build_bazel_rules_nodejs/internal/linker/test/integration/static_linked_pkg"] |
| # as the "runfiles" mapping comes from `:run_program` |
| "//internal/linker/test/integration/static_linked_pkg", |
| # NB: @linker_scoped/static_linked maps to both |
| # ["runfiles", "build_bazel_rules_nodejs/internal/linker/test/integration/static_linked_scoped_pkg"] and |
| # ["src", "build_bazel_rules_nodejs/internal/linker/test/integration/static_linked_scoped_pkg"] |
| # as the "runfiles" mapping comes from `:run_program` |
| "//internal/linker/test/integration/static_linked_scoped_pkg", |
| "//internal/linker/test/integration/dynamic_linked_pkg", |
| "//internal/linker/test/integration/dynamic_linked_scoped_pkg", |
| "@npm//semver", |
| ], |
| ) |
| |
| golden_file_test( |
| # default rule in this package |
| name = "integration", |
| actual = "actual", |
| golden = "golden.txt", |
| ) |
| |
| golden_file_test( |
| # default rule in this package |
| name = "integration_conflicts", |
| actual = "actual_with_conflicts", |
| golden = "golden.txt", |
| ) |