-
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): add support for custom environment variables in integrat…
…ion tests Adds support for custom environment variables in integration tests. The environment variable dictionary can use location expansion. Also there is a special placeholder called `<TMP>` that can be used to acquire a temporary directory. This is useful when setting up tools like BAZELISK, which requires a `HOME` environment variable as an example.
- Loading branch information
1 parent
f8a3346
commit 1647e31
Showing
7 changed files
with
190 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** | ||
* Placeholder that can be used in the test environment dictionary to reserve a | ||
* temporary directory. A temporary directory can be useful when running tools | ||
* like Bazelisk which need a `HOME` directory for example. | ||
*/ | ||
export const ENVIRONMENT_TMP_PLACEHOLDER = '<TMP>'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("//bazel/integration:index.bzl", "integration_test") | ||
|
||
integration_test( | ||
name = "test", | ||
srcs = [ | ||
"test.js", | ||
], | ||
commands = [ | ||
"node ./test.js", | ||
], | ||
data = ["@npm//:node_modules/semver/package.json"], | ||
environment = { | ||
"CUSTOM_VAR": "yes!", | ||
"RESOLVED_BIN": "$(rootpath @npm//:node_modules/semver/package.json)", | ||
"MANIFEST_PATH": "external/npm/node_modules/semver/package.json", | ||
"BAZELISK_HOME": "<TMP>", | ||
"BAZELISK_HOME_2": "<TMP>", | ||
}, | ||
tool_mappings = { | ||
"@nodejs//:node_bin": "node", | ||
}, | ||
) |
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,39 @@ | ||
const fs = require('fs'); | ||
|
||
if (process.env.CUSTOM_VAR !== 'yes!') { | ||
console.error('The expected `CUSTOM_VAR` environment variable is not set.'); | ||
process.exit(1); | ||
} | ||
|
||
if (process.env.RESOLVED_BIN === undefined) { | ||
console.error('The expected `RESOLVED_BIN` variable is not set.'); | ||
process.exit(1); | ||
} | ||
|
||
if (require(process.env.RESOLVED_BIN).name !== 'semver') { | ||
console.error('The `RESOLVED_BIN` file did not resolve to the "package.json" of "semver".'); | ||
process.exit(1); | ||
} | ||
|
||
if (process.env.MANIFEST_PATH !== 'external/npm/node_modules/semver/package.json') { | ||
console.error('Expected `MANIFEST_PATH` to remain untouched as it has not not been expanded.'); | ||
process.exit(1); | ||
} | ||
|
||
const bazeliskHome = process.env.BAZELISK_HOME; | ||
const bazeliskHome_2 = process.env.BAZELISK_HOME_2; | ||
|
||
if (!fs.statSync(bazeliskHome).isDirectory()) { | ||
console.error('Expected `BAZELISK_HOME` environment variable to point to a temp directory.'); | ||
process.exit(1); | ||
} | ||
|
||
if (!fs.statSync(bazeliskHome_2).isDirectory()) { | ||
console.error('Expected `BAZELISK_HOME_2` environment variable to point to a temp directory.'); | ||
process.exit(1); | ||
} | ||
|
||
if (bazeliskHome === bazeliskHome_2) { | ||
console.error('Expected the bazelisk home variables to point to different temp directories.'); | ||
process.exit(1); | ||
} |