Skip to content

Commit 7756882

Browse files
devversionjosephperrott
authored andcommitted
refactor(schematics): run tests for template files (#12562)
1 parent f8b70cd commit 7756882

File tree

19 files changed

+143
-92
lines changed

19 files changed

+143
-92
lines changed

src/lib/schematics/BUILD.bazel

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

@@ -30,12 +35,11 @@ jasmine_node_test(
3035
name = "unit_tests",
3136
srcs = [":schematics_test_sources"],
3237
data = [":schematics_assets", ":schematics_test_cases"],
33-
deps = [":copy-collection-file", ":copy-migration-file"],
3438
)
3539

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

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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';
5+
import {collectionPath, createTestApp} from '../test-setup/test-app';
66
import {getWorkspace} from '@schematics/angular/utility/config';
77
import {getIndexHtmlPath} from '../utils/ast';
88
import {normalize} from '@angular-devkit/core';

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)