@@ -29,7 +29,7 @@ describe('v9 HammerJS removal', () => {
29
29
} ) ;
30
30
31
31
function appendContent ( filePath : string , text : string ) {
32
- writeFile ( filePath , text + tree . readContent ( filePath ) )
32
+ writeFile ( filePath , text + tree . readContent ( filePath ) ) ;
33
33
}
34
34
35
35
function writeHammerTypes ( ) {
@@ -38,6 +38,10 @@ describe('v9 HammerJS removal', () => {
38
38
` ) ;
39
39
}
40
40
41
+ function getDependencyVersion ( name : string ) : string | undefined {
42
+ return ( JSON . parse ( tree . readContent ( '/package.json' ) ) as PackageJson ) . dependencies [ name ] ;
43
+ }
44
+
41
45
it ( 'should not throw if project tsconfig does not have explicit root file names' , async ( ) => {
42
46
// Generates a second project in the workspace. This is necessary to ensure that the
43
47
// migration runs logic to determine the correct workspace project.
@@ -60,12 +64,11 @@ describe('v9 HammerJS removal', () => {
60
64
it ( 'should remove hammerjs from "package.json" file' , async ( ) => {
61
65
addPackageToPackageJson ( tree , 'hammerjs' , '0.0.0' ) ;
62
66
63
- expect ( ( JSON . parse ( tree . readContent ( '/package.json' ) ) as PackageJson ) . dependencies [ ' hammerjs'] ) . toBe ( '0.0.0' ) ;
67
+ expect ( getDependencyVersion ( ' hammerjs') ) . toBe ( '0.0.0' ) ;
64
68
65
69
await runMigration ( ) ;
66
70
67
- expect ( ( JSON . parse ( tree . readContent ( '/package.json' ) ) as PackageJson ) . dependencies [ 'hammerjs' ] )
68
- . toBe ( undefined ) ;
71
+ expect ( getDependencyVersion ( 'hammerjs' ) ) . toBeUndefined ( ) ;
69
72
70
73
// expect that there is a "node-package" install task. The task is
71
74
// needed to update the lock file.
@@ -126,7 +129,10 @@ describe('v9 HammerJS removal', () => {
126
129
it ( 'should remove references to HammerModule' , async ( ) => {
127
130
writeFile ( '/projects/cdk-testing/src/test.module.ts' , dedent `
128
131
import {NgModule} from '@angular/core';
129
- import {HAMMER_GESTURE_CONFIG, HammerModule} from '@angular/platform-browser'; // some comment
132
+ import {
133
+ HAMMER_GESTURE_CONFIG,
134
+ HammerModule
135
+ } from '@angular/platform-browser'; // some comment
130
136
import {GestureConfig} from '@angular/material/core';
131
137
132
138
@NgModule({
@@ -161,7 +167,9 @@ describe('v9 HammerJS removal', () => {
161
167
it ( 'should remove references to gesture config if imports are aliased' , async ( ) => {
162
168
writeFile ( '/projects/cdk-testing/src/test.module.ts' , dedent `
163
169
import {NgModule} from '@angular/core';
164
- import {HAMMER_GESTURE_CONFIG as configToken} from '@angular/platform-browser'; // some comment
170
+ import {
171
+ HAMMER_GESTURE_CONFIG as configToken
172
+ } from '@angular/platform-browser'; // some comment
165
173
import {GestureConfig as gestureConfig} from '@angular/material/core';
166
174
167
175
@NgModule({
@@ -279,6 +287,7 @@ describe('v9 HammerJS removal', () => {
279
287
} ) ;
280
288
281
289
it ( 'should remove import scripts in project index files if found' , async ( ) => {
290
+ // tslint:disable:max-line-length
282
291
writeFile ( '/projects/cdk-testing/src/index.html' , dedent `
283
292
<!doctype html>
284
293
<html lang="en">
@@ -312,6 +321,7 @@ describe('v9 HammerJS removal', () => {
312
321
</body>
313
322
<script src="some-other-script.js"></script>
314
323
</html>` ) ;
324
+ // tslint:enable:max-line-length
315
325
} ) ;
316
326
} ) ;
317
327
@@ -661,6 +671,8 @@ describe('v9 HammerJS removal', () => {
661
671
662
672
expect ( tree . readContent ( '/projects/cdk-testing/src/main.ts' ) ) . toContain ( `import 'hammerjs';` ) ;
663
673
expect ( tree . exists ( '/projects/cdk-testing/src/gesture-config.ts' ) ) . toBe ( true ) ;
674
+
675
+ // tslint:disable:max-line-length
664
676
expect ( tree . readContent ( '/projects/cdk-testing/src/app/app.module.ts' ) ) . toContain ( dedent `\
665
677
import { NgModule } from '@angular/core';
666
678
import { BrowserModule, HAMMER_GESTURE_CONFIG, HammerModule } from '@angular/platform-browser';
@@ -680,6 +692,7 @@ describe('v9 HammerJS removal', () => {
680
692
bootstrap: [AppComponent]
681
693
})
682
694
export class AppModule { }` ) ;
695
+ // tslint:enable:max-line-length
683
696
} ) ;
684
697
685
698
it ( 'should add gesture config provider to app module if module is referenced through ' +
@@ -710,6 +723,8 @@ describe('v9 HammerJS removal', () => {
710
723
711
724
expect ( tree . readContent ( '/projects/cdk-testing/src/main.ts' ) ) . toContain ( `import 'hammerjs';` ) ;
712
725
expect ( tree . exists ( '/projects/cdk-testing/src/gesture-config.ts' ) ) . toBe ( true ) ;
726
+
727
+ // tslint:disable:max-line-length
713
728
expect ( tree . readContent ( '/projects/cdk-testing/src/app/app.module.ts' ) ) . toContain ( dedent `\
714
729
import { NgModule } from '@angular/core';
715
730
import { BrowserModule, HAMMER_GESTURE_CONFIG, HammerModule } from '@angular/platform-browser';
@@ -729,6 +744,7 @@ describe('v9 HammerJS removal', () => {
729
744
bootstrap: [AppComponent]
730
745
})
731
746
export class AppModule { }` ) ;
747
+ // tslint:enable:max-line-length
732
748
} ) ;
733
749
734
750
it ( 'should not add gesture config provider multiple times if already provided' , async ( ) => {
@@ -792,6 +808,7 @@ describe('v9 HammerJS removal', () => {
792
808
793
809
expect ( tree . readContent ( '/projects/cdk-testing/src/main.ts' ) ) . toContain ( `import 'hammerjs';` ) ;
794
810
expect ( tree . exists ( '/projects/cdk-testing/src/gesture-config.ts' ) ) . toBe ( true ) ;
811
+ // tslint:disable:max-line-length
795
812
expect ( tree . readContent ( '/projects/cdk-testing/src/app/app.module.ts' ) ) . toContain ( dedent `
796
813
import { HammerModule as myHammerModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
797
814
import {NgModule} from '@angular/core';
@@ -802,13 +819,14 @@ describe('v9 HammerJS removal', () => {
802
819
providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }],
803
820
})
804
821
export class AppModule {}` ) ;
822
+ // tslint:enable:max-line-length
805
823
} ) ;
806
824
} ) ;
807
825
808
826
it ( 'should not remove hammerjs if test target compilation scope does not contain hammerjs usage' ,
809
827
async ( ) => {
810
828
addPackageToPackageJson ( tree , 'hammerjs' , '0.0.0' ) ;
811
- expect ( ( JSON . parse ( tree . readContent ( '/package.json' ) ) as PackageJson ) . dependencies [ ' hammerjs'] ) . toBe ( '0.0.0' ) ;
829
+ expect ( getDependencyVersion ( ' hammerjs') ) . toBe ( '0.0.0' ) ;
812
830
813
831
// we simulate a case where a component does not have any tests for. In that case,
814
832
// the test target compilation scope does not include "test.component.ts" and the
@@ -825,14 +843,14 @@ describe('v9 HammerJS removal', () => {
825
843
826
844
await runMigration ( ) ;
827
845
828
- expect ( ( JSON . parse ( tree . readContent ( '/package.json' ) ) as PackageJson ) . dependencies [ ' hammerjs'] ) . toBe ( '0.0.0' ) ;
846
+ expect ( getDependencyVersion ( ' hammerjs') ) . toBe ( '0.0.0' ) ;
829
847
} ) ;
830
848
831
849
it ( 'should not remove hammerjs from "package.json" file if used in one project while ' +
832
850
'unused in other project' , async ( ) => {
833
851
addPackageToPackageJson ( tree , 'hammerjs' , '0.0.0' ) ;
834
852
835
- expect ( ( JSON . parse ( tree . readContent ( '/package.json' ) ) as PackageJson ) . dependencies [ ' hammerjs'] ) . toBe ( '0.0.0' ) ;
853
+ expect ( getDependencyVersion ( ' hammerjs') ) . toBe ( '0.0.0' ) ;
836
854
837
855
await runner . runExternalSchematicAsync ( '@schematics/angular' , 'application' ,
838
856
{ name : 'second-project' } , tree ) . toPromise ( ) ;
@@ -845,8 +863,7 @@ describe('v9 HammerJS removal', () => {
845
863
await runMigration ( ) ;
846
864
847
865
expect ( runner . tasks . some ( t => t . name === 'node-package' ) ) . toBe ( false ) ;
848
- expect ( ( JSON . parse ( tree . readContent ( '/package.json' ) ) as PackageJson ) . dependencies [ 'hammerjs' ] )
849
- . toBe ( '0.0.0' ) ;
866
+ expect ( getDependencyVersion ( 'hammerjs' ) ) . toBe ( '0.0.0' ) ;
850
867
} ) ;
851
868
852
869
describe ( 'with custom gesture config' , ( ) => {
0 commit comments