@@ -9,17 +9,19 @@ describe('ng-add schematics', () => {
9
9
const collectionPath = path . join ( __dirname , '../collection.json' ) ;
10
10
const runner : SchematicTestRunner = new SchematicTestRunner ( 'cli-schematics' , collectionPath ) ;
11
11
let tree : UnitTestTree ;
12
+ const sourceRoot = 'testSrc' ;
12
13
const ngJsonConfig = {
13
14
defaultProject : 'testProj' ,
14
15
projects : {
15
16
testProj : {
16
- sourceRoot : 'src' ,
17
+ sourceRoot : sourceRoot ,
17
18
projectType : ProjectType . Application ,
18
19
architect : {
19
20
serve : { } ,
20
21
build : {
21
22
options : {
22
- main : 'src/main.ts' ,
23
+ main : `${ sourceRoot } /main.ts` ,
24
+ polyfills : `${ sourceRoot } /polyfills.ts` ,
23
25
scripts : [ ]
24
26
}
25
27
}
@@ -42,7 +44,7 @@ describe('ng-add schematics', () => {
42
44
tree = new UnitTestTree ( new EmptyTree ( ) ) ;
43
45
tree . create ( '/angular.json' , JSON . stringify ( ngJsonConfig ) ) ;
44
46
tree . create ( '/package.json' , JSON . stringify ( pkgJsonConfig ) ) ;
45
- tree . create ( 'src /main.ts' , '// test comment' ) ;
47
+ tree . create ( ` ${ sourceRoot } /main.ts` , '// test comment' ) ;
46
48
} ) ;
47
49
48
50
it ( 'should create the needed files correctly' , ( ) => {
@@ -71,7 +73,7 @@ describe('ng-add schematics', () => {
71
73
72
74
it ( 'should add hammer.js to the main.ts file' , ( ) => {
73
75
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 ( ) ;
75
77
expect ( mainTs ) . toContain ( 'import \'hammerjs\';' ) ;
76
78
} ) ;
77
79
@@ -82,12 +84,12 @@ describe('ng-add schematics', () => {
82
84
tree . overwrite ( 'angular.json' , JSON . stringify ( workspace ) ) ;
83
85
runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
84
86
85
- const newContent = tree . read ( 'src /main.ts' ) . toString ( ) ;
87
+ const newContent = tree . read ( ` ${ sourceRoot } /main.ts` ) . toString ( ) ;
86
88
expect ( newContent . split ( 'import \'hammerjs\';\n// test comment' ) . length ) . toEqual ( 1 ) ;
87
89
} ) ;
88
90
89
91
it ( 'should not add hammer.js if it exists in main.ts' , ( ) => {
90
- const mainTsPath = 'src /main.ts' ;
92
+ const mainTsPath = ` ${ sourceRoot } /main.ts` ;
91
93
const content = tree . read ( mainTsPath ) . toString ( ) ;
92
94
tree . overwrite ( mainTsPath , 'import \'hammerjs\';\n' + content ) ;
93
95
runner . runSchematic ( 'ng-add' , { normalizeCss : false } , tree ) ;
@@ -138,54 +140,54 @@ import 'core-js/es6/set';
138
140
import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
139
141
` ;
140
142
141
- tree . create ( 'src /polyfills.ts' , polyfills ) ;
143
+ tree . create ( ` ${ sourceRoot } /polyfills.ts` , polyfills ) ;
142
144
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' ) ) ;
144
146
} ) ;
145
147
146
148
it ( 'should properly add css reset' , ( ) => {
147
- tree . create ( 'src /styles.scss' , '' ) ;
149
+ tree . create ( ` ${ sourceRoot } /styles.scss` , '' ) ;
148
150
runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
149
151
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 ) ;
151
153
expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
152
154
resetJsonConfigs ( tree ) ;
153
- tree . delete ( 'src /styles.scss' ) ;
155
+ tree . delete ( ` ${ sourceRoot } /styles.scss` ) ;
154
156
155
- tree . create ( 'src /styles.sass' , '' ) ;
157
+ tree . create ( ` ${ sourceRoot } /styles.sass` , '' ) ;
156
158
runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
157
159
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 ) ;
159
161
expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
160
162
resetJsonConfigs ( tree ) ;
161
- tree . delete ( 'src /styles.sass' ) ;
163
+ tree . delete ( ` ${ sourceRoot } /styles.sass` ) ;
162
164
163
- tree . create ( 'src /styles.css' , '' ) ;
165
+ tree . create ( ` ${ sourceRoot } /styles.css` , '' ) ;
164
166
runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
165
167
pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
166
- expect ( tree . readContent ( 'src /styles.css' ) ) . toBe ( '' ) ;
168
+ expect ( tree . readContent ( ` ${ sourceRoot } /styles.css` ) ) . toBe ( '' ) ;
167
169
expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
168
170
expect ( JSON . parse ( tree . readContent ( '/angular.json' ) ) . projects [ 'testProj' ] . architect . build . options . styles ) . toContain ( cssImport ) ;
169
171
resetJsonConfigs ( tree ) ;
170
- tree . delete ( 'src /styles.css' ) ;
172
+ tree . delete ( ` ${ sourceRoot } /styles.css` ) ;
171
173
172
- tree . create ( 'src /styles.less' , '' ) ;
174
+ tree . create ( ` ${ sourceRoot } /styles.less` , '' ) ;
173
175
runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
174
176
pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
175
- expect ( tree . readContent ( 'src /styles.less' ) ) . toBe ( '' ) ;
177
+ expect ( tree . readContent ( ` ${ sourceRoot } /styles.less` ) ) . toBe ( '' ) ;
176
178
expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
177
179
expect ( JSON . parse ( tree . readContent ( '/angular.json' ) ) . projects [ 'testProj' ] . architect . build . options . styles ) . toContain ( cssImport ) ;
178
180
resetJsonConfigs ( tree ) ;
179
- tree . delete ( 'src /styles.less' ) ;
181
+ tree . delete ( ` ${ sourceRoot } /styles.less` ) ;
180
182
181
- tree . create ( 'src /styles.styl' , '' ) ;
183
+ tree . create ( ` ${ sourceRoot } /styles.styl` , '' ) ;
182
184
runner . runSchematic ( 'ng-add' , { normalizeCss : true } , tree ) ;
183
185
pkgJsonData = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
184
- expect ( tree . readContent ( 'src /styles.styl' ) ) . toBe ( '' ) ;
186
+ expect ( tree . readContent ( ` ${ sourceRoot } /styles.styl` ) ) . toBe ( '' ) ;
185
187
expect ( pkgJsonData . dependencies [ 'minireset.css' ] ) . toBeTruthy ( ) ;
186
188
expect ( JSON . parse ( tree . readContent ( '/angular.json' ) ) . projects [ 'testProj' ] . architect . build . options . styles ) . toContain ( cssImport ) ;
187
189
resetJsonConfigs ( tree ) ;
188
- tree . delete ( 'src /styles.styl' ) ;
190
+ tree . delete ( ` ${ sourceRoot } /styles.styl` ) ;
189
191
} ) ;
190
192
191
193
it ( 'should properly add web animations' , ( ) => {
@@ -202,7 +204,7 @@ import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
202
204
* that is built with AngularCLI v7.3 or above. All else are considered below v7.3.
203
205
*/
204
206
it ( 'should enable es5BrowserSupport on projects with ng cli version >= 7.3' , ( ) => {
205
- tree . create ( 'src /polyfills.ts' , '' ) ;
207
+ tree . create ( ` ${ sourceRoot } /polyfills.ts` , '' ) ;
206
208
const newJson : any = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
207
209
newJson . projects [ 'testProj' ] . architect . build . options [ 'es5BrowserSupport' ] = false ;
208
210
tree . overwrite ( '/angular.json' , JSON . stringify ( newJson ) ) ;
@@ -226,11 +228,11 @@ import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
226
228
import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
227
229
` ;
228
230
229
- tree . create ( 'src /polyfills.ts' , polyfills ) ;
231
+ tree . create ( ` ${ sourceRoot } /polyfills.ts` , polyfills ) ;
230
232
const newJson : any = JSON . parse ( tree . read ( '/angular.json' ) . toString ( ) ) ;
231
233
newJson . projects [ 'testProj' ] . architect . build . options [ 'es5BrowserSupport' ] = false ;
232
234
tree . overwrite ( '/angular.json' , JSON . stringify ( newJson ) ) ;
233
235
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' ) ) ;
235
237
} ) ;
236
238
} ) ;
0 commit comments