Skip to content

Commit fa467e3

Browse files
committed
build: schematics unit tests not being run
Currently the schematics unit tests aren't being run and are assumed as passing. This was a result of the following issues: 1. The `require.resolve` call in the `index.spec.ts` files was failing, but it was inside of a `Promise` so it got silenced. It caused the test runner to completely give up on running the tests. I was only able to see the failure using a debugger. 2. Even if the `require.resolve` call worked as expected, the `filegroup` call doesn't seem to actually work, at least on Windows which would prevent the files from showing up in the Bazel directory. I've switched it to `copy_to_bin`. 3. There was some issue with loading the `index.spec.ts`, presumably because the file name follows the same pattern as unit test files. I've renamed it to `paths.ts` as a workaround.
1 parent fef9bf5 commit fa467e3

25 files changed

+53
-49
lines changed

src/cdk/schematics/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
1+
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "pkg_npm")
22
load("//:packages.bzl", "VERSION_PLACEHOLDER_REPLACEMENTS")
33
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
44

55
package(default_visibility = ["//visibility:public"])
66

7-
filegroup(
7+
copy_to_bin(
88
name = "schematics_assets",
99
srcs = glob([
1010
"**/files/**/*",

src/cdk/schematics/index.spec.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/cdk/schematics/ng-add/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Tree} from '@angular-devkit/schematics';
22
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
3-
import {COLLECTION_PATH} from '../index.spec';
3+
import {COLLECTION_PATH} from '../paths';
44
import {createTestApp, getFileContent} from '../testing';
55
import {addPackageToPackageJson} from './package-config';
66

src/cdk/schematics/ng-generate/drag-drop/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
2-
import {COLLECTION_PATH} from '../../index.spec';
2+
import {COLLECTION_PATH} from '../../paths';
33
import {createTestApp, getFileContent} from '../../testing';
44
import {Schema} from './schema';
55

src/cdk/schematics/ng-update/test-cases/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {defineJasmineTestCases, findBazelVersionTestCases} from '@angular/cdk/schematics/testing';
2-
import {MIGRATION_PATH} from '../../index.spec';
2+
import {MIGRATION_PATH} from '../../paths';
33
import {getAllVersionNames} from '../../update-tool/target-version';
44

55
describe('CDK upgrade test cases', () => {

src/cdk/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {resolveBazelPath} from '@angular/cdk/schematics/testing';
2-
import {MIGRATION_PATH} from '../../../index.spec';
2+
import {MIGRATION_PATH} from '../../../paths';
33
import {createTestCaseSetup} from '../../../testing';
44

55
describe('ng-update external resource resolution', () => {

src/cdk/schematics/ng-update/test-cases/misc/global-stylesheets.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {resolveBazelPath} from '@angular/cdk/schematics/testing';
22
import {readFileSync} from 'fs';
3-
import {MIGRATION_PATH} from '../../../index.spec';
3+
import {MIGRATION_PATH} from '../../../paths';
44
import {createTestCaseSetup} from '../../../testing';
55

66
describe('global stylesheets migration', () => {

src/cdk/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {resolveBazelPath} from '@angular/cdk/schematics/testing';
2-
import {MIGRATION_PATH} from '../../../index.spec';
2+
import {MIGRATION_PATH} from '../../../paths';
33
import {createTestCaseSetup} from '../../../testing';
44

55
describe('v6 method call checks', () => {

src/cdk/schematics/paths.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {join} from 'path';
10+
11+
/** Path to the schematic collection for non-migration schematics. */
12+
export const COLLECTION_PATH = join(__dirname, 'collection.json');
13+
14+
/** Path to the schematic collection that includes the migrations. */
15+
export const MIGRATION_PATH = join(__dirname, 'migration.json');

src/material/schematics/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
1+
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "pkg_npm")
22
load("//:packages.bzl", "VERSION_PLACEHOLDER_REPLACEMENTS")
33
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
44

55
package(default_visibility = ["//visibility:public"])
66

7-
filegroup(
7+
copy_to_bin(
88
name = "schematics_assets",
99
srcs = ["ng-update/migrations/hammer-gestures-v9/gesture-config.template"] + glob([
1010
"ng-generate/*/files/**/*",

src/material/schematics/index.spec.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/material/schematics/ng-add/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@angular/cdk/schematics';
1111
import {createTestApp, createTestLibrary, getFileContent} from '@angular/cdk/schematics/testing';
1212
import {getWorkspace} from '@schematics/angular/utility/workspace';
13-
import {COLLECTION_PATH} from '../index.spec';
13+
import {COLLECTION_PATH} from '../paths';
1414
import {addPackageToPackageJson} from './package-config';
1515

1616
interface PackageJson {

src/material/schematics/ng-generate/address-form/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
22
import {createTestApp, getFileContent} from '@angular/cdk/schematics/testing';
3-
import {COLLECTION_PATH} from '../../index.spec';
3+
import {COLLECTION_PATH} from '../../paths';
44
import {Schema} from './schema';
55

66
describe('Material address-form schematic', () => {

src/material/schematics/ng-generate/dashboard/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
22
import {createTestApp, getFileContent} from '@angular/cdk/schematics/testing';
3-
import {COLLECTION_PATH} from '../../index.spec';
3+
import {COLLECTION_PATH} from '../../paths';
44
import {Schema} from './schema';
55

66
describe('material-dashboard-schematic', () => {

src/material/schematics/ng-generate/navigation/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
22
import {createTestApp, getFileContent} from '@angular/cdk/schematics/testing';
3-
import {COLLECTION_PATH} from '../../index.spec';
3+
import {COLLECTION_PATH} from '../../paths';
44

55
import {Schema} from './schema';
66

src/material/schematics/ng-generate/table/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
22
import {createTestApp, getFileContent} from '@angular/cdk/schematics/testing';
3-
import {COLLECTION_PATH} from '../../index.spec';
3+
import {COLLECTION_PATH} from '../../paths';
44
import {Schema} from './schema';
55

66
describe('material-table-schematic', () => {

src/material/schematics/ng-generate/tree/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
22
import {createTestApp, getFileContent} from '@angular/cdk/schematics/testing';
3-
import {COLLECTION_PATH} from '../../index.spec';
3+
import {COLLECTION_PATH} from '../../paths';
44
import {Schema} from './schema';
55

66
describe('Material tree schematic', () => {

src/material/schematics/ng-update/test-cases/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {getAllVersionNames} from '@angular/cdk/schematics';
22
import {defineJasmineTestCases, findBazelVersionTestCases} from '@angular/cdk/schematics/testing';
3-
import {MIGRATION_PATH} from '../../index.spec';
3+
import {MIGRATION_PATH} from '../../paths';
44

55
describe('Material upgrade test cases', () => {
66
const versionNames = getAllVersionNames().map(versionName => versionName.toLowerCase());

src/material/schematics/ng-update/test-cases/misc/class-inheritance.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createTestCaseSetup, resolveBazelPath} from '@angular/cdk/schematics/testing';
2-
import {MIGRATION_PATH} from '../../../index.spec';
2+
import {MIGRATION_PATH} from '../../../paths';
33

44
describe('class inheritance misc checks', () => {
55
describe('v6 class which extends MatFormFieldControl', () => {

src/material/schematics/ng-update/test-cases/misc/constructor-checks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createTestCaseSetup, resolveBazelPath} from '@angular/cdk/schematics/testing';
2-
import {MIGRATION_PATH} from '../../../index.spec';
2+
import {MIGRATION_PATH} from '../../../paths';
33

44
describe('constructor checks', () => {
55
it('should properly report invalid constructor expression signatures', async () => {

src/material/schematics/ng-update/test-cases/misc/import-checks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createTestCaseSetup, resolveBazelPath} from '@angular/cdk/schematics/testing';
2-
import {MIGRATION_PATH} from '../../../index.spec';
2+
import {MIGRATION_PATH} from '../../../paths';
33

44
describe('v6 import misc checks', () => {
55
it('should report imports for deleted animation constants', async () => {

src/material/schematics/ng-update/test-cases/v8/misc/material-imports.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
readFileContent,
44
resolveBazelPath
55
} from '@angular/cdk/schematics/testing';
6-
import {MIGRATION_PATH} from '../../../../index.spec';
6+
import {MIGRATION_PATH} from '../../../../paths';
77

88
describe('v8 material imports', () => {
99
it('should re-map top-level material imports to the proper entry points', async () => {

src/material/schematics/ng-update/test-cases/v9/misc/hammer-migration-v9.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {dedent} from '@angular/cdk/testing/private';
33
import {addPackageToPackageJson} from '@angular/cdk/schematics/ng-add/package-config';
44
import {createTestCaseSetup, resolveBazelPath} from '@angular/cdk/schematics/testing';
55
import {readFileSync} from 'fs';
6-
import {MIGRATION_PATH} from '../../../../index.spec';
6+
import {MIGRATION_PATH} from '../../../../paths';
77

88

99
interface PackageJson {

src/material/schematics/ng-update/test-cases/v9/misc/material-imports.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createTestCaseSetup, readFileContent, resolveBazelPath} from '@angular/cdk/schematics/testing';
2-
import {MIGRATION_PATH} from '../../../../index.spec';
2+
import {MIGRATION_PATH} from '../../../../paths';
33

44
describe('v9 material imports', () => {
55
it('should re-map top-level material imports to the proper entry points when top-level ' +

src/material/schematics/paths.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {join} from 'path';
10+
11+
/** Path to the schematic collection for non-migration schematics. */
12+
export const COLLECTION_PATH = join(__dirname, 'collection.json');
13+
14+
/** Path to the schematic collection that includes the migrations. */
15+
export const MIGRATION_PATH = join(__dirname, 'migration.json');

0 commit comments

Comments
 (0)