Skip to content

Commit

Permalink
test: update environment spec to work with windows (#3358)
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion authored Mar 8, 2022
1 parent 78aefa3 commit 8606c50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ for more details about the trade-offs between the two rules.

Some TypeScript options affect which files are emitted, and Bazel wants to know these ahead-of-time.
So several options from the tsconfig file must be mirrored as attributes to ts_project.
See https://www.typescriptlang.org/v2/en/tsconfig for a listing of the TypeScript options.
See https://www.typescriptlang.org/tsconfig for a listing of the TypeScript options.

Any code that works with `tsc` should work with `ts_project` with a few caveats:

Expand Down
24 changes: 12 additions & 12 deletions internal/node/test/env.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ describe('launcher.sh environment', function() {
expectPathsToMatch(process.env['BAZEL_WORKSPACE'], 'build_bazel_rules_nodejs');
expectPathsToMatch(process.env['BAZEL_TARGET'], '//internal/node/test:env_test');
expectPathsToMatch(process.cwd(), `${process.env['RUNFILES_DIR']}/build_bazel_rules_nodejs`);
expectPathsToMatch(process.env['PWD'], `${process.env['RUNFILES_DIR']}/build_bazel_rules_nodejs`);
expectPathsToMatch(
process.env['PWD'],
`${process.env['RUNFILES_DIR']}/build_bazel_rules_nodejs`
);
// On Windows, an empty string value for 'BAZEL_NODE_MODULES_ROOTS' does not make it into
// dump_build_env.json
process.env['BAZEL_NODE_MODULES_ROOTS'] = process.env['BAZEL_NODE_MODULES_ROOTS'] || '';
Expand All @@ -54,23 +57,22 @@ describe('launcher.sh environment', function() {
`${execroot}/node_modules`,
`${runfilesRoot}`,
`${runfilesRoot}/build_bazel_rules_nodejs/node_modules`,
]
];
if (isWindows) {
expectedRoots.push(
process.env['RUNFILES'],
`${process.env['RUNFILES']}/build_bazel_rules_nodejs/node_modules`,
)
`${process.env['RUNFILES']}/build_bazel_rules_nodejs/node_modules`
);
}
expectPathsToMatch(process.env['BAZEL_PATCH_ROOTS'].split(','), expectedRoots);
});

it('should setup correct bazel environment variables when in execroot with no third party deps', function() {
const env = require(runfiles.resolvePackageRelative('dump_build_env.json'));
// On Windows, an empty string value for 'BAZEL_NODE_MODULES_ROOTS' does not make it into
// dump_build_env.json
env['BAZEL_NODE_MODULES_ROOTS'] = env['BAZEL_NODE_MODULES_ROOTS'] || '';
// On Windows, the RUNFILES path ends in a /MANIFEST segment in this context
const runfilesRoot = normPath(isWindows ? path.dirname(env['RUNFILES']) : env['RUNFILES']);
const runfilesRoot = normPath(env['RUNFILES']);
const match = runfilesRoot.match(/\/bazel-out\//);
expect(!!match).toBe(true);
const execroot = runfilesRoot.slice(0, match.index);
Expand All @@ -87,14 +89,13 @@ describe('launcher.sh environment', function() {
];
expectPathsToMatch(env['BAZEL_PATCH_ROOTS'].split(','), expectedRoots);
});

it('should setup correct bazel environment variables when in execroot with third party deps', function() {
const env = require(runfiles.resolvePackageRelative('dump_build_env_alt.json'));
// On Windows, an empty string value for 'BAZEL_NODE_MODULES_ROOTS' does not make it into
// dump_build_env.json
env['BAZEL_NODE_MODULES_ROOTS'] = env['BAZEL_NODE_MODULES_ROOTS'] || '';
// On Windows, the RUNFILES path ends in a /MANIFEST segment in this context
const runfilesRoot = normPath(isWindows ? path.dirname(env['RUNFILES']) : env['RUNFILES']);
const runfilesRoot = normPath(env['RUNFILES']);
const match = runfilesRoot.match(/\/bazel-out\//);
expect(!!match).toBe(true);
const execroot = runfilesRoot.slice(0, match.index);
Expand All @@ -111,11 +112,10 @@ describe('launcher.sh environment', function() {
];
expectPathsToMatch(env['BAZEL_PATCH_ROOTS'].split(','), expectedRoots);
});

it('should setup correct bazel environment variables from env attr', function() {
const env = require(runfiles.resolvePackageRelative('dump_build_env_attr.json'));
expect(env['FOO']).toBe('BAR');
expect(env['LOC']).toBe('build_bazel_rules_nodejs/internal/node/test/dump_build_env.js');
});
});

0 comments on commit 8606c50

Please sign in to comment.