Skip to content

Commit ac055e1

Browse files
committed
build: migrate @angular-devkit/schematics-cli tests to rules_js
Migrates the schematics-cli tests to `rules_js`. Notably a little extra logic was needed here as the tests were relying on the built npm package at runtime, resolvable via it's "package name". To address this, we manually link the package for the test at runtime. The spec file is moved into a separate folder for this reason, so that we don't accidentally expose the schematics CLI package for unexpected reasons.
1 parent 612c178 commit ac055e1

File tree

9 files changed

+66
-35
lines changed

9 files changed

+66
-35
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_MzA5NzUwNzMx

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ packages/angular_devkit/architect_cli/package.json=1551210941
1010
packages/angular_devkit/build_webpack/package.json=373950017
1111
packages/angular_devkit/core/package.json=339935828
1212
packages/angular_devkit/schematics/package.json=673943597
13+
packages/angular_devkit/schematics_cli/package.json=-1663529211
1314
packages/ngtools/webpack/package.json=597254444
1415
packages/schematics/angular/package.json=251715148
15-
pnpm-lock.yaml=-690479437
16-
pnpm-workspace.yaml=634423855
16+
pnpm-lock.yaml=-2058271568
17+
pnpm-workspace.yaml=1732591250
1718
yarn.lock=-1257671515

WORKSPACE

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ npm_translate_lock(
193193
"//packages/angular_devkit/build_webpack:package.json",
194194
"//packages/angular_devkit/core:package.json",
195195
"//packages/angular_devkit/schematics:package.json",
196+
"//packages/angular_devkit/schematics_cli:package.json",
196197
"//packages/ngtools/webpack:package.json",
197198
"//packages/schematics/angular:package.json",
198199
],

packages/angular_devkit/schematics_cli/BUILD.bazel

+5-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
1+
load("@npm2//:defs.bzl", "npm_link_all_packages")
22
load("//tools:defaults2.bzl", "npm_package", "ts_project")
33
load("//tools:ts_json_schema.bzl", "ts_json_schema")
44

@@ -10,6 +10,8 @@ licenses(["notice"])
1010

1111
package(default_visibility = ["//visibility:public"])
1212

13+
npm_link_all_packages()
14+
1315
RUNTIME_ASSETS = [
1416
"blank/schema.json",
1517
"collection.json",
@@ -44,39 +46,14 @@ ts_project(
4446
data = RUNTIME_ASSETS,
4547
module_name = "@angular-devkit/schematics-cli",
4648
deps = [
49+
":node_modules/@angular-devkit/core",
50+
":node_modules/@angular-devkit/schematics",
4751
"//:node_modules/@inquirer/prompts",
4852
"//:node_modules/@types/node",
4953
"//:node_modules/@types/yargs-parser",
5054
"//:node_modules/ansi-colors",
5155
"//:node_modules/symbol-observable",
5256
"//:node_modules/yargs-parser",
53-
"//packages/angular_devkit/core:core_rjs",
54-
"//packages/angular_devkit/core/node:node_rjs",
55-
"//packages/angular_devkit/schematics:schematics_rjs",
56-
"//packages/angular_devkit/schematics/tasks:tasks_rjs",
57-
"//packages/angular_devkit/schematics/tools:tools_rjs",
58-
],
59-
)
60-
61-
ts_project(
62-
name = "schematics_cli_test_lib",
63-
testonly = True,
64-
srcs = glob(
65-
include = [
66-
"bin/**/*_spec.ts",
67-
],
68-
),
69-
deps = [
70-
":schematics_cli_rjs",
71-
],
72-
)
73-
74-
jasmine_node_test(
75-
name = "schematics_cli_test",
76-
srcs = [":schematics_cli_test_lib"],
77-
data = [
78-
# The package is loaded at runtime within the tests
79-
":schematics_cli",
8057
],
8158
)
8259

packages/angular_devkit/schematics_cli/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
],
1717
"schematics": "./collection.json",
1818
"dependencies": {
19-
"@angular-devkit/core": "0.0.0-PLACEHOLDER",
20-
"@angular-devkit/schematics": "0.0.0-PLACEHOLDER",
19+
"@angular-devkit/core": "workspace:0.0.0-PLACEHOLDER",
20+
"@angular-devkit/schematics": "workspace:0.0.0-PLACEHOLDER",
2121
"@inquirer/prompts": "7.2.3",
2222
"ansi-colors": "4.1.3",
2323
"symbol-observable": "4.0.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
2+
load("//tools:defaults2.bzl", "jasmine_test", "ts_project")
3+
4+
ts_project(
5+
name = "schematics_cli_test_lib",
6+
testonly = True,
7+
srcs = glob(["**/*"]),
8+
deps = [
9+
"//packages/angular_devkit/schematics_cli:schematics_cli_rjs",
10+
],
11+
)
12+
13+
# Note: Link the schematics CLI package into node modules for testing. Notably, tests
14+
# of a package typically don't use the npm package, to e.g. allow for relative
15+
# imports, but here this is an exception as the package needs to be resolvable at runtime.
16+
npm_link_package(
17+
name = "node_modules/@angular-devkit/schematics-cli",
18+
src = "//packages/angular_devkit/schematics_cli:pkg",
19+
package = "@angular-devkit/schematics-cli",
20+
root_package = package_name(),
21+
)
22+
23+
jasmine_test(
24+
name = "schematics_cli_test",
25+
data = [
26+
":schematics_cli_test_lib_rjs",
27+
# The npm package itself is needed for the test at runtime, so we
28+
# link it into this folder as `node_modules/@angular-devkit/schematics-cli`.
29+
":node_modules/@angular-devkit/schematics-cli",
30+
],
31+
)

packages/angular_devkit/schematics_cli/bin/schematics_spec.ts renamed to packages/angular_devkit/schematics_cli/test/schematics.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { main } from './schematics';
9+
import { main } from '../bin/schematics';
1010

1111
// We only care about the write method in these mocks of NodeJS.WriteStream.
1212
class MockWriteStream {

pnpm-lock.yaml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ packages:
55
- packages/angular_devkit/core
66
- packages/angular_devkit/build_webpack
77
- packages/angular_devkit/schematics
8+
- packages/angular_devkit/schematics_cli
89
- packages/angular/cli
910
- packages/angular/pwa
1011
- packages/schematics/angular

tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"dist-schema/**",
3434
"**/node_modules/**/*",
3535
"**/third_party/**/*",
36-
"packages/angular_devkit/schematics_cli/schematic/files/**/*",
37-
"packages/angular_devkit/*/test/**/*"
36+
"packages/angular_devkit/schematics_cli/schematic/files/**/*"
3837
]
3938
}

0 commit comments

Comments
 (0)