Skip to content

Commit a05695e

Browse files
committed
refactor(schematics): run tests for template files
* No longer skips tests that verify that the template files are properly created as part of the schematic. This is now possible because we have a more clean workaround for the schematic testing (related: bazelbuild/rules_typescript#154) * Updates all schema.json files to properly match the current implementation of the `build-component` function (consistent with `ng g component`) * Due to the new workaround for the schematic testing we can also now re-add the `schema.json` files to the collection. The schema files are needed for the schematics when using `ng generate`)
1 parent 1e1751f commit a05695e

File tree

19 files changed

+144
-93
lines changed

19 files changed

+144
-93
lines changed

src/lib/schematics/BUILD.bazel

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ filegroup(
1111
ts_library(
1212
name = "schematics",
1313
module_name = "@angular/material/schematics",
14-
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts", "update/test-cases/**/*.ts", "**/files/**/*"]),
14+
srcs = glob(["**/*.ts"], exclude=[
15+
"**/*.spec.ts",
16+
"**/files/**/*",
17+
"test-setup/**/*",
18+
"update/test-cases/**/*",
19+
]),
1520
tsconfig = ":tsconfig.json",
1621
)
1722

@@ -28,12 +33,11 @@ jasmine_node_test(
2833
name = "unit_tests",
2934
srcs = [":schematics_test_sources"],
3035
data = [":schematics_assets", ":schematics_test_cases"],
31-
deps = [":copy-collection-file", ":copy-migration-file"],
3236
)
3337

3438
ts_library(
3539
name = "schematics_test_sources",
36-
srcs = glob(["**/*.spec.ts"], exclude=["**/files/**/*"]),
40+
srcs = glob(["**/*.spec.ts", "test-setup/**/*.ts"], exclude=["**/files/**/*"]),
3741
deps = [":schematics"],
3842
tsconfig = ":tsconfig.json",
3943
testonly = True,
@@ -44,23 +48,3 @@ filegroup(
4448
srcs = glob(["update/test-cases/**/*_input.ts", "update/test-cases/**/*_expected_output.ts"]),
4549
testonly = True,
4650
)
47-
48-
# Workaround for https://github.com/bazelbuild/rules_typescript/issues/154
49-
genrule(
50-
name = "copy-collection-file",
51-
srcs = ["collection.json"],
52-
outs = ["test-collection.json"],
53-
cmd = "cp $< $@",
54-
output_to_bindir = True,
55-
testonly = True,
56-
)
57-
58-
# Workaround for https://github.com/bazelbuild/rules_typescript/issues/154
59-
genrule(
60-
name = "copy-migration-file",
61-
srcs = ["migration.json"],
62-
outs = ["test-migration.json"],
63-
cmd = "cp $< $@",
64-
output_to_bindir = True,
65-
testonly = True,
66-
)

src/lib/schematics/address-form/schema.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"project": {
1414
"type": "string",
1515
"description": "The name of the project.",
16-
"visible": false
16+
"$default": {
17+
"$source": "projectName"
18+
}
1719
},
1820
"name": {
1921
"type": "string",
@@ -88,6 +90,12 @@
8890
"type": "boolean",
8991
"default": false,
9092
"description": "Specifies if declaring module exports the component."
93+
},
94+
"entryComponent": {
95+
"type": "boolean",
96+
"default": false,
97+
"description": "Specifies if the component is an entry component of declaring module."
9198
}
92-
}
99+
},
100+
"required": []
93101
}

src/lib/schematics/collection.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,43 @@
66
"ng-add": {
77
"description": "Adds Angular Material to the application without affecting any templates",
88
"factory": "./install",
9+
"schema": "./install/schema.json",
910
"aliases": ["material-shell"]
1011
},
1112
// Create a dashboard component
1213
"dashboard": {
1314
"description": "Create a card-based dashboard component",
1415
"factory": "./dashboard/index",
16+
"schema": "./dashboard/schema.json",
1517
"aliases": ["material-dashboard"]
1618
},
1719
// Creates a table component
1820
"table": {
1921
"description": "Create a component that displays data with a data-table",
2022
"factory": "./table/index",
23+
"schema": "./table/schema.json",
2124
"aliases": ["material-table"]
2225
},
2326
// Creates toolbar and navigation components
2427
"nav": {
2528
"description": "Create a component with a responsive sidenav for navigation",
2629
"factory": "./nav/index",
30+
"schema": "./nav/schema.json",
2731
// TODO(devversion): re-add `materialNav` alias if we have the latest schematics version
2832
// that includes https://github.com/angular/angular-cli/pull/11390
2933
"aliases": [ "material-nav"]
3034
},
3135
// Create a file tree component
3236
"tree": {
3337
"description": "Create a file tree component.",
34-
"factory": "./tree/index"
38+
"factory": "./tree/index",
39+
"schema": "./tree/schema.json"
3540
},
3641
// Creates a address form component
3742
"addressForm": {
3843
"description": "Create a component with a address form",
3944
"factory": "./address-form/index",
45+
"schema": "./address-form/schema.json",
4046
"aliases": ["address-form"]
4147
}
4248
}

src/lib/schematics/dashboard/index.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
2-
import {createTestApp, collectionPath} from '../utils/testing';
2+
import {collectionPath, createTestApp} from '../test-setup/test-app';
33
import {getFileContent} from '@schematics/angular/utility/test';
44
import {Schema} from './schema';
55

@@ -18,10 +18,7 @@ describe('material-dashboard-schematic', () => {
1818
runner = new SchematicTestRunner('schematics', collectionPath);
1919
});
2020

21-
// TODO(devversion): Temporarily disabled because @angular-devkit/schematics is not able to
22-
// find the template files for the schematic. As soon as we find a way to properly reference
23-
// those files, we can re-enable this test.
24-
xit('should create dashboard files and add them to module', () => {
21+
it('should create dashboard files and add them to module', () => {
2522
const tree = runner.runSchematic('dashboard', { ...options }, createTestApp());
2623
const files = tree.files;
2724

src/lib/schematics/dashboard/schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"project": {
1414
"type": "string",
1515
"description": "The name of the project.",
16-
"visible": false,
1716
"$default": {
1817
"$source": "projectName"
1918
}
@@ -91,6 +90,11 @@
9190
"type": "boolean",
9291
"default": false,
9392
"description": "Specifies if declaring module exports the component."
93+
},
94+
"entryComponent": {
95+
"type": "boolean",
96+
"default": false,
97+
"description": "Specifies if the component is an entry component of declaring module."
9498
}
9599
},
96100
"required": []

src/lib/schematics/install/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {Tree} from '@angular-devkit/schematics';
22
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
33
import {getProjectFromWorkspace} from '../utils/get-project';
44
import {getFileContent} from '@schematics/angular/utility/test';
5-
import {collectionPath, createTestApp} from '../utils/testing';
6-
import {getConfig, getAppFromConfig, getWorkspace} from '@schematics/angular/utility/config';
5+
import {collectionPath, createTestApp} from '../test-setup/test-app';
6+
import {getWorkspace} from '@schematics/angular/utility/config';
77
import {getIndexHtmlPath} from '../utils/ast';
88
import {normalize} from '@angular-devkit/core';
99

src/lib/schematics/nav/index.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
22
import {Schema} from './schema';
33
import {getFileContent} from '@schematics/angular/utility/test';
4-
import {collectionPath, createTestApp} from '../utils/testing';
4+
import {collectionPath, createTestApp} from '../test-setup/test-app';
55

66
describe('material-nav-schematic', () => {
77
let runner: SchematicTestRunner;
@@ -19,10 +19,7 @@ describe('material-nav-schematic', () => {
1919
runner = new SchematicTestRunner('schematics', collectionPath);
2020
});
2121

22-
// TODO(devversion): Temporarily disabled because @angular-devkit/schematics is not able to
23-
// find the template files for the schematic. As soon as we find a way to properly reference
24-
// those files, we can re-enable this test.
25-
xit('should create nav files and add them to module', () => {
22+
it('should create nav files and add them to module', () => {
2623
const tree = runner.runSchematic('nav', { ...options }, createTestApp());
2724
const files = tree.files;
2825

src/lib/schematics/nav/schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"project": {
1414
"type": "string",
1515
"description": "The name of the project.",
16-
"visible": false,
1716
"$default": {
1817
"$source": "projectName"
1918
}
@@ -91,6 +90,11 @@
9190
"type": "boolean",
9291
"default": false,
9392
"description": "Specifies if declaring module exports the component."
93+
},
94+
"entryComponent": {
95+
"type": "boolean",
96+
"default": false,
97+
"description": "Specifies if the component is an entry component of declaring module."
9498
}
9599
},
96100
"required": []

src/lib/schematics/table/index.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
22
import {Schema} from './schema';
33
import {getFileContent} from '@schematics/angular/utility/test';
4-
import {collectionPath, createTestApp} from '../utils/testing';
4+
import {collectionPath, createTestApp} from '../test-setup/test-app';
55

66
describe('material-table-schematic', () => {
77
let runner: SchematicTestRunner;
@@ -19,10 +19,7 @@ describe('material-table-schematic', () => {
1919
runner = new SchematicTestRunner('schematics', collectionPath);
2020
});
2121

22-
// TODO(devversion): Temporarily disabled because @angular-devkit/schematics is not able to
23-
// find the template files for the schematic. As soon as we find a way to properly reference
24-
// those files, we can re-enable this test.
25-
xit('should create table files and add them to module', () => {
22+
it('should create table files and add them to module', () => {
2623
const tree = runner.runSchematic('table', { ...options }, createTestApp());
2724
const files = tree.files;
2825

src/lib/schematics/table/schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"project": {
1414
"type": "string",
1515
"description": "The name of the project.",
16-
"visible": false,
1716
"$default": {
1817
"$source": "projectName"
1918
}
@@ -91,6 +90,11 @@
9190
"type": "boolean",
9291
"default": false,
9392
"description": "Specifies if declaring module exports the component."
93+
},
94+
"entryComponent": {
95+
"type": "boolean",
96+
"default": false,
97+
"description": "Specifies if the component is an entry component of declaring module."
9498
}
9599
},
96100
"required": []

0 commit comments

Comments
 (0)