|
| 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 | +import { latestVersions } from '../../utility/latest-versions'; |
| 12 | +import { Builders, ProjectType } from '../../utility/workspace-models'; |
| 13 | + |
| 14 | +describe(`Migration to add 'browser-sync' as a dev dependency`, () => { |
| 15 | + const schematicName = 'add-browser-sync-dependency'; |
| 16 | + const schematicRunner = new SchematicTestRunner( |
| 17 | + 'migrations', |
| 18 | + require.resolve('../migration-collection.json'), |
| 19 | + ); |
| 20 | + |
| 21 | + let tree: UnitTestTree; |
| 22 | + beforeEach(() => { |
| 23 | + tree = new UnitTestTree(new EmptyTree()); |
| 24 | + tree.create( |
| 25 | + '/package.json', |
| 26 | + JSON.stringify( |
| 27 | + { |
| 28 | + devDependencies: {}, |
| 29 | + }, |
| 30 | + undefined, |
| 31 | + 2, |
| 32 | + ), |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + it(`should add 'browser-sync' as devDependencies when '@angular-devkit/build-angular:ssr-dev-server' is used`, async () => { |
| 37 | + tree.create( |
| 38 | + '/angular.json', |
| 39 | + JSON.stringify( |
| 40 | + { |
| 41 | + version: 1, |
| 42 | + projects: { |
| 43 | + app: { |
| 44 | + root: '', |
| 45 | + projectType: ProjectType.Application, |
| 46 | + prefix: 'app', |
| 47 | + architect: { |
| 48 | + 'serve-ssr': { |
| 49 | + builder: Builders.SsrDevServer, |
| 50 | + options: {}, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + undefined, |
| 57 | + 2, |
| 58 | + ), |
| 59 | + ); |
| 60 | + |
| 61 | + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); |
| 62 | + const { devDependencies } = JSON.parse(newTree.readContent('/package.json')); |
| 63 | + expect(devDependencies['browser-sync']).toBe(latestVersions['browser-sync']); |
| 64 | + }); |
| 65 | + |
| 66 | + it(`should not add 'browser-sync' as devDependencies when '@angular-devkit/build-angular:ssr-dev-server' is not used`, async () => { |
| 67 | + tree.create( |
| 68 | + '/angular.json', |
| 69 | + JSON.stringify( |
| 70 | + { |
| 71 | + version: 1, |
| 72 | + projects: { |
| 73 | + app: { |
| 74 | + root: '', |
| 75 | + projectType: ProjectType.Application, |
| 76 | + prefix: 'app', |
| 77 | + architect: { |
| 78 | + 'serve-ssr': { |
| 79 | + builder: Builders.Browser, |
| 80 | + options: {}, |
| 81 | + }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + undefined, |
| 87 | + 2, |
| 88 | + ), |
| 89 | + ); |
| 90 | + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); |
| 91 | + const { devDependencies } = JSON.parse(newTree.readContent('/package.json')); |
| 92 | + expect(devDependencies['browser-sync']).toBeUndefined(); |
| 93 | + }); |
| 94 | +}); |
0 commit comments