@@ -71,7 +71,7 @@ describe('ng-add schematics', () => {
7171 it ( 'should add packages to package.json dependencies' , async ( ) => {
7272 const expectedDeps = DEPENDENCIES_MAP . filter ( dep => dep . target === PackageTarget . REGULAR ) . map ( dep => dep . name ) ;
7373 const expectedDevDeps = DEPENDENCIES_MAP . filter ( dep => dep . target === PackageTarget . DEV ) . map ( dep => dep . name ) ;
74- await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
74+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
7575 const pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
7676 expect ( pkgJsonData . dependencies ) . toBeTruthy ( ) ;
7777 expect ( pkgJsonData . devDependencies ) . toBeTruthy ( ) ;
@@ -90,38 +90,60 @@ describe('ng-add schematics', () => {
9090 await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
9191 const pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
9292 expect ( pkgJsonData . dependencies [ 'fflate' ] ) . toBeTruthy ( ) ;
93+ // hammer is optional now.
94+ expect ( pkgJsonData . dependencies [ 'hammerjs' ] ) . toBeFalsy ( ) ;
95+ } ) ;
96+
97+ it ( 'should add hammerjs dependency to package.json dependencies if addHammer prompt is set.' , async ( ) => {
98+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
99+ const pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
100+ expect ( pkgJsonData . dependencies [ 'fflate' ] ) . toBeTruthy ( ) ;
93101 expect ( pkgJsonData . dependencies [ 'hammerjs' ] ) . toBeTruthy ( ) ;
94102 } ) ;
95103
96104 it ( 'should NOT add hammer.js to the main.ts file' , async ( ) => {
97- await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
105+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
98106 const mainTs = tree . read ( `${ sourceRoot } /main.ts` ) . toString ( ) ;
99107 expect ( mainTs ) . not . toContain ( 'import \'hammerjs\';' ) ;
100108 } ) ;
101109
102110 it ( 'should NOT add hammer.js to the test.ts file' , async ( ) => {
103- await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
111+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
104112 const testTs = tree . read ( `${ sourceRoot } /test.ts` ) . toString ( ) ;
105113 expect ( testTs ) . not . toContain ( 'import \'hammerjs\';' ) ;
106114 } ) ;
107115
108- it ( 'should add hammer.js in angular.json build options under scripts' , async ( ) => {
116+ // Hammer is optional now.
117+ it ( 'should not add hammer.js in angular.json build options under scripts' , async ( ) => {
109118 await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
110119 const ngJsonConfigResult = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
120+ expect ( ngJsonConfigResult . projects . testProj . architect . build . options . scripts ) . not . toContain ( './node_modules/hammerjs/hammer.min.js' ) ;
121+ } ) ;
122+
123+ it ( 'should add hammer.js in angular.json build options under scripts if addHammer prompt is set.' , async ( ) => {
124+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
125+ const ngJsonConfigResult = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
111126 expect ( ngJsonConfigResult . projects . testProj . architect . build . options . scripts ) . toContain ( './node_modules/hammerjs/hammer.min.js' ) ;
112127 } ) ;
113128
114- it ( 'should add hammer.js in angular.json test options under scripts' , async ( ) => {
129+ // Hammer is optional now.
130+ it ( 'should not add hammer.js in angular.json test options under scripts' , async ( ) => {
115131 await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
116132 const ngJsonConfigResult = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
133+ expect ( ngJsonConfigResult . projects . testProj . architect . test . options . scripts ) . not . toContain ( './node_modules/hammerjs/hammer.min.js' ) ;
134+ } ) ;
135+
136+ it ( 'should add hammer.js in angular.json test options under scripts if addHammer prompt is set.' , async ( ) => {
137+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
138+ const ngJsonConfigResult = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
117139 expect ( ngJsonConfigResult . projects . testProj . architect . test . options . scripts ) . toContain ( './node_modules/hammerjs/hammer.min.js' ) ;
118140 } ) ;
119141
120142 it ( 'should NOT duplicate hammer.js if it exists in angular.json build options' , async ( ) => {
121143 const ngJsonConfig1 = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
122144 ngJsonConfig1 . projects . testProj . architect . build . options . scripts . push ( './node_modules/hammerjs/hammer.min.js' ) ;
123145 tree . overwrite ( '/angular.json' , JSON . stringify ( ngJsonConfig1 ) ) ;
124- await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
146+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
125147
126148 const ngJsonConfigResult = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
127149 expect ( ngJsonConfigResult . projects . testProj . architect . build . options . scripts . length ) . toBe ( 1 ) ;
@@ -132,7 +154,7 @@ describe('ng-add schematics', () => {
132154 const ngJsonConfig1 = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
133155 ngJsonConfig1 . projects . testProj . architect . test . options . scripts . push ( './node_modules/hammerjs/hammer.min.js' ) ;
134156 tree . overwrite ( '/angular.json' , JSON . stringify ( ngJsonConfig1 ) ) ;
135- await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
157+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
136158
137159 const ngJsonConfigResult = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
138160 expect ( ngJsonConfigResult . projects . testProj . architect . test . options . scripts . length ) . toBe ( 1 ) ;
@@ -143,7 +165,7 @@ describe('ng-add schematics', () => {
143165 const ngJsonConfig1 = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
144166 ngJsonConfig1 . projects . testProj . architect . build . options . scripts . push ( './node_modules/hammerjs/hammer.min.js' ) ;
145167 tree . overwrite ( '/angular.json' , JSON . stringify ( ngJsonConfig1 ) ) ;
146- await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
168+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
147169
148170 const newContent = tree . read ( `${ sourceRoot } /main.ts` ) . toString ( ) ;
149171 expect ( newContent ) . toMatch ( '// test comment' ) ;
@@ -153,23 +175,30 @@ describe('ng-add schematics', () => {
153175 const ngJsonConfig1 = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
154176 ngJsonConfig1 . projects . testProj . architect . test . options . scripts . push ( './node_modules/hammerjs/hammer.min.js' ) ;
155177 tree . overwrite ( '/angular.json' , JSON . stringify ( ngJsonConfig1 ) ) ;
156- await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
178+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
157179
158180 const newContent = tree . read ( `${ sourceRoot } /test.ts` ) . toString ( ) ;
159181 expect ( newContent ) . toMatch ( '// test comment' ) ;
160182 } ) ;
161183
162- it ( 'should add hammer.js to package.json dependencies' , async ( ) => {
184+ // Hammer is optional now.
185+ it ( 'should not add hammer.js to package.json dependencies' , async ( ) => {
163186 await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
164187 const pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
188+ expect ( pkgJsonData . dependencies [ 'hammerjs' ] ) . toBeFalsy ( ) ;
189+ } ) ;
190+
191+ it ( 'should add hammer.js to package.json dependencies if addHammer prompt is set.' , async ( ) => {
192+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
193+ const pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
165194 expect ( pkgJsonData . dependencies [ 'hammerjs' ] ) . toBeTruthy ( ) ;
166195 } ) ;
167196
168197 it ( 'should NOT add hammer.js to angular.json if it exists in main.ts options' , async ( ) => {
169198 const mainTsPath = `${ sourceRoot } /main.ts` ;
170199 const content = tree . read ( mainTsPath ) . toString ( ) ;
171200 tree . overwrite ( mainTsPath , 'import \'hammerjs\';\n' + content ) ;
172- await runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
201+ await runner . runSchematic ( 'ng-add' , { normalizeCss : false , addHammer : true } , tree ) ;
173202
174203 const ngJsonConfigResult = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
175204 expect ( ngJsonConfigResult . projects . testProj . architect . build . options . scripts . length ) . toBe ( 0 ) ;
@@ -231,4 +260,3 @@ describe('ng-add schematics', () => {
231260 } ) ;
232261
233262} ) ;
234-
0 commit comments