@@ -9,17 +9,19 @@ describe('ng-add schematics', () => {
99 const collectionPath = path . join ( __dirname , '../collection.json' ) ;
1010 const runner : SchematicTestRunner = new SchematicTestRunner ( 'cli-schematics' , collectionPath ) ;
1111 let tree : UnitTestTree ;
12+ const sourceRoot = 'testSrc' ;
1213 const ngJsonConfig = {
1314 defaultProject : 'testProj' ,
1415 projects : {
1516 testProj : {
16- sourceRoot : 'src' ,
17+ sourceRoot : sourceRoot ,
1718 projectType : ProjectType . Application ,
1819 architect : {
1920 serve : { } ,
2021 build : {
2122 options : {
22- main : 'src/main.ts' ,
23+ main : `${ sourceRoot } /main.ts` ,
24+ polyfills : `${ sourceRoot } /polyfills.ts` ,
2325 scripts : [ ]
2426 }
2527 }
@@ -42,7 +44,7 @@ describe('ng-add schematics', () => {
4244 tree = new UnitTestTree ( new EmptyTree ( ) ) ;
4345 tree . create ( '/angular.json' , JSON . stringify ( ngJsonConfig ) ) ;
4446 tree . create ( '/package.json' , JSON . stringify ( pkgJsonConfig ) ) ;
45- tree . create ( 'src /main.ts' , '// test comment' ) ;
47+ tree . create ( ` ${ sourceRoot } /main.ts` , '// test comment' ) ;
4648 } ) ;
4749
4850 it ( 'should create the needed files correctly' , ( ) => {
@@ -71,7 +73,7 @@ describe('ng-add schematics', () => {
7173
7274 it ( 'should add hammer.js to the main.ts file' , ( ) => {
7375 runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
74- const mainTs = tree . read ( 'src /main.ts' ) . toString ( ) ;
76+ const mainTs = tree . read ( ` ${ sourceRoot } /main.ts` ) . toString ( ) ;
7577 expect ( mainTs ) . toContain ( 'import \'hammerjs\';' ) ;
7678 } ) ;
7779
@@ -82,12 +84,12 @@ describe('ng-add schematics', () => {
8284 tree . overwrite ( 'angular.json' , JSON . stringify ( workspace ) ) ;
8385 runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
8486
85- const newContent = tree . read ( 'src /main.ts' ) . toString ( ) ;
87+ const newContent = tree . read ( ` ${ sourceRoot } /main.ts` ) . toString ( ) ;
8688 expect ( newContent . split ( 'import \'hammerjs\';\n// test comment' ) . length ) . toEqual ( 1 ) ;
8789 } ) ;
8890
8991 it ( 'should not add hammer.js if it exists in main.ts' , ( ) => {
90- const mainTsPath = 'src /main.ts' ;
92+ const mainTsPath = ` ${ sourceRoot } /main.ts` ;
9193 const content = tree . read ( mainTsPath ) . toString ( ) ;
9294 tree . overwrite ( mainTsPath , 'import \'hammerjs\';\n' + content ) ;
9395 runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
@@ -138,54 +140,54 @@ import 'core-js/es6/set';
138140import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
139141` ;
140142
141- tree . create ( 'src /polyfills.ts' , polyfills ) ;
143+ tree . create ( ` ${ sourceRoot } /polyfills.ts` , polyfills ) ;
142144 runner . runSchematic ( 'ng-add' , { polyfills : true , normalizeCss : false } , tree ) ;
143- expect ( tree . readContent ( 'src /polyfills.ts' ) . replace ( / \r \n / g, '\n' ) ) . toEqual ( result . replace ( / \r \n / g, '\n' ) ) ;
145+ expect ( tree . readContent ( ` ${ sourceRoot } /polyfills.ts` ) . replace ( / \r \n / g, '\n' ) ) . toEqual ( result . replace ( / \r \n / g, '\n' ) ) ;
144146 } ) ;
145147
146148 it ( 'should properly add css reset' , ( ) => {
147- tree . create ( 'src /styles.scss' , '' ) ;
149+ tree . create ( ` ${ sourceRoot } /styles.scss` , '' ) ;
148150 runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
149151 let pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
150- expect ( tree . readContent ( 'src /styles.scss' ) ) . toEqual ( scssImport ) ;
152+ expect ( tree . readContent ( ` ${ sourceRoot } /styles.scss` ) ) . toEqual ( scssImport ) ;
151153 expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
152154 resetJsonConfigs ( tree ) ;
153- tree . delete ( 'src /styles.scss' ) ;
155+ tree . delete ( ` ${ sourceRoot } /styles.scss` ) ;
154156
155- tree . create ( 'src /styles.sass' , '' ) ;
157+ tree . create ( ` ${ sourceRoot } /styles.sass` , '' ) ;
156158 runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
157159 pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
158- expect ( tree . readContent ( 'src /styles.sass' ) ) . toEqual ( scssImport ) ;
160+ expect ( tree . readContent ( ` ${ sourceRoot } /styles.sass` ) ) . toEqual ( scssImport ) ;
159161 expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
160162 resetJsonConfigs ( tree ) ;
161- tree . delete ( 'src /styles.sass' ) ;
163+ tree . delete ( ` ${ sourceRoot } /styles.sass` ) ;
162164
163- tree . create ( 'src /styles.css' , '' ) ;
165+ tree . create ( ` ${ sourceRoot } /styles.css` , '' ) ;
164166 runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
165167 pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
166- expect ( tree . readContent ( 'src /styles.css' ) ) . toBe ( '' ) ;
168+ expect ( tree . readContent ( ` ${ sourceRoot } /styles.css` ) ) . toBe ( '' ) ;
167169 expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
168170 expect ( JSON . parse ( tree . readContent ( '/angular.json' ) ) . projects [ 'testProj' ] . architect . build . options . styles ) . toContain ( cssImport ) ;
169171 resetJsonConfigs ( tree ) ;
170- tree . delete ( 'src /styles.css' ) ;
172+ tree . delete ( ` ${ sourceRoot } /styles.css` ) ;
171173
172- tree . create ( 'src /styles.less' , '' ) ;
174+ tree . create ( ` ${ sourceRoot } /styles.less` , '' ) ;
173175 runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
174176 pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
175- expect ( tree . readContent ( 'src /styles.less' ) ) . toBe ( '' ) ;
177+ expect ( tree . readContent ( ` ${ sourceRoot } /styles.less` ) ) . toBe ( '' ) ;
176178 expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
177179 expect ( JSON . parse ( tree . readContent ( '/angular.json' ) ) . projects [ 'testProj' ] . architect . build . options . styles ) . toContain ( cssImport ) ;
178180 resetJsonConfigs ( tree ) ;
179- tree . delete ( 'src /styles.less' ) ;
181+ tree . delete ( ` ${ sourceRoot } /styles.less` ) ;
180182
181- tree . create ( 'src /styles.styl' , '' ) ;
183+ tree . create ( ` ${ sourceRoot } /styles.styl` , '' ) ;
182184 runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
183185 pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
184- expect ( tree . readContent ( 'src /styles.styl' ) ) . toBe ( '' ) ;
186+ expect ( tree . readContent ( ` ${ sourceRoot } /styles.styl` ) ) . toBe ( '' ) ;
185187 expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
186188 expect ( JSON . parse ( tree . readContent ( '/angular.json' ) ) . projects [ 'testProj' ] . architect . build . options . styles ) . toContain ( cssImport ) ;
187189 resetJsonConfigs ( tree ) ;
188- tree . delete ( 'src /styles.styl' ) ;
190+ tree . delete ( ` ${ sourceRoot } /styles.styl` ) ;
189191 } ) ;
190192
191193 it ( 'should properly add web animations' , ( ) => {
@@ -202,7 +204,7 @@ import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
202204 * that is built with AngularCLI v7.3 or above. All else are considered below v7.3.
203205 */
204206 it ( 'should enable es5BrowserSupport on projects with ng cli version >= 7.3' , ( ) => {
205- tree . create ( 'src /polyfills.ts' , '' ) ;
207+ tree . create ( ` ${ sourceRoot } /polyfills.ts` , '' ) ;
206208 const newJson : any = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
207209 newJson . projects [ 'testProj' ] . architect . build . options [ 'es5BrowserSupport' ] = false ;
208210 tree . overwrite ( '/angular.json' , JSON . stringify ( newJson ) ) ;
@@ -226,11 +228,11 @@ import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
226228import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
227229 ` ;
228230
229- tree . create ( 'src /polyfills.ts' , polyfills ) ;
231+ tree . create ( ` ${ sourceRoot } /polyfills.ts` , polyfills ) ;
230232 const newJson : any = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
231233 newJson . projects [ 'testProj' ] . architect . build . options [ 'es5BrowserSupport' ] = false ;
232234 tree . overwrite ( '/angular.json' , JSON . stringify ( newJson ) ) ;
233235 runner . runSchematic ( 'ng-add' , { polyfills : true } , tree ) ;
234- expect ( tree . readContent ( 'src /polyfills.ts' ) . replace ( / \r \n / g, '\n' ) ) . toEqual ( result . replace ( / \r \n / g, '\n' ) ) ;
236+ expect ( tree . readContent ( ` ${ sourceRoot } /polyfills.ts` ) . replace ( / \r \n / g, '\n' ) ) . toEqual ( result . replace ( / \r \n / g, '\n' ) ) ;
235237 } ) ;
236238} ) ;
0 commit comments