|
| 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 { parse as parseJson } from 'jsonc-parser'; |
| 11 | + |
| 12 | +describe('Migration to remove "emitDecoratorMetadata" compiler option', () => { |
| 13 | + const schematicName = 'remove-emit-decorator-metadata'; |
| 14 | + |
| 15 | + const schematicRunner = new SchematicTestRunner( |
| 16 | + 'migrations', |
| 17 | + require.resolve('../migration-collection.json'), |
| 18 | + ); |
| 19 | + |
| 20 | + // tslint:disable-next-line: no-any |
| 21 | + function readJsonFile(tree: UnitTestTree, filePath: string): any { |
| 22 | + return parseJson(tree.readContent(filePath).toString()); |
| 23 | + } |
| 24 | + |
| 25 | + let tree: UnitTestTree; |
| 26 | + beforeEach(() => { |
| 27 | + tree = new UnitTestTree(new EmptyTree()); |
| 28 | + }); |
| 29 | + |
| 30 | + it(`should rename 'emitDecoratorMetadata' when set to false`, async () => { |
| 31 | + tree.create('/tsconfig.json', JSON.stringify({ |
| 32 | + compilerOptions: { |
| 33 | + emitDecoratorMetadata: false, |
| 34 | + strict: true, |
| 35 | + }, |
| 36 | + }, undefined, 2)); |
| 37 | + |
| 38 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 39 | + const { compilerOptions } = readJsonFile(newTree, '/tsconfig.json'); |
| 40 | + expect(compilerOptions['emitDecoratorMetadata']).toBeUndefined(); |
| 41 | + expect(compilerOptions['strict']).toBeTrue(); |
| 42 | + }); |
| 43 | + |
| 44 | + it(`should rename 'emitDecoratorMetadata' when set to true`, async () => { |
| 45 | + tree.create('/tsconfig.json', JSON.stringify({ |
| 46 | + compilerOptions: { |
| 47 | + emitDecoratorMetadata: true, |
| 48 | + strict: true, |
| 49 | + }, |
| 50 | + }, undefined, 2)); |
| 51 | + |
| 52 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 53 | + const { compilerOptions } = readJsonFile(newTree, '/tsconfig.json'); |
| 54 | + expect(compilerOptions['emitDecoratorMetadata']).toBeUndefined(); |
| 55 | + expect(compilerOptions['strict']).toBeTrue(); |
| 56 | + }); |
| 57 | + |
| 58 | + it(`should not rename 'emitDecoratorMetadata' when it's not under 'compilerOptions'`, async () => { |
| 59 | + tree.create('/foo.json', JSON.stringify({ |
| 60 | + options: { |
| 61 | + emitDecoratorMetadata: true, |
| 62 | + }, |
| 63 | + }, undefined, 2)); |
| 64 | + |
| 65 | + const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); |
| 66 | + const { options } = readJsonFile(newTree, '/foo.json'); |
| 67 | + expect(options['emitDecoratorMetadata']).toBeTrue(); |
| 68 | + }); |
| 69 | +}); |
0 commit comments