blob: 704ed6c1e9927fb19ef057a3af0b170f5ea050b2 [file]
load("//:defs.bzl", "nodejs_binary", "nodejs_test")
load("//internal/js_library:js_library.bzl", "js_library")
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file")
load(":nodejs_toolchain_test.bzl", "nodejs_binary_test_suite")
nodejs_binary_test_suite()
# You can have a nodejs_binary with no node_modules attribute
# and no fine grained deps
nodejs_binary(
name = "no_deps",
data = ["no-deps.js"],
entry_point = ":no-deps.js",
)
# You can have a nodejs_binary with a node_modules attribute
# and no fine grained deps
nodejs_binary(
name = "has_deps_legacy",
data = ["has-deps.js"],
entry_point = ":has-deps.js",
node_modules = "@fine_grained_deps_yarn//:node_modules",
)
# You can have a nodejs_binary with no node_modules attribute
# and fine grained deps
nodejs_binary(
name = "has_deps",
data = [
"has-deps.js",
"@fine_grained_deps_yarn//typescript",
],
entry_point = ":has-deps.js",
)
# You can have a nodejs_binary with both a node_modules attribute
# and fine grained deps so long as they come from the same root
nodejs_binary(
name = "has_deps_hybrid",
data = [
"has-deps.js",
"@fine_grained_deps_yarn//typescript",
],
entry_point = ":has-deps.js",
node_modules = "@fine_grained_deps_yarn//:node_modules",
)
filegroup(
name = "entry_file",
srcs = ["no-deps.js"],
)
nodejs_binary(
name = "has_entry_file",
entry_point = ":entry_file",
)
# Coverage for issue https://github.com/bazelbuild/rules_nodejs/issues/834
# where module_name is equal to the workspace naem
js_library(
name = "module_name_lib",
srcs = ["module-name.js"],
module_name = "build_bazel_rules_nodejs",
)
nodejs_binary(
name = "module_name_test",
data = [":module_name_lib"],
entry_point = ":module-name.js",
)
nodejs_test(
name = "define_var",
configuration_env_vars = ["SOME_TEST_ENV"],
data = glob(["*.spec.js"]),
entry_point = ":define.spec.js",
)
nodejs_test(
name = "mode_resolution_test",
data = [
"//internal/node/test/lib1",
"@npm//node_resolve_index",
"@npm//node_resolve_index_2",
"@npm//node_resolve_index_3",
"@npm//node_resolve_index_4",
"@npm//node_resolve_main",
"@npm//node_resolve_main_2",
"@npm//node_resolve_nested_main",
],
entry_point = ":module_resolution.spec.js",
)
nodejs_test(
name = "data_resolution_test",
data = [
"data/data.json",
],
entry_point = ":data_resolution.spec.js",
)
# Also test resolution from built files.
copy_file(
name = "module_resolution_lib",
src = "module_resolution.spec.js",
out = "module_resolution_built.spec.js",
)
copy_file(
name = "data_resolution_lib",
src = "data_resolution.spec.js",
out = "data_resolution_built.spec.js",
)
# This rule creates a file that alphabetically comes before any source file in this
# package. This genfile can be then set up as runfile to verify that the "node_loader.js"
# properly determines the local workspace path without incorrectly using the genfile as base
# for the local workspace path. See: https://github.com/bazelbuild/rules_nodejs/issues/352
write_file(
name = "genfile-runfile",
out = "#LEADING.txt",
)
nodejs_test(
name = "mode_resolution_built_test",
data = [
"//internal/node/test/lib1",
"@npm//node_resolve_index",
"@npm//node_resolve_index_2",
"@npm//node_resolve_index_3",
"@npm//node_resolve_index_4",
"@npm//node_resolve_main",
"@npm//node_resolve_main_2",
"@npm//node_resolve_nested_main",
],
entry_point = ":module_resolution_built.spec.js",
)
nodejs_test(
name = "data_resolution_built_test",
data = [
"data/data.json",
":genfile-runfile",
],
entry_point = ":data_resolution_built.spec.js",
)