Skip to content

Commit 29d4705

Browse files
committed
refactor(bazel): update integration test rule to use rules_js
Technically this wouldn't be necessary for `rules_js` as the rule is pretty agnostic, but it means we don't end up hitting the `@npm` workspace, or more `rules_nodejs` dependencies— so it's part of our migration. Also this commit simplifies some logic around the temporary directory creation to spare an extra dependency. We also remove some unnecessary Windows logic. Finally, we fix runfile resolution to work with `rules_js`, without relying on any runfile helpes, as we can expect a runfiles directory with proper real files.
1 parent 77b2017 commit 29d4705

File tree

15 files changed

+74
-100
lines changed

15 files changed

+74
-100
lines changed

bazel/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ filegroup(
2727
"//bazel/esbuild:files",
2828
"//bazel/git-toolchain:files",
2929
"//bazel/http-server:files",
30-
"//bazel/integration:files",
3130
"//bazel/karma:files",
3231
"//bazel/map-size-tracking:files",
3332
"//bazel/private:files",

bazel/integration/BUILD.bazel

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
package(default_visibility = ["//visibility:public"])
2-
3-
# Make source files available for distribution via pkg_npm
4-
filegroup(
5-
name = "files",
6-
srcs = glob(["*"]) + [
7-
"//bazel/integration/test_runner:files",
8-
],
9-
)

bazel/integration/index.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
1+
load("@aspect_rules_js//js:defs.bzl", "js_test")
22

33
def _serialize_file(file):
44
"""Serializes a file into a struct that matches the `BazelFileInfo` type in the
@@ -259,11 +259,11 @@ def integration_test(
259259
toolchains = toolchains,
260260
)
261261

262-
nodejs_test(
262+
js_test(
263263
name = name,
264-
data = ["//bazel/integration/test_runner", ":" + config_target],
265-
templated_args = ["--nobazel_run_linker", "$(rootpath :%s)" % config_target],
266-
entry_point = "//bazel/integration/test_runner:main.ts",
264+
data = ["@devinfra//bazel/integration/test_runner", ":%s" % config_target],
265+
fixed_args = ["$(rootpath :%s)" % config_target],
266+
entry_point = "@devinfra//bazel/integration/test_runner:main.mjs",
267267
tags = tags,
268268
**kwargs
269269
)
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
load("//bazel:defaults.bzl", "ts_library")
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
22

33
package(default_visibility = ["//visibility:public"])
44

5-
ts_library(
5+
ts_project(
66
name = "test_runner",
7-
srcs = glob(["*.ts"]),
8-
module_name = "@angular/build-tooling/bazel/integration/test_runner",
9-
# A tsconfig needs to be specified as otherwise `ts_library` will look for the config
10-
# in `//:package.json` and this breaks when the BUILD file is copied to `@npm//`.
11-
tsconfig = "//:tsconfig.json",
7+
srcs = glob(["*.mts"]),
8+
tsconfig = "//bazel:tsconfig",
129
deps = [
13-
"@npm//@bazel/runfiles",
14-
"@npm//@types/node",
15-
"@npm//@types/tmp",
16-
"@npm//tmp",
17-
"@npm//true-case-path",
10+
"//bazel:node_modules/@types/node",
11+
"//bazel:node_modules/true-case-path",
1812
],
1913
)
20-
21-
# Make source files available for distribution via pkg_npm
22-
filegroup(
23-
name = "files",
24-
srcs = glob(["*"]),
25-
)

bazel/integration/test_runner/bazel.ts renamed to bazel/integration/test_runner/bazel.mts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {debug} from './debug';
10-
import {runfiles} from '@bazel/runfiles';
11-
12-
// Exposing the runfiles to keep the Bazel-specific code local to this file.
13-
export {runfiles};
9+
import path from 'node:path';
10+
import assert from 'node:assert';
11+
import {debug} from './debug.mjs';
1412

1513
/**
1614
* Interface describing a file captured in the Bazel action.
@@ -38,8 +36,9 @@ export interface BazelExpandedValue {
3836
}
3937

4038
/** Resolves the specified Bazel file to an absolute disk path. */
41-
export function resolveBazelFile(file: BazelFileInfo): string {
42-
return runfiles.resolveWorkspaceRelative(file.shortPath);
39+
export function resolveBazelFile(file: Pick<BazelFileInfo, 'shortPath'>): string {
40+
// CWD is runfiles root inside workspace. All short paths naturally work.
41+
return path.join(process.cwd(), file.shortPath);
4342
}
4443

4544
/**
@@ -53,7 +52,8 @@ export function resolveBazelFile(file: BazelFileInfo): string {
5352
*/
5453
export async function resolveBinaryWithRunfilesGracefully(binary: string): Promise<string> {
5554
try {
56-
const resolved = runfiles.resolveWorkspaceRelative(binary);
55+
// CWD is runfiles root inside workspace. All short paths naturally work.
56+
const resolved = path.join(process.cwd(), binary);
5757
debug(`Resolved ${binary} to ${resolved} using runfile resolution.`);
5858
return resolved;
5959
} catch {

bazel/integration/test_runner/debug.ts renamed to bazel/integration/test_runner/debug.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as util from 'util';
9+
import util from 'node:util';
1010

1111
/** Function for printing debug messages when working with the test runner. */
1212
export const debug = util.debuglog('ng-integration-test');

bazel/integration/test_runner/file_system_utils.ts renamed to bazel/integration/test_runner/file_system_utils.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as fs from 'fs';
9+
import fs from 'node:fs';
1010
import {trueCasePath} from 'true-case-path';
1111

1212
/** Gets whether the file is executable or not. */

bazel/integration/test_runner/main.ts renamed to bazel/integration/test_runner/main.mts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TestRunner} from './runner';
10-
import {BazelExpandedValue, BazelFileInfo, runfiles} from './bazel';
11-
import * as fs from 'fs';
12-
import {debug} from './debug';
9+
import {TestRunner} from './runner.mjs';
10+
import {BazelExpandedValue, BazelFileInfo} from './bazel.mjs';
11+
import fs from 'node:fs';
12+
import path from 'node:path';
13+
import {debug} from './debug.mjs';
1314

1415
/**
1516
* Test config that is passed as JSON from the Bazel action.
@@ -30,7 +31,8 @@ async function main(): Promise<void> {
3031
debug(`Running test with arguments: ${process.argv.join(' ')}`);
3132
debug(`Current working directory: ${process.cwd()}`);
3233

33-
const configPath = runfiles.resolveWorkspaceRelative(process.argv[2]);
34+
// Config is passed as short path, relative to current working dir.
35+
const configPath = path.resolve(process.argv[2]);
3436
const configContent = await fs.promises.readFile(configPath, 'utf8');
3537
const config = JSON.parse(configContent) as TestConfig;
3638

bazel/integration/test_runner/package_json.ts renamed to bazel/integration/test_runner/package_json.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import * as fs from 'fs';
10-
import {debug} from './debug';
10+
import {debug} from './debug.mjs';
1111

1212
/** Record capturing dependencies in a `package.json`. */
1313
export type DependencyRecord = Record<string, string>;

0 commit comments

Comments
 (0)