Skip to content

Commit aed0341

Browse files
FrozenPandazhansl
authored andcommitted
fix(@schematics/angular): use old config root to set root and sourceRoot during update-6
1 parent fd06d95 commit aed0341

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ function extractProjectsConfig(
388388
}
389389

390390
const project: JsonObject = {
391-
root: '',
392-
sourceRoot: 'src',
391+
root: join(normalize(appRoot), '..'),
392+
sourceRoot: appRoot,
393393
projectType: 'application',
394394
};
395395

@@ -526,7 +526,7 @@ function extractProjectsConfig(
526526
}
527527
const e2eProject: JsonObject = {
528528
root: project.root,
529-
sourceRoot: project.root,
529+
sourceRoot: join(project.root as Path, 'e2e'),
530530
projectType: 'application',
531531
};
532532

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,17 @@ describe('Migration to v6', () => {
509509
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
510510
const project = getConfig(tree).projects.foo;
511511
expect(project.root).toEqual('');
512+
expect(project.sourceRoot).toEqual('src');
513+
expect(project.projectType).toEqual('application');
514+
});
515+
516+
it('should set the project root values for a different root', () => {
517+
baseConfig.apps[0].root = 'apps/app1/src';
518+
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
519+
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
520+
const project = getConfig(tree).projects.foo;
521+
expect(project.root).toEqual('apps/app1');
522+
expect(project.sourceRoot).toEqual('apps/app1/src');
512523
expect(project.projectType).toEqual('application');
513524
});
514525

@@ -631,9 +642,26 @@ describe('Migration to v6', () => {
631642
it('should set the project root values', () => {
632643
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
633644
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
634-
const e2e = getConfig(tree).projects['foo-e2e'].architect.e2e;
635-
expect(e2e.builder).toEqual('@angular-devkit/build-angular:protractor');
636-
const options = e2e.options;
645+
const e2eProject = getConfig(tree).projects['foo-e2e'];
646+
expect(e2eProject.root).toBe('');
647+
expect(e2eProject.sourceRoot).toBe('e2e');
648+
const e2eOptions = e2eProject.architect.e2e;
649+
expect(e2eOptions.builder).toEqual('@angular-devkit/build-angular:protractor');
650+
const options = e2eOptions.options;
651+
expect(options.protractorConfig).toEqual('./protractor.conf.js');
652+
expect(options.devServerTarget).toEqual('foo:serve');
653+
});
654+
655+
it('should set the project root values for a different root', () => {
656+
baseConfig.apps[0].root = 'apps/app1/src';
657+
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
658+
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
659+
const e2eProject = getConfig(tree).projects['foo-e2e'];
660+
expect(e2eProject.root).toBe('apps/app1');
661+
expect(e2eProject.sourceRoot).toBe('apps/app1/e2e');
662+
const e2eOptions = e2eProject.architect.e2e;
663+
expect(e2eOptions.builder).toEqual('@angular-devkit/build-angular:protractor');
664+
const options = e2eOptions.options;
637665
expect(options.protractorConfig).toEqual('./protractor.conf.js');
638666
expect(options.devServerTarget).toEqual('foo:serve');
639667
});

0 commit comments

Comments
 (0)