|
| 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 { EmptyTree } from '@angular-devkit/schematics'; |
| 10 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 11 | + |
| 12 | +describe(`Migration to remove 'defaultProject' option.`, () => { |
| 13 | + const schematicName = 'remove-default-project-option'; |
| 14 | + const schematicRunner = new SchematicTestRunner( |
| 15 | + 'migrations', |
| 16 | + require.resolve('../migration-collection.json'), |
| 17 | + ); |
| 18 | + |
| 19 | + let tree: UnitTestTree; |
| 20 | + beforeEach(() => { |
| 21 | + tree = new UnitTestTree(new EmptyTree()); |
| 22 | + }); |
| 23 | + |
| 24 | + it(`should remove 'defaultProject'`, async () => { |
| 25 | + const angularConfig = { |
| 26 | + version: 1, |
| 27 | + projects: {}, |
| 28 | + defaultProject: 'foo', |
| 29 | + }; |
| 30 | + |
| 31 | + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); |
| 32 | + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); |
| 33 | + const { defaultProject } = JSON.parse(newTree.readContent('/angular.json')); |
| 34 | + |
| 35 | + expect(defaultProject).toBeUndefined(); |
| 36 | + }); |
| 37 | + |
| 38 | + it(`should not error when 'defaultProject' is not defined`, async () => { |
| 39 | + const angularConfig = { |
| 40 | + version: 1, |
| 41 | + projects: {}, |
| 42 | + }; |
| 43 | + |
| 44 | + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); |
| 45 | + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); |
| 46 | + const { defaultProject } = JSON.parse(newTree.readContent('/angular.json')); |
| 47 | + |
| 48 | + expect(defaultProject).toBeUndefined(); |
| 49 | + }); |
| 50 | +}); |
0 commit comments