|
| 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 | + |
| 11 | +describe('Migration of tslint to version 6', () => { |
| 12 | + const schematicRunner = new SchematicTestRunner( |
| 13 | + 'migrations', |
| 14 | + require.resolve('../migration-collection.json'), |
| 15 | + ); |
| 16 | + |
| 17 | + let tree: UnitTestTree; |
| 18 | + const TSLINT_PATH = '/tslint.json'; |
| 19 | + const PACKAGE_JSON_PATH = '/package.json'; |
| 20 | + |
| 21 | + const PACKAGE_JSON = { |
| 22 | + devDependencies: { |
| 23 | + tslint: '~6.1.0', |
| 24 | + }, |
| 25 | + }; |
| 26 | + |
| 27 | + beforeEach(() => { |
| 28 | + tree = new UnitTestTree(new EmptyTree()); |
| 29 | + tree.create(PACKAGE_JSON_PATH, JSON.stringify(PACKAGE_JSON, null, 2)); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should add new rules', async () => { |
| 33 | + const config = { |
| 34 | + extends: 'tslint:recommended', |
| 35 | + rules: { |
| 36 | + 'no-use-before-declare': true, |
| 37 | + 'arrow-return-shorthand': false, |
| 38 | + 'label-position': true, |
| 39 | + }, |
| 40 | + }; |
| 41 | + tree.create(TSLINT_PATH, JSON.stringify(config, null, 2)); |
| 42 | + |
| 43 | + const newTree = await schematicRunner.runSchematicAsync('tslint-add-deprecation-rule', {}, tree).toPromise(); |
| 44 | + const { rules } = JSON.parse(newTree.readContent(TSLINT_PATH)); |
| 45 | + expect(rules['deprecation'].severity).toBe('warning'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should not update already present rules', async () => { |
| 49 | + const config = { |
| 50 | + extends: 'tslint:recommended', |
| 51 | + rules: { |
| 52 | + 'no-use-before-declare': true, |
| 53 | + 'arrow-return-shorthand': false, |
| 54 | + 'label-position': true, |
| 55 | + deprecation: false, |
| 56 | + }, |
| 57 | + }; |
| 58 | + tree.create(TSLINT_PATH, JSON.stringify(config, null, 2)); |
| 59 | + |
| 60 | + const newTree = await schematicRunner.runSchematicAsync('tslint-add-deprecation-rule', {}, tree).toPromise(); |
| 61 | + const { rules } = JSON.parse(newTree.readContent(TSLINT_PATH)); |
| 62 | + expect(rules['deprecation']).toBe(false); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should not update already present rules with different severity', async () => { |
| 66 | + const config = { |
| 67 | + extends: 'tslint:recommended', |
| 68 | + rules: { |
| 69 | + 'no-use-before-declare': true, |
| 70 | + 'arrow-return-shorthand': false, |
| 71 | + 'label-position': true, |
| 72 | + deprecation: { |
| 73 | + severity: 'error', |
| 74 | + }, |
| 75 | + }, |
| 76 | + }; |
| 77 | + tree.create(TSLINT_PATH, JSON.stringify(config, null, 2)); |
| 78 | + |
| 79 | + const newTree = await schematicRunner.runSchematicAsync('tslint-add-deprecation-rule', {}, tree).toPromise(); |
| 80 | + const { rules } = JSON.parse(newTree.readContent(TSLINT_PATH)); |
| 81 | + expect(rules['deprecation'].severity).toBe('error'); |
| 82 | + }); |
| 83 | +}); |
0 commit comments