|
| 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 { JsonObject } from '@angular-devkit/core'; |
| 10 | +import { EmptyTree } from '@angular-devkit/schematics'; |
| 11 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 12 | +import { |
| 13 | + BuilderTarget, |
| 14 | + Builders, |
| 15 | + ProjectType, |
| 16 | + WorkspaceSchema, |
| 17 | +} from '../../utility/workspace-models'; |
| 18 | + |
| 19 | +function getBuildTarget(tree: UnitTestTree): BuilderTarget<Builders.Browser, JsonObject> { |
| 20 | + return JSON.parse(tree.readContent('/angular.json')).projects.app.architect.build; |
| 21 | +} |
| 22 | + |
| 23 | +function createWorkSpaceConfig(tree: UnitTestTree) { |
| 24 | + const angularConfig: WorkspaceSchema = { |
| 25 | + version: 1, |
| 26 | + projects: { |
| 27 | + app: { |
| 28 | + root: '', |
| 29 | + sourceRoot: 'src', |
| 30 | + projectType: ProjectType.Application, |
| 31 | + prefix: 'app', |
| 32 | + architect: { |
| 33 | + build: { |
| 34 | + builder: Builders.Browser, |
| 35 | + options: { |
| 36 | + extractCss: false, |
| 37 | + showCircularDependencies: true, |
| 38 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 39 | + } as any, |
| 40 | + configurations: { |
| 41 | + one: { |
| 42 | + showCircularDependencies: false, |
| 43 | + aot: true, |
| 44 | + }, |
| 45 | + two: { |
| 46 | + showCircularDependencies: false, |
| 47 | + aot: true, |
| 48 | + }, |
| 49 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 50 | + } as any, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }; |
| 56 | + |
| 57 | + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); |
| 58 | +} |
| 59 | + |
| 60 | +describe(`Migration to remove 'showCircularDependencies' option.`, () => { |
| 61 | + const schematicName = 'remove-show-circular-dependencies-option'; |
| 62 | + const schematicRunner = new SchematicTestRunner( |
| 63 | + 'migrations', |
| 64 | + require.resolve('../migration-collection.json'), |
| 65 | + ); |
| 66 | + |
| 67 | + let tree: UnitTestTree; |
| 68 | + beforeEach(() => { |
| 69 | + tree = new UnitTestTree(new EmptyTree()); |
| 70 | + createWorkSpaceConfig(tree); |
| 71 | + }); |
| 72 | + |
| 73 | + it(`should remove 'showCircularDependencies'`, async () => { |
| 74 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 75 | + const { options, configurations } = getBuildTarget(newTree); |
| 76 | + |
| 77 | + expect(options.showCircularDependencies).toBeUndefined(); |
| 78 | + expect(configurations).toBeDefined(); |
| 79 | + expect(configurations?.one.showCircularDependencies).toBeUndefined(); |
| 80 | + expect(configurations?.two.showCircularDependencies).toBeUndefined(); |
| 81 | + }); |
| 82 | +}); |
0 commit comments