|
| 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 schematics old options in angular.json', () => { |
| 13 | + const workspacePath = '/angular.json'; |
| 14 | + const schematicName = 'schematic-options-12'; |
| 15 | + |
| 16 | + const schematicRunner = new SchematicTestRunner( |
| 17 | + 'migrations', |
| 18 | + require.resolve('../migration-collection.json'), |
| 19 | + ); |
| 20 | + |
| 21 | + let tree: UnitTestTree; |
| 22 | + |
| 23 | + beforeEach(async () => { |
| 24 | + tree = new UnitTestTree(new EmptyTree()); |
| 25 | + tree = await schematicRunner |
| 26 | + .runExternalSchematicAsync( |
| 27 | + require.resolve('../../collection.json'), |
| 28 | + 'ng-new', |
| 29 | + { |
| 30 | + name: 'migration-test', |
| 31 | + version: '1.2.3', |
| 32 | + directory: '.', |
| 33 | + }, |
| 34 | + tree, |
| 35 | + ) |
| 36 | + .toPromise(); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('schematic options', () => { |
| 40 | + it('should remove `skipTests` from `@schematics/angular:module`', async () => { |
| 41 | + const workspace = JSON.parse(tree.readContent(workspacePath)); |
| 42 | + workspace.schematics = { |
| 43 | + '@schematics/angular:module': { |
| 44 | + skipTests: true, |
| 45 | + }, |
| 46 | + }; |
| 47 | + tree.overwrite(workspacePath, JSON.stringify(workspace, undefined, 2)); |
| 48 | + |
| 49 | + const tree2 = await schematicRunner |
| 50 | + .runSchematicAsync(schematicName, {}, tree.branch()) |
| 51 | + .toPromise(); |
| 52 | + const { schematics } = JSON.parse(tree2.readContent(workspacePath)); |
| 53 | + expect(schematics['@schematics/angular:module'].skipTests).toBeUndefined(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should not remove `skipTests` from non `@schematics/angular:module` schematic', async () => { |
| 57 | + const workspace = JSON.parse(tree.readContent(workspacePath)); |
| 58 | + workspace.schematics = { |
| 59 | + '@schematics/angular:component': { |
| 60 | + skipTests: true, |
| 61 | + }, |
| 62 | + '@schematics/some-other:module': { |
| 63 | + skipTests: true, |
| 64 | + }, |
| 65 | + }; |
| 66 | + tree.overwrite(workspacePath, JSON.stringify(workspace, undefined, 2)); |
| 67 | + |
| 68 | + const tree2 = await schematicRunner |
| 69 | + .runSchematicAsync(schematicName, {}, tree.branch()) |
| 70 | + .toPromise(); |
| 71 | + const { schematics } = JSON.parse(tree2.readContent(workspacePath)); |
| 72 | + expect(schematics['@schematics/angular:component'].skipTests).toBeTrue(); |
| 73 | + expect(schematics['@schematics/some-other:module'].skipTests).toBeTrue(); |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments