Skip to content

Commit

Permalink
build: migrate @angular-devkit/schematics tests to rules_js
Browse files Browse the repository at this point in the history
Migrates `@angular-devkit/schematics` jasmine rules to the
native `rules_js` variant.

As part of this commit, we are performing a few adjustments that we've
discussed as preparation for this migration:

- cross package imports are always using the module name
- inside package imports are always using relative imports, matching
  existing tests, fixing a few outliers.
  • Loading branch information
devversion authored and alan-agius4 committed Jan 20, 2025
1 parent c9bf07d commit 4700c5d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { Observable } from 'rxjs';
import { Path } from '@angular-devkit/core';
import { PathFragment } from '@angular-devkit/core';
import { schema } from '@angular-devkit/core';
import { Subject } from 'rxjs';
import { Url } from 'url';
import { virtualFs } from '@angular-devkit/core';
import { workflow } from '@angular-devkit/schematics';

// @public (undocumented)
export class CollectionCannotBeResolvedException extends BaseException {
Expand Down
16 changes: 8 additions & 8 deletions packages/angular_devkit/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@npm//@angular/build-tooling/bazel/api-golden:index.bzl", "api_golden_test_npm_package")
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("//tools:defaults2.bzl", "npm_package", "ts_project")
load("@npm2//:defs.bzl", "npm_link_all_packages")
load("//tools:defaults2.bzl", "jasmine_test", "npm_package", "ts_project")

# Copyright Google Inc. All Rights Reserved.
#
Expand All @@ -10,6 +10,8 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"])

npm_link_all_packages()

# @angular-devkit/schematics

ts_project(
Expand All @@ -25,12 +27,11 @@ ts_project(
],
module_name = "@angular-devkit/schematics",
deps = [
":node_modules/@angular-devkit/core",
"//:node_modules/@types/node",
"//:node_modules/jsonc-parser",
"//:node_modules/magic-string",
"//:node_modules/rxjs",
"//packages/angular_devkit/core:core_rjs",
"//packages/angular_devkit/core/node:node_rjs", # TODO: get rid of this for 6.0
],
)

Expand All @@ -39,18 +40,17 @@ ts_project(
testonly = True,
srcs = glob(["src/**/*_spec.ts"]),
deps = [
":node_modules/@angular-devkit/core",
":schematics",
"//:node_modules/@types/jasmine",
"//:node_modules/rxjs",
"//packages/angular_devkit/core:core_rjs",
"//packages/angular_devkit/core/node:node_rjs",
"//packages/angular_devkit/schematics/testing:testing_rjs",
],
)

jasmine_node_test(
jasmine_test(
name = "schematics_test",
deps = [":schematics_test_lib"],
data = [":schematics_test_lib_rjs"],
)

genrule(
Expand Down
6 changes: 3 additions & 3 deletions packages/angular_devkit/schematics/src/rules/base_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { Path, virtualFs } from '@angular-devkit/core';
import { HostTree, MergeStrategy, partitionApplyMerge } from '@angular-devkit/schematics';
import { lastValueFrom, of as observableOf } from 'rxjs';
import { Rule, SchematicContext, Source } from '../engine/interface';
import { Tree } from '../tree/interface';
import { HostTree } from '../tree/host-tree';
import { MergeStrategy, Tree } from '../tree/interface';
import { empty } from '../tree/static';
import { apply, applyToSubtree, chain } from './base';
import { apply, applyToSubtree, chain, partitionApplyMerge } from './base';
import { callRule, callSource } from './call';
import { move } from './move';

Expand Down
3 changes: 1 addition & 2 deletions packages/angular_devkit/schematics/src/rules/call_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { MergeStrategy } from '@angular-devkit/schematics';
import { of as observableOf } from 'rxjs';
import { Rule, SchematicContext, Source } from '../engine/interface';
import { Tree } from '../tree/interface';
import { MergeStrategy, Tree } from '../tree/interface';
import { empty } from '../tree/static';
import {
InvalidRuleResultException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

/* eslint-disable import/no-extraneous-dependencies */
import { normalize } from '@angular-devkit/core';
import { UnitTestTree } from '@angular-devkit/schematics/testing';
import { of as observableOf } from 'rxjs';
import { UnitTestTree } from '../../testing';
import { SchematicContext } from '../engine/interface';
import { HostTree } from '../tree/host-tree';
import { FileEntry, MergeStrategy } from '../tree/interface';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/schematics/src/sink/host_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import { normalize, virtualFs } from '@angular-devkit/core';
import { HostSink } from '@angular-devkit/schematics';
import { HostCreateTree, HostTree } from '../tree/host-tree';
import { HostSink } from './host';

describe('FileSystemSink', () => {
it('works', (done) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

import { JsonValue } from '@angular-devkit/core';
import { FileDoesNotExistException } from '@angular-devkit/schematics';
import { readFileSync } from 'fs';
import { ParseError, parse, printParseErrorCode } from 'jsonc-parser';
import { FileDoesNotExistException } from '../src/exception/exception';

export function readJsonFile(path: string): JsonValue {
let data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Path, getSystemPath, normalize, schema, virtualFs } from '@angular-devkit/core';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
import { workflow } from '@angular-devkit/schematics';
import { workflow } from '../../src';
import { BuiltinTaskExecutor } from '../../tasks/node';
import { FileSystemEngine } from '../description';
import { OptionTransform } from '../file-system-engine-host-base';
Expand Down

0 comments on commit 4700c5d

Please sign in to comment.