@@ -34,13 +34,13 @@ describe('ng-add schematic', () => {
34
34
tree . overwrite ( '/package.json' , JSON . stringify ( packageContent , null , 2 ) ) ;
35
35
}
36
36
37
- it ( 'should update package.json' , ( ) => {
37
+ it ( 'should update package.json' , async ( ) => {
38
38
// By default, the Angular workspace schematic sets up "@angular/animations". In order
39
39
// to verify that we would set up the dependency properly if someone doesn't have the
40
40
// animations installed already, we remove the animations dependency explicitly.
41
41
removePackageJsonDependency ( appTree , '@angular/animations' ) ;
42
42
43
- const tree = runner . runSchematic ( 'ng-add' , { } , appTree ) ;
43
+ const tree = await runner . runSchematicAsync ( 'ng-add' , { } , appTree ) . toPromise ( ) ;
44
44
const packageJson = JSON . parse ( getFileContent ( tree , '/package.json' ) ) ;
45
45
const dependencies = packageJson . dependencies ;
46
46
const angularCoreVersion = dependencies [ '@angular/core' ] ;
@@ -59,16 +59,16 @@ describe('ng-add schematic', () => {
59
59
expect ( runner . tasks . some ( task => task . name === 'run-schematic' ) ) . toBe ( true ) ;
60
60
} ) ;
61
61
62
- it ( 'should add hammerjs import to project main file' , ( ) => {
63
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
62
+ it ( 'should add hammerjs import to project main file' , async ( ) => {
63
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
64
64
const fileContent = getFileContent ( tree , '/projects/material/src/main.ts' ) ;
65
65
66
66
expect ( fileContent ) . toContain ( `import 'hammerjs';` ,
67
67
'Expected the project main file to contain a HammerJS import.' ) ;
68
68
} ) ;
69
69
70
- it ( 'should add default theme' , ( ) => {
71
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
70
+ it ( 'should add default theme' , async ( ) => {
71
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
72
72
73
73
const workspace = getWorkspace ( tree ) ;
74
74
const project = getProjectFromWorkspace ( workspace ) ;
@@ -81,7 +81,8 @@ describe('ng-add schematic', () => {
81
81
// TODO(devversion): do not re-create test app here.
82
82
appTree = await createTestApp ( runner , { style : 'scss' } ) ;
83
83
84
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { theme : 'custom' } , appTree ) ;
84
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' ,
85
+ { theme : 'custom' } , appTree ) . toPromise ( ) ;
85
86
86
87
const workspace = getWorkspace ( tree ) ;
87
88
const project = getProjectFromWorkspace ( workspace ) ;
@@ -98,7 +99,8 @@ describe('ng-add schematic', () => {
98
99
// TODO(devversion): do not re-create test app here.
99
100
appTree = await createTestApp ( runner , { style : 'css' } ) ;
100
101
101
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { theme : 'custom' } , appTree ) ;
102
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' ,
103
+ { theme : 'custom' } , appTree ) . toPromise ( ) ;
102
104
const workspace = getWorkspace ( tree ) ;
103
105
const project = getProjectFromWorkspace ( workspace ) ;
104
106
const expectedStylesPath = normalize ( `/${ project . root } /src/custom-theme.scss` ) ;
@@ -107,8 +109,8 @@ describe('ng-add schematic', () => {
107
109
expectProjectStyleFile ( project , 'projects/material/src/custom-theme.scss' ) ;
108
110
} ) ;
109
111
110
- it ( 'should add font links' , ( ) => {
111
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
112
+ it ( 'should add font links' , async ( ) => {
113
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
112
114
const workspace = getWorkspace ( tree ) ;
113
115
const project = getProjectFromWorkspace ( workspace ) ;
114
116
@@ -125,8 +127,8 @@ describe('ng-add schematic', () => {
125
127
' <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"' ) ;
126
128
} ) ;
127
129
128
- it ( 'should add material app styles' , ( ) => {
129
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
130
+ it ( 'should add material app styles' , async ( ) => {
131
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
130
132
const workspace = getWorkspace ( tree ) ;
131
133
const project = getProjectFromWorkspace ( workspace ) ;
132
134
@@ -140,16 +142,16 @@ describe('ng-add schematic', () => {
140
142
141
143
describe ( 'gestures disabled' , ( ) => {
142
144
143
- it ( 'should not add hammerjs to package.json' , ( ) => {
144
- const tree = runner . runSchematic ( 'ng-add' , { gestures : false } , appTree ) ;
145
+ it ( 'should not add hammerjs to package.json' , async ( ) => {
146
+ const tree = await runner . runSchematicAsync ( 'ng-add' , { gestures : false } , appTree ) . toPromise ( ) ;
145
147
const packageJson = JSON . parse ( getFileContent ( tree , '/package.json' ) ) ;
146
148
147
149
expect ( packageJson . dependencies [ 'hammerjs' ] )
148
150
. toBeUndefined ( `Expected 'hammerjs' to be not added to the package.json` ) ;
149
151
} ) ;
150
152
151
- it ( 'should not add hammerjs import to project main file' , ( ) => {
152
- const tree = runner . runSchematic ( 'ng-add' , { gestures : false } , appTree ) ;
153
+ it ( 'should not add hammerjs import to project main file' , async ( ) => {
154
+ const tree = await runner . runSchematicAsync ( 'ng-add' , { gestures : false } , appTree ) . toPromise ( ) ;
153
155
const fileContent = getFileContent ( tree , '/projects/material/src/main.ts' ) ;
154
156
155
157
expect ( fileContent ) . not . toContain ( `import 'hammerjs';` ,
@@ -158,15 +160,15 @@ describe('ng-add schematic', () => {
158
160
} ) ;
159
161
160
162
describe ( 'animations enabled' , ( ) => {
161
- it ( 'should add the BrowserAnimationsModule to the project module' , ( ) => {
162
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
163
+ it ( 'should add the BrowserAnimationsModule to the project module' , async ( ) => {
164
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
163
165
const fileContent = getFileContent ( tree , '/projects/material/src/app/app.module.ts' ) ;
164
166
165
167
expect ( fileContent ) . toContain ( 'BrowserAnimationsModule' ,
166
168
'Expected the project app module to import the "BrowserAnimationsModule".' ) ;
167
169
} ) ;
168
170
169
- it ( 'should not add BrowserAnimationsModule if NoopAnimationsModule is set up' , ( ) => {
171
+ it ( 'should not add BrowserAnimationsModule if NoopAnimationsModule is set up' , async ( ) => {
170
172
const workspace = getWorkspace ( appTree ) ;
171
173
const project = getProjectFromWorkspace ( workspace ) ;
172
174
@@ -178,16 +180,17 @@ describe('ng-add schematic', () => {
178
180
'@angular/platform-browser/animations' , project ) ;
179
181
180
182
spyOn ( console , 'warn' ) ;
181
- runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
183
+ await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
182
184
183
185
expect ( console . warn ) . toHaveBeenCalledWith (
184
186
jasmine . stringMatching ( / C o u l d n o t s e t u p " B r o w s e r A n i m a t i o n s M o d u l e " / ) ) ;
185
187
} ) ;
186
188
} ) ;
187
189
188
190
describe ( 'animations disabled' , ( ) => {
189
- it ( 'should add the NoopAnimationsModule to the project module' , ( ) => {
190
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { animations : false } , appTree ) ;
191
+ it ( 'should add the NoopAnimationsModule to the project module' , async ( ) => {
192
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' ,
193
+ { animations : false } , appTree ) . toPromise ( ) ;
191
194
const fileContent = getFileContent ( tree , '/projects/material/src/app/app.module.ts' ) ;
192
195
193
196
expect ( fileContent ) . toContain ( 'NoopAnimationsModule' ,
@@ -221,18 +224,25 @@ describe('ng-add schematic', () => {
221
224
tree . overwrite ( '/angular.json' , JSON . stringify ( workspace , null , 2 ) ) ;
222
225
}
223
226
224
- it ( 'should throw an error if the "build" target has been changed' , ( ) => {
227
+ it ( 'should throw an error if the "build" target has been changed' , async ( ) => {
225
228
overwriteTargetBuilder ( appTree , 'build' , 'thirdparty-builder' ) ;
226
229
227
- expect ( ( ) => runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) )
228
- . toThrowError ( / n o t u s i n g t h e d e f a u l t b u i l d e r s .* b u i l d / ) ;
230
+ let message : string | null = null ;
231
+
232
+ try {
233
+ await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
234
+ } catch ( e ) {
235
+ message = e . message ;
236
+ }
237
+
238
+ expect ( message ) . toMatch ( / n o t u s i n g t h e d e f a u l t b u i l d e r s .* b u i l d / ) ;
229
239
} ) ;
230
240
231
- it ( 'should warn if the "test" target has been changed' , ( ) => {
241
+ it ( 'should warn if the "test" target has been changed' , async ( ) => {
232
242
overwriteTargetBuilder ( appTree , 'test' , 'thirdparty-test-builder' ) ;
233
243
234
244
spyOn ( console , 'warn' ) ;
235
- runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
245
+ await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
236
246
237
247
expect ( console . warn ) . toHaveBeenCalledWith (
238
248
jasmine . stringMatching ( / n o t u s i n g t h e d e f a u l t b u i l d e r s .* c a n n o t a d d t h e c o n f i g u r e d t h e m e / ) ) ;
@@ -260,12 +270,12 @@ describe('ng-add schematic', () => {
260
270
tree . overwrite ( '/angular.json' , JSON . stringify ( workspace , null , 2 ) ) ;
261
271
}
262
272
263
- it ( 'should replace existing prebuilt theme files' , ( ) => {
273
+ it ( 'should replace existing prebuilt theme files' , async ( ) => {
264
274
const existingThemePath =
265
275
'./node_modules/@angular/material/prebuilt-themes/purple-green.css' ;
266
276
writeStyleFileToWorkspace ( appTree , existingThemePath ) ;
267
277
268
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
278
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
269
279
const workspace = getWorkspace ( tree ) ;
270
280
const project = getProjectFromWorkspace ( workspace ) ;
271
281
const styles = getProjectTargetOptions ( project , 'build' ) . styles ;
@@ -276,11 +286,11 @@ describe('ng-add schematic', () => {
276
286
'Expected the default prebuilt theme to be added.' ) ;
277
287
} ) ;
278
288
279
- it ( 'should not replace existing custom theme files' , ( ) => {
289
+ it ( 'should not replace existing custom theme files' , async ( ) => {
280
290
spyOn ( console , 'warn' ) ;
281
291
writeStyleFileToWorkspace ( appTree , './projects/material/custom-theme.scss' ) ;
282
292
283
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
293
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
284
294
const workspace = getWorkspace ( tree ) ;
285
295
const project = getProjectFromWorkspace ( workspace ) ;
286
296
const styles = getProjectTargetOptions ( project , 'build' ) . styles ;
@@ -291,10 +301,10 @@ describe('ng-add schematic', () => {
291
301
jasmine . stringMatching ( / C o u l d n o t a d d t h e s e l e c t e d t h e m e / ) ) ;
292
302
} ) ;
293
303
294
- it ( 'should not add a theme file multiple times' , ( ) => {
304
+ it ( 'should not add a theme file multiple times' , async ( ) => {
295
305
writeStyleFileToWorkspace ( appTree , defaultPrebuiltThemePath ) ;
296
306
297
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
307
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
298
308
const workspace = getWorkspace ( tree ) ;
299
309
const project = getProjectFromWorkspace ( workspace ) ;
300
310
const styles = getProjectTargetOptions ( project , 'build' ) . styles ;
@@ -303,9 +313,10 @@ describe('ng-add schematic', () => {
303
313
'Expected the "styles.css" file and default prebuilt theme to be the only styles' ) ;
304
314
} ) ;
305
315
306
- it ( 'should not overwrite existing custom theme files' , ( ) => {
316
+ it ( 'should not overwrite existing custom theme files' , async ( ) => {
307
317
appTree . create ( '/projects/material/custom-theme.scss' , 'custom-theme' ) ;
308
- const tree = runner . runSchematic ( 'ng-add-setup-project' , { theme : 'custom' } , appTree ) ;
318
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' ,
319
+ { theme : 'custom' } , appTree ) . toPromise ( ) ;
309
320
310
321
expect ( tree . readContent ( '/projects/material/custom-theme.scss' ) ) . toBe ( 'custom-theme' ,
311
322
'Expected the old custom theme content to be unchanged.' ) ;
0 commit comments