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.
This commit is contained in:
Paul Gschwendtner 2025-01-21 14:27:35 +00:00
parent 612c17823a
commit ac055e1ff3
9 changed files with 66 additions and 35 deletions

View File

@ -10,8 +10,9 @@ packages/angular_devkit/architect_cli/package.json=1551210941
packages/angular_devkit/build_webpack/package.json=373950017
packages/angular_devkit/core/package.json=339935828
packages/angular_devkit/schematics/package.json=673943597
packages/angular_devkit/schematics_cli/package.json=-1663529211
packages/ngtools/webpack/package.json=597254444
packages/schematics/angular/package.json=251715148
pnpm-lock.yaml=-690479437
pnpm-workspace.yaml=634423855
pnpm-lock.yaml=-2058271568
pnpm-workspace.yaml=1732591250
yarn.lock=-1257671515

View File

@ -193,6 +193,7 @@ npm_translate_lock(
"//packages/angular_devkit/build_webpack:package.json",
"//packages/angular_devkit/core:package.json",
"//packages/angular_devkit/schematics:package.json",
"//packages/angular_devkit/schematics_cli:package.json",
"//packages/ngtools/webpack:package.json",
"//packages/schematics/angular:package.json",
],

View File

@ -1,4 +1,4 @@
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("@npm2//:defs.bzl", "npm_link_all_packages")
load("//tools:defaults2.bzl", "npm_package", "ts_project")
load("//tools:ts_json_schema.bzl", "ts_json_schema")
@ -10,6 +10,8 @@ licenses(["notice"])
package(default_visibility = ["//visibility:public"])
npm_link_all_packages()
RUNTIME_ASSETS = [
"blank/schema.json",
"collection.json",
@ -44,39 +46,14 @@ ts_project(
data = RUNTIME_ASSETS,
module_name = "@angular-devkit/schematics-cli",
deps = [
":node_modules/@angular-devkit/core",
":node_modules/@angular-devkit/schematics",
"//:node_modules/@inquirer/prompts",
"//:node_modules/@types/node",
"//:node_modules/@types/yargs-parser",
"//:node_modules/ansi-colors",
"//:node_modules/symbol-observable",
"//:node_modules/yargs-parser",
"//packages/angular_devkit/core:core_rjs",
"//packages/angular_devkit/core/node:node_rjs",
"//packages/angular_devkit/schematics:schematics_rjs",
"//packages/angular_devkit/schematics/tasks:tasks_rjs",
"//packages/angular_devkit/schematics/tools:tools_rjs",
],
)
ts_project(
name = "schematics_cli_test_lib",
testonly = True,
srcs = glob(
include = [
"bin/**/*_spec.ts",
],
),
deps = [
":schematics_cli_rjs",
],
)
jasmine_node_test(
name = "schematics_cli_test",
srcs = [":schematics_cli_test_lib"],
data = [
# The package is loaded at runtime within the tests
":schematics_cli",
],
)

View File

@ -16,8 +16,8 @@
],
"schematics": "./collection.json",
"dependencies": {
"@angular-devkit/core": "0.0.0-PLACEHOLDER",
"@angular-devkit/schematics": "0.0.0-PLACEHOLDER",
"@angular-devkit/core": "workspace:0.0.0-PLACEHOLDER",
"@angular-devkit/schematics": "workspace:0.0.0-PLACEHOLDER",
"@inquirer/prompts": "7.2.3",
"ansi-colors": "4.1.3",
"symbol-observable": "4.0.0",

View File

@ -0,0 +1,31 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("//tools:defaults2.bzl", "jasmine_test", "ts_project")
ts_project(
name = "schematics_cli_test_lib",
testonly = True,
srcs = glob(["**/*"]),
deps = [
"//packages/angular_devkit/schematics_cli:schematics_cli_rjs",
],
)
# Note: Link the schematics CLI package into node modules for testing. Notably, tests
# of a package typically don't use the npm package, to e.g. allow for relative
# imports, but here this is an exception as the package needs to be resolvable at runtime.
npm_link_package(
name = "node_modules/@angular-devkit/schematics-cli",
src = "//packages/angular_devkit/schematics_cli:pkg",
package = "@angular-devkit/schematics-cli",
root_package = package_name(),
)
jasmine_test(
name = "schematics_cli_test",
data = [
":schematics_cli_test_lib_rjs",
# The npm package itself is needed for the test at runtime, so we
# link it into this folder as `node_modules/@angular-devkit/schematics-cli`.
":node_modules/@angular-devkit/schematics-cli",
],
)

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import { main } from './schematics';
import { main } from '../bin/schematics';
// We only care about the write method in these mocks of NodeJS.WriteStream.
class MockWriteStream {

21
pnpm-lock.yaml generated
View File

@ -693,6 +693,27 @@ importers:
specifier: 7.8.1
version: 7.8.1
packages/angular_devkit/schematics_cli:
dependencies:
'@angular-devkit/core':
specifier: workspace:0.0.0-PLACEHOLDER
version: link:../core
'@angular-devkit/schematics':
specifier: workspace:0.0.0-PLACEHOLDER
version: link:../schematics
'@inquirer/prompts':
specifier: 7.2.3
version: 7.2.3(@types/node@22.10.7)
ansi-colors:
specifier: 4.1.3
version: 4.1.3
symbol-observable:
specifier: 4.0.0
version: 4.0.0
yargs-parser:
specifier: 21.1.1
version: 21.1.1
packages/ngtools/webpack:
devDependencies:
'@angular-devkit/core':

View File

@ -5,6 +5,7 @@ packages:
- packages/angular_devkit/core
- packages/angular_devkit/build_webpack
- packages/angular_devkit/schematics
- packages/angular_devkit/schematics_cli
- packages/angular/cli
- packages/angular/pwa
- packages/schematics/angular

View File

@ -33,7 +33,6 @@
"dist-schema/**",
"**/node_modules/**/*",
"**/third_party/**/*",
"packages/angular_devkit/schematics_cli/schematic/files/**/*",
"packages/angular_devkit/*/test/**/*"
"packages/angular_devkit/schematics_cli/schematic/files/**/*"
]
}