Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion js/private/js_binary.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ fi
# Change directory to user specified package if set
if [ "${JS_BINARY__CHDIR:-}" ]; then
logf_debug "changing directory to user specified package %s" "$JS_BINARY__CHDIR"
cd "$JS_BINARY__EXECROOT/${BAZEL_BINDIR:-$JS_BINARY__BINDIR}/$JS_BINARY__CHDIR"
case "$JS_BINARY__CHDIR" in
external/*) cd "$(resolve_execroot_bin_path "$JS_BINARY__CHDIR")" ;;
*) cd "$JS_BINARY__CHDIR" ;;
esac
fi

# Gather node options
Expand Down
36 changes: 36 additions & 0 deletions js/private/test/data/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,42 @@ js_test(
entry_point = "test.js",
)

# TEST: js_test(data = source file, chdir = package_name())
# This test and the following one verify that with `chdir = package_name()` we
# are changing to the correct directory, by making sure data.json is present in
# the working directory.
js_test(
name = "chdir-source-data",
args = ["data.json"],
chdir = package_name(),
data = [":data.json"],
entry_point = "open_arg.mjs",
)

js_test(
name = "chdir-source-data-relative",
args = ["./data.json"],
chdir = package_name(),
data = [":data.json"],
entry_point = "open_arg.mjs",
)

# TEST: js_test(data = source file, chdir = None) with rootpath
js_test(
name = "source-data-rootpath",
args = ["$(rootpath :data.json)"],
data = [":data.json"],
entry_point = "open_arg.mjs",
)

# TEST: js_test(data = source file, chdir = None) with execpath
js_test(
name = "source-data-execpath",
args = ["$(execpath :data.json)"],
data = [":data.json"],
entry_point = "open_arg.mjs",
)

# TEST: js_test(data = genrule()) -------------------------
js_test(
name = "from-genrule",
Expand Down
2 changes: 2 additions & 0 deletions js/private/test/data/open_arg.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { readFileSync } from 'fs';
readFileSync(process.argv[2]);
5 changes: 4 additions & 1 deletion js/private/test/snapshots/launcher.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading