diff --git a/src/cdk/schematics/ng-update/test-cases/misc/module-resolution.spec.ts b/src/cdk/schematics/ng-update/test-cases/misc/module-resolution.spec.ts index 11f2c1f93b40..e7a9950a02e4 100644 --- a/src/cdk/schematics/ng-update/test-cases/misc/module-resolution.spec.ts +++ b/src/cdk/schematics/ng-update/test-cases/misc/module-resolution.spec.ts @@ -10,7 +10,7 @@ describe('ng update typescript program module resolution', () => { 'migration-v6', MIGRATION_PATH, []); writeFile('/node_modules/some-other-module/package.json', `{}`); - writeFile('/node_modules/some-other-module/styles.css', '') + writeFile('/node_modules/some-other-module/styles.css', ''); // We add an import to a non-existent sub-path of `some-other-module/styles`. The TypeScript // module resolution logic could try various sub-paths. This previously resulted in an error diff --git a/src/material/schematics/ng-update/test-cases/misc/class-inheritance.spec.ts b/src/material/schematics/ng-update/test-cases/misc/class-inheritance.spec.ts index 53ba4678274e..db6e90b15c69 100644 --- a/src/material/schematics/ng-update/test-cases/misc/class-inheritance.spec.ts +++ b/src/material/schematics/ng-update/test-cases/misc/class-inheritance.spec.ts @@ -10,10 +10,12 @@ describe('class inheritance misc checks', () => { const {logOutput} = await runFixers(); + // tslint:disable:max-line-length expect(logOutput).toMatch( /Found class "WithoutLabelProp".*extends "MatFormFieldControl.*must define "shouldLabelFloat"/); expect(logOutput).not.toMatch( /Found class "WithLabelProp".*extends "MatFormFieldControl".*must define "shouldLabelFloat"/); + // tslint:enable:max-line-length }); }); }); diff --git a/src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts b/src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts index af7cd5913cf9..32253aa72453 100644 --- a/src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts +++ b/src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts @@ -1,6 +1,8 @@ import {UnitTestTree} from '@angular-devkit/schematics/testing'; import {createTestCaseSetup} from '@angular/cdk/schematics/testing'; -import {migrateFileContent} from '@angular/material/schematics/ng-update/migrations/theming-api-v12/migration'; +import { + migrateFileContent +} from '@angular/material/schematics/ng-update/migrations/theming-api-v12/migration'; import {join} from 'path'; import {MIGRATION_PATH} from '../../../../paths'; diff --git a/src/material/schematics/ng-update/test-cases/v9/misc/hammer-migration-v9.spec.ts b/src/material/schematics/ng-update/test-cases/v9/misc/hammer-migration-v9.spec.ts index 9916e3a63d63..24b3ad108b5f 100644 --- a/src/material/schematics/ng-update/test-cases/v9/misc/hammer-migration-v9.spec.ts +++ b/src/material/schematics/ng-update/test-cases/v9/misc/hammer-migration-v9.spec.ts @@ -29,7 +29,7 @@ describe('v9 HammerJS removal', () => { }); function appendContent(filePath: string, text: string) { - writeFile(filePath, text + tree.readContent(filePath)) + writeFile(filePath, text + tree.readContent(filePath)); } function writeHammerTypes() { @@ -38,6 +38,10 @@ describe('v9 HammerJS removal', () => { `); } + function getDependencyVersion(name: string): string | undefined { + return (JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies[name]; + } + it('should not throw if project tsconfig does not have explicit root file names', async () => { // Generates a second project in the workspace. This is necessary to ensure that the // migration runs logic to determine the correct workspace project. @@ -60,12 +64,11 @@ describe('v9 HammerJS removal', () => { it('should remove hammerjs from "package.json" file', async () => { addPackageToPackageJson(tree, 'hammerjs', '0.0.0'); - expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']).toBe('0.0.0'); + expect(getDependencyVersion('hammerjs')).toBe('0.0.0'); await runMigration(); - expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']) - .toBe(undefined); + expect(getDependencyVersion('hammerjs')).toBeUndefined(); // expect that there is a "node-package" install task. The task is // needed to update the lock file. @@ -126,7 +129,10 @@ describe('v9 HammerJS removal', () => { it('should remove references to HammerModule', async () => { writeFile('/projects/cdk-testing/src/test.module.ts', dedent` import {NgModule} from '@angular/core'; - import {HAMMER_GESTURE_CONFIG, HammerModule} from '@angular/platform-browser'; // some comment + import { + HAMMER_GESTURE_CONFIG, + HammerModule + } from '@angular/platform-browser'; // some comment import {GestureConfig} from '@angular/material/core'; @NgModule({ @@ -161,7 +167,9 @@ describe('v9 HammerJS removal', () => { it('should remove references to gesture config if imports are aliased', async () => { writeFile('/projects/cdk-testing/src/test.module.ts', dedent` import {NgModule} from '@angular/core'; - import {HAMMER_GESTURE_CONFIG as configToken} from '@angular/platform-browser'; // some comment + import { + HAMMER_GESTURE_CONFIG as configToken + } from '@angular/platform-browser'; // some comment import {GestureConfig as gestureConfig} from '@angular/material/core'; @NgModule({ @@ -279,6 +287,7 @@ describe('v9 HammerJS removal', () => { }); it('should remove import scripts in project index files if found', async () => { + // tslint:disable:max-line-length writeFile('/projects/cdk-testing/src/index.html', dedent` @@ -312,6 +321,7 @@ describe('v9 HammerJS removal', () => { `); + // tslint:enable:max-line-length }); }); @@ -661,6 +671,8 @@ describe('v9 HammerJS removal', () => { expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain(`import 'hammerjs';`); expect(tree.exists('/projects/cdk-testing/src/gesture-config.ts')).toBe(true); + + // tslint:disable:max-line-length expect(tree.readContent('/projects/cdk-testing/src/app/app.module.ts')).toContain(dedent`\ import { NgModule } from '@angular/core'; import { BrowserModule, HAMMER_GESTURE_CONFIG, HammerModule } from '@angular/platform-browser'; @@ -680,6 +692,7 @@ describe('v9 HammerJS removal', () => { bootstrap: [AppComponent] }) export class AppModule { }`); + // tslint:enable:max-line-length }); it('should add gesture config provider to app module if module is referenced through ' + @@ -710,6 +723,8 @@ describe('v9 HammerJS removal', () => { expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain(`import 'hammerjs';`); expect(tree.exists('/projects/cdk-testing/src/gesture-config.ts')).toBe(true); + + // tslint:disable:max-line-length expect(tree.readContent('/projects/cdk-testing/src/app/app.module.ts')).toContain(dedent`\ import { NgModule } from '@angular/core'; import { BrowserModule, HAMMER_GESTURE_CONFIG, HammerModule } from '@angular/platform-browser'; @@ -729,6 +744,7 @@ describe('v9 HammerJS removal', () => { bootstrap: [AppComponent] }) export class AppModule { }`); + // tslint:enable:max-line-length }); it('should not add gesture config provider multiple times if already provided', async () => { @@ -792,6 +808,7 @@ describe('v9 HammerJS removal', () => { expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain(`import 'hammerjs';`); expect(tree.exists('/projects/cdk-testing/src/gesture-config.ts')).toBe(true); + // tslint:disable:max-line-length expect(tree.readContent('/projects/cdk-testing/src/app/app.module.ts')).toContain(dedent` import { HammerModule as myHammerModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser'; import {NgModule} from '@angular/core'; @@ -802,13 +819,14 @@ describe('v9 HammerJS removal', () => { providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }], }) export class AppModule {}`); + // tslint:enable:max-line-length }); }); it('should not remove hammerjs if test target compilation scope does not contain hammerjs usage', async () => { addPackageToPackageJson(tree, 'hammerjs', '0.0.0'); - expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']).toBe('0.0.0'); + expect(getDependencyVersion('hammerjs')).toBe('0.0.0'); // we simulate a case where a component does not have any tests for. In that case, // the test target compilation scope does not include "test.component.ts" and the @@ -825,14 +843,14 @@ describe('v9 HammerJS removal', () => { await runMigration(); - expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']).toBe('0.0.0'); + expect(getDependencyVersion('hammerjs')).toBe('0.0.0'); }); it('should not remove hammerjs from "package.json" file if used in one project while ' + 'unused in other project', async () => { addPackageToPackageJson(tree, 'hammerjs', '0.0.0'); - expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']).toBe('0.0.0'); + expect(getDependencyVersion('hammerjs')).toBe('0.0.0'); await runner.runExternalSchematicAsync('@schematics/angular', 'application', {name: 'second-project'}, tree).toPromise(); @@ -845,8 +863,7 @@ describe('v9 HammerJS removal', () => { await runMigration(); expect(runner.tasks.some(t => t.name === 'node-package')).toBe(false); - expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']) - .toBe('0.0.0'); + expect(getDependencyVersion('hammerjs')).toBe('0.0.0'); }); describe('with custom gesture config', () => { diff --git a/src/material/schematics/ng-update/test-cases/v9/misc/material-imports.spec.ts b/src/material/schematics/ng-update/test-cases/v9/misc/material-imports.spec.ts index 2007bf084765..66eb2de1b9b5 100644 --- a/src/material/schematics/ng-update/test-cases/v9/misc/material-imports.spec.ts +++ b/src/material/schematics/ng-update/test-cases/v9/misc/material-imports.spec.ts @@ -1,4 +1,8 @@ -import {createTestCaseSetup, readFileContent, resolveBazelPath} from '@angular/cdk/schematics/testing'; +import { + createTestCaseSetup, + readFileContent, + resolveBazelPath, +} from '@angular/cdk/schematics/testing'; import {MIGRATION_PATH} from '../../../../paths'; describe('v9 material imports', () => { diff --git a/tsconfig.json b/tsconfig.json index 102ca9e9d9b9..62733ffb7161 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -58,7 +58,9 @@ // Exclude schematic template files and test cases which aren't valid TS files. "src/material/schematics/ng-generate/*/files/**/*", "src/cdk/schematics/ng-generate/*/files/**/*", - "src/cdk/schematics/ng-update/test-cases/**/*", - "src/material/schematics/ng-update/test-cases/**/*" + "src/cdk/schematics/ng-update/test-cases/**/*_input.ts", + "src/cdk/schematics/ng-update/test-cases/**/*_expected_output.ts", + "src/material/schematics/ng-update/test-cases/**/*_input.ts", + "src/material/schematics/ng-update/test-cases/**/*_expected_output.ts" ] } diff --git a/tslint.json b/tslint.json index 2a854c9d1924..7a08f84bb2c0 100644 --- a/tslint.json +++ b/tslint.json @@ -224,8 +224,10 @@ // Exclude schematic template files and test cases that can't be linted. "src/material/schematics/ng-generate/*/files/**/*", "src/cdk/schematics/ng-generate/*/files/**/*", - "src/cdk/schematics/ng-update/test-cases/**/*", - "src/material/schematics/ng-update/test-cases/**/*" + "src/cdk/schematics/ng-update/test-cases/**/*_input.ts", + "src/cdk/schematics/ng-update/test-cases/**/*_expected_output.ts", + "src/material/schematics/ng-update/test-cases/**/*_input.ts", + "src/material/schematics/ng-update/test-cases/**/*_expected_output.ts" ] } }