Skip to content

Commit 95dcb36

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
test: update to support targets & architect fields
1 parent 7fbaba5 commit 95dcb36

40 files changed

+109
-103
lines changed

packages/angular/pwa/pwa/index_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('PWA Schematic', () => {
5151
const tree = schematicRunner.runSchematic('ng-add', defaultOptions, appTree);
5252
const configText = tree.readContent('/angular.json');
5353
const config = JSON.parse(configText);
54-
const swFlag = config.projects.bar.targets.build.configurations.production.serviceWorker;
54+
const swFlag = config.projects.bar.architect.build.configurations.production.serviceWorker;
5555
expect(swFlag).toEqual(true);
5656
});
5757

@@ -101,7 +101,7 @@ describe('PWA Schematic', () => {
101101
const tree = schematicRunner.runSchematic('ng-add', defaultOptions, appTree);
102102
const configText = tree.readContent('/angular.json');
103103
const config = JSON.parse(configText);
104-
const targets = config.projects.bar.targets;
104+
const targets = config.projects.bar.architect;
105105
['build', 'test'].forEach((target) => {
106106
expect(targets[target].options.assets).toContain('projects/bar/src/manifest.json');
107107
});

packages/schematics/angular/app-shell/index_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('App Shell Schematic', () => {
6464
const filePath = '/angular.json';
6565
const content = tree.readContent(filePath);
6666
const workspace = JSON.parse(content);
67-
const target = workspace.projects.bar.targets['app-shell'];
67+
const target = workspace.projects.bar.architect['app-shell'];
6868
expect(target.options.browserTarget).toEqual('bar:build');
6969
expect(target.options.serverTarget).toEqual('bar:server');
7070
expect(target.options.route).toEqual('shell');

packages/schematics/angular/application/index_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ describe('Application Schematic', () => {
207207
const config = JSON.parse(tree.readContent('/angular.json'));
208208
const prj = config.projects.foo;
209209
expect(prj.root).toEqual('');
210-
const buildOpt = prj.targets.build.options;
210+
const buildOpt = prj.architect.build.options;
211211
expect(buildOpt.index).toEqual('src/index.html');
212212
expect(buildOpt.main).toEqual('src/main.ts');
213213
expect(buildOpt.polyfills).toEqual('src/polyfills.ts');
214214
expect(buildOpt.tsConfig).toEqual('src/tsconfig.app.json');
215215

216-
const testOpt = prj.targets.test.options;
216+
const testOpt = prj.architect.test.options;
217217
expect(testOpt.main).toEqual('src/test.ts');
218218
expect(testOpt.tsConfig).toEqual('src/tsconfig.spec.json');
219219
expect(testOpt.karmaConfig).toEqual('src/karma.conf.js');

packages/schematics/angular/e2e/index_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ describe('Application Schematic', () => {
7979
it('should set 2 targets for the app', () => {
8080
const tree = schematicRunner.runSchematic('e2e', defaultOptions, workspaceTree);
8181
const workspace = JSON.parse(tree.readContent('/angular.json'));
82-
const targets = workspace.projects.foo.targets;
82+
const targets = workspace.projects.foo.architect;
8383
expect(Object.keys(targets)).toEqual(['e2e', 'lint']);
8484
});
8585

8686
it('should set the e2e options', () => {
8787
const tree = schematicRunner.runSchematic('e2e', defaultOptions, workspaceTree);
8888
const workspace = JSON.parse(tree.readContent('/angular.json'));
89-
const e2eOptions = workspace.projects.foo.targets.e2e.options;
89+
const e2eOptions = workspace.projects.foo.architect.e2e.options;
9090
expect(e2eOptions.protractorConfig).toEqual('projects/foo/protractor.conf.js');
9191
expect(e2eOptions.devServerTarget).toEqual('app:serve');
9292
});
9393

9494
it('should set the lint options', () => {
9595
const tree = schematicRunner.runSchematic('e2e', defaultOptions, workspaceTree);
9696
const workspace = JSON.parse(tree.readContent('/angular.json'));
97-
const lintOptions = workspace.projects.foo.targets.lint.options;
97+
const lintOptions = workspace.projects.foo.architect.lint.options;
9898
expect(lintOptions.tsConfig).toEqual('projects/foo/tsconfig.e2e.json');
9999
});
100100
});

packages/schematics/angular/migrations/update-6/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function migrateConfiguration(oldConfig: CliConfig, logger: logging.LoggerApi):
121121
}
122122
const targetsConfig = extractTargetsConfig(oldConfig);
123123
if (targetsConfig !== null) {
124-
config.targets = targetsConfig;
124+
config.architect = targetsConfig;
125125
}
126126

127127
context.logger.info(`Removing old config file (${oldConfigPath})`);
@@ -577,7 +577,7 @@ function extractProjectsConfig(
577577
};
578578
e2eTargets.lint = e2eLintTarget;
579579
if (protractorConfig) {
580-
e2eProject.targets = e2eTargets;
580+
e2eProject.architect = e2eTargets;
581581
}
582582

583583
return { name, project, e2eProject };

packages/schematics/angular/migrations/update-6/index_spec.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ describe('Migration to v6', () => {
124124
return JSON.parse(tree.readContent(configPath));
125125
}
126126

127+
// tslint:disable-next-line:no-any
128+
function getTarget(tree: UnitTestTree, targetName: string): any {
129+
const project = getConfig(tree).projects.foo;
130+
131+
return project.architect[targetName];
132+
}
133+
127134
describe('file creation/deletion', () => {
128135
it('should delete the old config file', () => {
129136
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
@@ -474,7 +481,7 @@ describe('Migration to v6', () => {
474481
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
475482
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
476483
const config = getConfig(tree);
477-
expect(config.targets).not.toBeDefined();
484+
expect(config.architect).not.toBeDefined();
478485
});
479486
});
480487

@@ -526,7 +533,7 @@ describe('Migration to v6', () => {
526533
it('should set build target', () => {
527534
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
528535
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
529-
const build = getConfig(tree).projects.foo.targets.build;
536+
const build = getTarget(tree, 'build');
530537
expect(build.builder).toEqual('@angular-devkit/build-angular:browser');
531538
expect(build.options.scripts).toEqual([]);
532539
expect(build.options.styles).toEqual(['src/styles.css']);
@@ -560,7 +567,7 @@ describe('Migration to v6', () => {
560567
it('should not set baseHref on build & serve targets if not defined', () => {
561568
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
562569
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
563-
const build = getConfig(tree).projects.foo.targets.build;
570+
const build = getTarget(tree, 'build');
564571
expect(build.options.baseHref).toBeUndefined();
565572
});
566573

@@ -569,27 +576,25 @@ describe('Migration to v6', () => {
569576
config.apps[0].baseHref = '/base/href/';
570577
tree.create(oldConfigPath, JSON.stringify(config, null, 2));
571578
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
572-
const build = getConfig(tree).projects.foo.targets.build;
579+
const build = getTarget(tree, 'build');
573580
expect(build.options.baseHref).toEqual('/base/href/');
574581
});
575582

576583
it('should add serviceWorker to production configuration', () => {
577584
baseConfig.apps[0].serviceWorker = true;
578585
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
579586
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
580-
const config = getConfig(tree);
581-
expect(config.projects.foo.targets.build.options.serviceWorker).toBeUndefined();
582-
expect(
583-
config.projects.foo.targets.build.configurations.production.serviceWorker,
584-
).toBe(true);
587+
const build = getTarget(tree, 'build');
588+
expect(build.options.serviceWorker).toBeUndefined();
589+
expect(build.configurations.production.serviceWorker).toBe(true);
585590
});
586591

587592
it('should add production configuration when no environments', () => {
588593
delete baseConfig.apps[0].environments;
589594
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
590595
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
591-
const config = getConfig(tree);
592-
expect(config.projects.foo.targets.build.configurations).toEqual({
596+
const build = getTarget(tree, 'build');
597+
expect(build.configurations).toEqual({
593598
production: {
594599
optimization: true,
595600
outputHashing: 'all',
@@ -608,8 +613,8 @@ describe('Migration to v6', () => {
608613
tree.delete('/src/environments/environment.prod.ts');
609614
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
610615
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
611-
const config = getConfig(tree);
612-
expect(config.projects.foo.targets.build.configurations).toEqual({
616+
const build = getTarget(tree, 'build');
617+
expect(build.configurations).toEqual({
613618
prod: {
614619
fileReplacements: [{
615620
replace: 'src/environments/environment.ts',
@@ -633,7 +638,7 @@ describe('Migration to v6', () => {
633638
it('should set the serve target', () => {
634639
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
635640
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
636-
const serve = getConfig(tree).projects.foo.targets.serve;
641+
const serve = getTarget(tree, 'serve');
637642
expect(serve.builder).toEqual('@angular-devkit/build-angular:dev-server');
638643
expect(serve.options).toEqual({
639644
browserTarget: 'foo:build',
@@ -646,7 +651,7 @@ describe('Migration to v6', () => {
646651
it('should set the test target', () => {
647652
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
648653
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
649-
const test = getConfig(tree).projects.foo.targets['test'];
654+
const test = getTarget(tree, 'test');
650655
expect(test.builder).toEqual('@angular-devkit/build-angular:karma');
651656
expect(test.options.main).toEqual('src/test.ts');
652657
expect(test.options.polyfills).toEqual('src/polyfills.ts');
@@ -665,7 +670,7 @@ describe('Migration to v6', () => {
665670
it('should set the extract i18n target', () => {
666671
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
667672
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
668-
const extract = getConfig(tree).projects.foo.targets['extract-i18n'];
673+
const extract = getTarget(tree, 'extract-i18n');
669674
expect(extract.builder).toEqual('@angular-devkit/build-angular:extract-i18n');
670675
expect(extract.options).toBeDefined();
671676
expect(extract.options.browserTarget).toEqual(`foo:build` );
@@ -674,7 +679,7 @@ describe('Migration to v6', () => {
674679
it('should set the lint target', () => {
675680
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
676681
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
677-
const tslint = getConfig(tree).projects.foo.targets['lint'];
682+
const tslint = getTarget(tree, 'lint');
678683
expect(tslint.builder).toEqual('@angular-devkit/build-angular:tslint');
679684
expect(tslint.options).toBeDefined();
680685
expect(tslint.options.tsConfig)
@@ -691,8 +696,8 @@ describe('Migration to v6', () => {
691696

692697
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
693698
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
694-
const config = getConfig(tree);
695-
const budgets = config.projects.foo.targets.build.configurations.production.budgets;
699+
const build = getTarget(tree, 'build');
700+
const budgets = build.configurations.production.budgets;
696701
expect(budgets.length).toEqual(1);
697702
expect(budgets[0].type).toEqual('bundle');
698703
expect(budgets[0].name).toEqual('main');
@@ -707,7 +712,7 @@ describe('Migration to v6', () => {
707712
const e2eProject = getConfig(tree).projects['foo-e2e'];
708713
expect(e2eProject.root).toBe('e2e');
709714
expect(e2eProject.sourceRoot).toBe('e2e');
710-
const e2eOptions = e2eProject.targets.e2e;
715+
const e2eOptions = e2eProject.architect.e2e;
711716
expect(e2eOptions.builder).toEqual('@angular-devkit/build-angular:protractor');
712717
const options = e2eOptions.options;
713718
expect(options.protractorConfig).toEqual('./protractor.conf.js');
@@ -721,7 +726,7 @@ describe('Migration to v6', () => {
721726
const e2eProject = getConfig(tree).projects['foo-e2e'];
722727
expect(e2eProject.root).toBe('apps/app1/e2e');
723728
expect(e2eProject.sourceRoot).toBe('apps/app1/e2e');
724-
const e2eOptions = e2eProject.targets.e2e;
729+
const e2eOptions = e2eProject.architect.e2e;
725730
expect(e2eOptions.builder).toEqual('@angular-devkit/build-angular:protractor');
726731
const options = e2eOptions.options;
727732
expect(options.protractorConfig).toEqual('./protractor.conf.js');
@@ -731,7 +736,7 @@ describe('Migration to v6', () => {
731736
it('should set the lint target', () => {
732737
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
733738
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
734-
const tslint = getConfig(tree).projects['foo-e2e'].targets.lint;
739+
const tslint = getConfig(tree).projects['foo-e2e'].architect.lint;
735740
expect(tslint.builder).toEqual('@angular-devkit/build-angular:tslint');
736741
expect(tslint.options).toBeDefined();
737742
expect(tslint.options.tsConfig).toEqual(['e2e/tsconfig.e2e.json']);
@@ -988,7 +993,7 @@ describe('Migration to v6', () => {
988993
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
989994
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
990995
const config = getConfig(tree);
991-
const target = config.projects.foo.targets.server;
996+
const target = config.projects.foo.architect.server;
992997
expect(target).toBeDefined();
993998
expect(target.builder).toEqual('@angular-devkit/build-angular:server');
994999
expect(target.options.outputPath).toEqual('dist/server');

packages/schematics/angular/service-worker/index_spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ describe('Service Worker Schematic', () => {
4545
appTree = schematicRunner.runSchematic('application', appOptions, appTree);
4646
});
4747

48-
it('should update the proudction configuration', () => {
48+
it('should update the production configuration', () => {
4949
const tree = schematicRunner.runSchematic('service-worker', defaultOptions, appTree);
5050
const configText = tree.readContent('/angular.json');
5151
const config = JSON.parse(configText);
52-
const swFlag = config.projects.bar.targets.build.configurations.production.serviceWorker;
52+
const swFlag = config.projects.bar.architect
53+
.build.configurations.production.serviceWorker;
5354
expect(swFlag).toEqual(true);
5455
});
5556

@@ -58,7 +59,8 @@ describe('Service Worker Schematic', () => {
5859
const tree = schematicRunner.runSchematic('service-worker', options, appTree);
5960
const configText = tree.readContent('/angular.json');
6061
const config = JSON.parse(configText);
61-
const swFlag = config.projects.bar.targets.build.options.serviceWorker;
62+
const swFlag = config.projects.bar.architect
63+
.build.options.serviceWorker;
6264
expect(swFlag).toEqual(true);
6365
});
6466

packages/schematics/angular/universal/index_spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ describe('Universal Schematic', () => {
8787
},
8888
});
8989
const angularConfig = JSON.parse(tree.readContent('angular.json'));
90-
expect(angularConfig.projects.workspace.targets.server.options.tsConfig)
91-
.toEqual('src/tsconfig.server.json');
90+
expect(angularConfig.projects.workspace.architect
91+
.server.options.tsConfig).toEqual('src/tsconfig.server.json');
9292
});
9393

9494
it('should create a tsconfig file for a generated application', () => {
@@ -107,8 +107,8 @@ describe('Universal Schematic', () => {
107107
},
108108
});
109109
const angularConfig = JSON.parse(tree.readContent('angular.json'));
110-
expect(angularConfig.projects.bar.targets.server.options.tsConfig)
111-
.toEqual('projects/bar/tsconfig.server.json');
110+
expect(angularConfig.projects.bar.architect
111+
.server.options.tsConfig).toEqual('projects/bar/tsconfig.server.json');
112112
});
113113

114114
it('should add dependency: @angular/platform-server', () => {
@@ -123,7 +123,7 @@ describe('Universal Schematic', () => {
123123
const filePath = '/angular.json';
124124
const contents = tree.readContent(filePath);
125125
const config = JSON.parse(contents.toString());
126-
const targets = config.projects.bar.targets;
126+
const targets = config.projects.bar.architect;
127127
expect(targets.server).toBeDefined();
128128
expect(targets.server.builder).toBeDefined();
129129
const opts = targets.server.options;

tests/legacy-cli/e2e/tests/basic/assets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ export default function () {
9393
{ 'glob': '**/*', 'input': 'src/folder', 'output': 'folder' },
9494
{ 'glob': 'glob-asset.txt' },
9595
{ 'glob': 'output-asset.txt', 'output': 'output-folder' },
96-
{ 'glob': '**/*', 'input': 'node_modules/some-package/', 'output': 'package-folder' }
96+
{ 'glob': '**/*', 'input': 'node_modules/some-package/', 'output': 'package-folder' },
9797
];
98-
const appArchitect = workspaceJson.projects['test-project'].targets;
98+
const appArchitect = workspaceJson.projects['test-project'].architect;
9999
appArchitect.build.options.assets = assets;
100100
appArchitect.test.options.assets = assets;
101101
}))

tests/legacy-cli/e2e/tests/basic/scripts-array.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export default function () {
2525
'src/input-script.js': 'console.log(\'input-script\');',
2626
'src/lazy-script.js': 'console.log(\'lazy-script\');',
2727
'src/pre-rename-script.js': 'console.log(\'pre-rename-script\');',
28-
'src/pre-rename-lazy-script.js': 'console.log(\'pre-rename-lazy-script\');'
28+
'src/pre-rename-lazy-script.js': 'console.log(\'pre-rename-lazy-script\');',
2929
})
3030
.then(() => appendToFile('src/main.ts', 'import \'./string-script.js\';'))
3131
.then(() => updateJsonFile('angular.json', configJson => {
32-
const appArchitect = configJson.projects['test-project'].targets;
32+
const appArchitect = configJson.projects['test-project'].architect;
3333
appArchitect.build.options.scripts = [
3434
{ input: 'src/string-script.js' },
3535
{ input: 'src/zstring-script.js' },

tests/legacy-cli/e2e/tests/basic/styles-array.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export default function () {
1414
'src/input-style.css': '.input-style { color: red }',
1515
'src/lazy-style.css': '.lazy-style { color: red }',
1616
'src/pre-rename-style.css': '.pre-rename-style { color: red }',
17-
'src/pre-rename-lazy-style.css': '.pre-rename-lazy-style { color: red }'
17+
'src/pre-rename-lazy-style.css': '.pre-rename-lazy-style { color: red }',
1818
})
1919
.then(() => updateJsonFile('angular.json', workspaceJson => {
20-
const appArchitect = workspaceJson.projects['test-project'].targets;
20+
const appArchitect = workspaceJson.projects['test-project'].architect;
2121
appArchitect.build.options.styles = [
2222
{ input: 'src/string-style.css' },
2323
{ input: 'src/input-style.css' },

tests/legacy-cli/e2e/tests/build/build-app-shell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function () {
2626

2727
return Promise.resolve()
2828
.then(() => updateJsonFile('angular.json', workspaceJson => {
29-
const appArchitect = workspaceJson.projects['test-project'].targets;
29+
const appArchitect = workspaceJson.projects['test-project'].architect;
3030
appArchitect['server'] = {
3131
builder: '@angular-devkit/build-angular:server',
3232
options: {

0 commit comments

Comments
 (0)