|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. 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 | +import { EmptyTree } from '@angular-devkit/schematics'; |
| 9 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 10 | +import { Builders, ProjectType, WorkspaceSchema } from '../../utility/workspace-models'; |
| 11 | + |
| 12 | +function createWorkSpaceConfig(tree: UnitTestTree) { |
| 13 | + const angularConfig: WorkspaceSchema = { |
| 14 | + version: 1, |
| 15 | + projects: { |
| 16 | + demo: { |
| 17 | + root: '', |
| 18 | + sourceRoot: 'src', |
| 19 | + projectType: ProjectType.Application, |
| 20 | + prefix: 'app', |
| 21 | + architect: { |
| 22 | + build: { |
| 23 | + builder: Builders.Browser, |
| 24 | + options: { |
| 25 | + tsConfig: '', |
| 26 | + main: '', |
| 27 | + polyfills: '', |
| 28 | + }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }; |
| 34 | + |
| 35 | + tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); |
| 36 | +} |
| 37 | + |
| 38 | +describe(`Migration to add sideEffects package.json`, () => { |
| 39 | + const schematicName = 'side-effects-package-json'; |
| 40 | + |
| 41 | + const schematicRunner = new SchematicTestRunner( |
| 42 | + 'migrations', |
| 43 | + require.resolve('../migration-collection.json'), |
| 44 | + ); |
| 45 | + |
| 46 | + let tree: UnitTestTree; |
| 47 | + beforeEach(() => { |
| 48 | + tree = new UnitTestTree(new EmptyTree()); |
| 49 | + createWorkSpaceConfig(tree); |
| 50 | + tree.create('src/app/main.ts', ''); |
| 51 | + }); |
| 52 | + |
| 53 | + it(`should create a package.json with sideEffects true under app folder.`, async () => { |
| 54 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 55 | + const { name, sideEffects } = JSON.parse(newTree.readContent('src/app/package.json')); |
| 56 | + expect(name).toBe('demo'); |
| 57 | + expect(sideEffects).toBeTrue(); |
| 58 | + }); |
| 59 | +}); |
0 commit comments