-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): allow for working directory to be configured in integrat…
…ion tests Allows for the working directory of an integration test to be configured. This is useful when a test cannot be declared directly in the integration project. e.g. when the test directory is a Bazel workspace itself, then we cannot declare the test within the `BUILD.bazel` file as that file does not belong to the workspace we are intending to run the test within. To achieve what we want the test is declared in a directory which has a sub-directory for the nested workspace. Then the test target can set the working directory to the sub-directory so that commands can be executed within it. e.g. consider a Bazel workspace test like this: ``` integration/bazel-tests/BUILD.bazel # <- Defines the test | -----------------> /ng_module_test/WORKSPACE | -----------------> /ng_module_test/package.json | -----------------> /ng_module_test/BUILD.bazel ``` As seen in the snippet above, the Bazel-nested tests need to be in a parent folder with a `BUILD.bazel` that is part of the main workspace. The nested workspace has its own set of files and is ignored by Bazel (due to it being a nested workspace).. inherently the test running the nested workspace needs to be declared outside of the nested space!
- Loading branch information
1 parent
aaa90c5
commit 8b007f3
Showing
11 changed files
with
103 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
bazel/integration/tests/nested_bazel_workspaces/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
load("//bazel/integration:index.bzl", "integration_test") | ||
|
||
# Note: Since the Bazel nested workspace is fully isolated we cannot simply wire up | ||
# the integration test with a `BUILD` file in the nested workspace. Instead we need | ||
# the test to be defined at a higher-level, part of the actual `dev-infra` workspace. | ||
integration_test( | ||
name = "basic", | ||
srcs = glob(["basic/**/*"]), | ||
commands = [ | ||
"yarn", | ||
"yarn test", | ||
], | ||
data = [ | ||
# The Yarn files also need to be part of the integration test as runfiles | ||
# because the `yarn_bin` target is not a self-contained standalone binary. | ||
"@nodejs//:yarn_files", | ||
], | ||
environment = { | ||
# Setup a HOME directory so that Bazelisk can work, both Linux/macOS and Windows variants | ||
# are configured to provide a fake home directory so that Bazelisk can download Bazel. | ||
"HOME": "<TMP>", | ||
"LOCALAPPDATA": "<TMP>", | ||
}, | ||
tags = [ | ||
# This test relies on `yarn` so there needs to be internet access. | ||
"requires-network", | ||
], | ||
tool_mappings = { | ||
"@nodejs//:yarn_bin": "yarn", | ||
"@nodejs//:node_bin": "node", | ||
}, | ||
working_dir = "basic/", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build --symlink_prefix=/ |
4 changes: 4 additions & 0 deletions
4
bazel/integration/tests/nested_bazel_workspaces/basic/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sh_test( | ||
name = "test", | ||
srcs = ["some_test.sh"], | ||
) |
3 changes: 3 additions & 0 deletions
3
bazel/integration/tests/nested_bazel_workspaces/basic/WORKSPACE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
workspace( | ||
name = "nested_bazel_workspace", | ||
) |
12 changes: 12 additions & 0 deletions
12
bazel/integration/tests/nested_bazel_workspaces/basic/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "basic", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "bazel test ..." | ||
}, | ||
"devDependencies": { | ||
"@bazel/bazelisk": "^1.10.1" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
bazel/integration/tests/nested_bazel_workspaces/basic/some_test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Passes" | ||
exit 0 |
8 changes: 8 additions & 0 deletions
8
bazel/integration/tests/nested_bazel_workspaces/basic/yarn.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@bazel/bazelisk@^1.10.1": | ||
version "1.10.1" | ||
resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.10.1.tgz#46236a43ad58e310c55247f866da0dc6083c3d8b" | ||
integrity sha512-IHszNzBO2UrUy6YtsSAsZtnU6I6qpzXGkWdEvGoMxLgJnDsEnsIYniDCUjvjU1KAP+A03eepmCHlyFcRHMSxRA== |