|
| 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 { getPackageJsonDependency } from '../../utility/dependencies'; |
| 11 | + |
| 12 | +const schematicName = 'update-zonejs'; |
| 13 | +describe(`Migration to update 'zone.js' to 0.11.x. ${schematicName}`, () => { |
| 14 | + const schematicRunner = new SchematicTestRunner( |
| 15 | + 'migrations', |
| 16 | + require.resolve('../migration-collection.json'), |
| 17 | + ); |
| 18 | + |
| 19 | + let tree: UnitTestTree; |
| 20 | + beforeEach(() => { |
| 21 | + tree = new UnitTestTree(new EmptyTree()); |
| 22 | + tree.create('/package.json', JSON.stringify({ 'dependencies': { 'zone.js': '~0.10.0' } }, undefined, 2)); |
| 23 | + }); |
| 24 | + |
| 25 | + it(`should update 'zone.js' dependency in 'package.json'`, async () => { |
| 26 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 27 | + expect(getPackageJsonDependency(newTree, 'zone.js')?.version).toBe('~0.11.4'); |
| 28 | + }); |
| 29 | + |
| 30 | + it(`should update 'zone.js/dist/zone' import`, async () => { |
| 31 | + tree.create('file.ts', ` |
| 32 | + import 'zone.js'; |
| 33 | + import 'zone.js/dist/zone'; |
| 34 | + import "zone.js/dist/zone"; |
| 35 | + // import "zone.js/dist/zone"; |
| 36 | + `); |
| 37 | + |
| 38 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 39 | + expect(newTree.readContent('file.ts')).toBe(` |
| 40 | + import 'zone.js'; |
| 41 | + import 'zone.js'; |
| 42 | + import "zone.js"; |
| 43 | + // import "zone.js"; |
| 44 | + `); |
| 45 | + }); |
| 46 | + |
| 47 | + it(`should update 'zone.js/dist/zone' require`, async () => { |
| 48 | + tree.create('file.ts', ` |
| 49 | + require('zone.js'); |
| 50 | + require('zone.js/dist/zone'); |
| 51 | + require("zone.js/dist/zone"); |
| 52 | + // require("zone.js/dist/zone"); |
| 53 | + `); |
| 54 | + |
| 55 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 56 | + expect(newTree.readContent('file.ts')).toBe(` |
| 57 | + require('zone.js'); |
| 58 | + require('zone.js'); |
| 59 | + require("zone.js"); |
| 60 | + // require("zone.js"); |
| 61 | + `); |
| 62 | + }); |
| 63 | + |
| 64 | + it(`should update 'zone.js/dist/zone-error' import`, async () => { |
| 65 | + tree.create('file.ts', ` |
| 66 | + import 'zone.js/plugins/zone-error'; |
| 67 | + import 'zone.js/dist/zone-error'; |
| 68 | + import "zone.js/dist/zone-error"; |
| 69 | + // import "zone.js/dist/zone-error"; |
| 70 | + `); |
| 71 | + |
| 72 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 73 | + expect(newTree.readContent('file.ts')).toBe(` |
| 74 | + import 'zone.js/plugins/zone-error'; |
| 75 | + import 'zone.js/plugins/zone-error'; |
| 76 | + import "zone.js/plugins/zone-error"; |
| 77 | + // import "zone.js/plugins/zone-error"; |
| 78 | + `); |
| 79 | + }); |
| 80 | + |
| 81 | + it(`should update 'zone.js/dist/zone-error' require`, async () => { |
| 82 | + tree.create('file.ts', ` |
| 83 | + require('zone.js/plugins/zone-error'); |
| 84 | + require('zone.js/dist/zone-error'); |
| 85 | + require("zone.js/dist/zone-error"); |
| 86 | + // require("zone.js/dist/zone-error"); |
| 87 | + `); |
| 88 | + |
| 89 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 90 | + expect(newTree.readContent('file.ts')).toBe(` |
| 91 | + require('zone.js/plugins/zone-error'); |
| 92 | + require('zone.js/plugins/zone-error'); |
| 93 | + require("zone.js/plugins/zone-error"); |
| 94 | + // require("zone.js/plugins/zone-error"); |
| 95 | + `); |
| 96 | + }); |
| 97 | + |
| 98 | + it(`should update 'zone.js/dist/zone-testing' import`, async () => { |
| 99 | + tree.create('file.ts', ` |
| 100 | + import 'zone.js/testing'; |
| 101 | + import 'zone.js/dist/zone-testing'; |
| 102 | + import "zone.js/dist/zone-testing"; |
| 103 | + // import "zone.js/dist/zone-testing"; |
| 104 | + `); |
| 105 | + |
| 106 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 107 | + expect(newTree.readContent('file.ts')).toBe(` |
| 108 | + import 'zone.js/testing'; |
| 109 | + import 'zone.js/testing'; |
| 110 | + import "zone.js/testing"; |
| 111 | + // import "zone.js/testing"; |
| 112 | + `); |
| 113 | + }); |
| 114 | + |
| 115 | + it(`should update 'zone.js/dist/zone-testing' require`, async () => { |
| 116 | + tree.create('file.ts', ` |
| 117 | + require('zone.js/testing'); |
| 118 | + require('zone.js/dist/zone-testing'); |
| 119 | + require("zone.js/dist/zone-testing"); |
| 120 | + // require("zone.js/dist/zone-testing"); |
| 121 | + `); |
| 122 | + |
| 123 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 124 | + expect(newTree.readContent('file.ts')).toBe(` |
| 125 | + require('zone.js/testing'); |
| 126 | + require('zone.js/testing'); |
| 127 | + require("zone.js/testing"); |
| 128 | + // require("zone.js/testing"); |
| 129 | + `); |
| 130 | + }); |
| 131 | +}); |
0 commit comments