|
| 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.dev/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { EmptyTree } from '@angular-devkit/schematics'; |
| 10 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 11 | +import { Builders, ProjectType } from '../../utility/workspace-models'; |
| 12 | + |
| 13 | +describe('Migration to update the angular workspace configuration', () => { |
| 14 | + const schematicName = 'update-workspace-config'; |
| 15 | + const schematicRunner = new SchematicTestRunner( |
| 16 | + 'migrations', |
| 17 | + require.resolve('../migration-collection.json'), |
| 18 | + ); |
| 19 | + |
| 20 | + let tree: UnitTestTree; |
| 21 | + beforeEach(() => { |
| 22 | + tree = new UnitTestTree(new EmptyTree()); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should rename experimentalPlatform to platform in application builder', async () => { |
| 26 | + const angularConfig = { |
| 27 | + version: 1, |
| 28 | + projects: { |
| 29 | + app: { |
| 30 | + root: '', |
| 31 | + sourceRoot: 'src', |
| 32 | + projectType: ProjectType.Application, |
| 33 | + prefix: 'app', |
| 34 | + architect: { |
| 35 | + build: { |
| 36 | + builder: Builders.Application, |
| 37 | + options: { |
| 38 | + ssr: { |
| 39 | + entry: 'src/server.ts', |
| 40 | + experimentalPlatform: 'neutral', |
| 41 | + }, |
| 42 | + }, |
| 43 | + configurations: { |
| 44 | + production: { |
| 45 | + ssr: { |
| 46 | + experimentalPlatform: 'node', |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }; |
| 55 | + |
| 56 | + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); |
| 57 | + |
| 58 | + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); |
| 59 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 60 | + const config = newTree.readJson('/angular.json') as any; |
| 61 | + const options = config.projects.app.architect.build.options; |
| 62 | + const prodOptions = config.projects.app.architect.build.configurations.production; |
| 63 | + |
| 64 | + expect(options.ssr.platform).toBe('neutral'); |
| 65 | + expect(options.ssr.experimentalPlatform).toBeUndefined(); |
| 66 | + expect(prodOptions.ssr.platform).toBe('node'); |
| 67 | + expect(prodOptions.ssr.experimentalPlatform).toBeUndefined(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should not change other builders', async () => { |
| 71 | + const angularConfig = { |
| 72 | + version: 1, |
| 73 | + projects: { |
| 74 | + app: { |
| 75 | + root: '', |
| 76 | + sourceRoot: 'src', |
| 77 | + projectType: ProjectType.Application, |
| 78 | + prefix: 'app', |
| 79 | + architect: { |
| 80 | + build: { |
| 81 | + builder: Builders.Browser, |
| 82 | + options: { |
| 83 | + ssr: { |
| 84 | + experimentalPlatform: 'neutral', |
| 85 | + }, |
| 86 | + }, |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + }; |
| 92 | + |
| 93 | + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); |
| 94 | + |
| 95 | + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); |
| 96 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 97 | + const config = newTree.readJson('/angular.json') as any; |
| 98 | + const options = config.projects.app.architect.build.options; |
| 99 | + |
| 100 | + expect(options.ssr.experimentalPlatform).toBe('neutral'); |
| 101 | + expect(options.ssr.platform).toBeUndefined(); |
| 102 | + }); |
| 103 | +}); |
0 commit comments