@@ -34,13 +34,13 @@ describe('ng-add schematic', () => {
3434 tree . overwrite ( '/package.json' , JSON . stringify ( packageContent , null , 2 ) ) ;
3535 }
3636
37- it ( 'should update package.json' , ( ) => {
37+ it ( 'should update package.json' , async ( ) => {
3838 // By default, the Angular workspace schematic sets up "@angular/animations". In order
3939 // to verify that we would set up the dependency properly if someone doesn't have the
4040 // animations installed already, we remove the animations dependency explicitly.
4141 removePackageJsonDependency ( appTree , '@angular/animations' ) ;
4242
43- const tree = runner . runSchematic ( 'ng-add' , { } , appTree ) ;
43+ const tree = await runner . runSchematicAsync ( 'ng-add' , { } , appTree ) . toPromise ( ) ;
4444 const packageJson = JSON . parse ( getFileContent ( tree , '/package.json' ) ) ;
4545 const dependencies = packageJson . dependencies ;
4646 const angularCoreVersion = dependencies [ '@angular/core' ] ;
@@ -59,16 +59,16 @@ describe('ng-add schematic', () => {
5959 expect ( runner . tasks . some ( task => task . name === 'run-schematic' ) ) . toBe ( true ) ;
6060 } ) ;
6161
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 ( ) ;
6464 const fileContent = getFileContent ( tree , '/projects/material/src/main.ts' ) ;
6565
6666 expect ( fileContent ) . toContain ( `import 'hammerjs';` ,
6767 'Expected the project main file to contain a HammerJS import.' ) ;
6868 } ) ;
6969
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 ( ) ;
7272
7373 const workspace = getWorkspace ( tree ) ;
7474 const project = getProjectFromWorkspace ( workspace ) ;
@@ -81,7 +81,8 @@ describe('ng-add schematic', () => {
8181 // TODO(devversion): do not re-create test app here.
8282 appTree = await createTestApp ( runner , { style : 'scss' } ) ;
8383
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 ( ) ;
8586
8687 const workspace = getWorkspace ( tree ) ;
8788 const project = getProjectFromWorkspace ( workspace ) ;
@@ -98,7 +99,8 @@ describe('ng-add schematic', () => {
9899 // TODO(devversion): do not re-create test app here.
99100 appTree = await createTestApp ( runner , { style : 'css' } ) ;
100101
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 ( ) ;
102104 const workspace = getWorkspace ( tree ) ;
103105 const project = getProjectFromWorkspace ( workspace ) ;
104106 const expectedStylesPath = normalize ( `/${ project . root } /src/custom-theme.scss` ) ;
@@ -107,8 +109,8 @@ describe('ng-add schematic', () => {
107109 expectProjectStyleFile ( project , 'projects/material/src/custom-theme.scss' ) ;
108110 } ) ;
109111
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 ( ) ;
112114 const workspace = getWorkspace ( tree ) ;
113115 const project = getProjectFromWorkspace ( workspace ) ;
114116
@@ -125,8 +127,8 @@ describe('ng-add schematic', () => {
125127 ' <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"' ) ;
126128 } ) ;
127129
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 ( ) ;
130132 const workspace = getWorkspace ( tree ) ;
131133 const project = getProjectFromWorkspace ( workspace ) ;
132134
@@ -140,16 +142,16 @@ describe('ng-add schematic', () => {
140142
141143 describe ( 'gestures disabled' , ( ) => {
142144
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 ( ) ;
145147 const packageJson = JSON . parse ( getFileContent ( tree , '/package.json' ) ) ;
146148
147149 expect ( packageJson . dependencies [ 'hammerjs' ] )
148150 . toBeUndefined ( `Expected 'hammerjs' to be not added to the package.json` ) ;
149151 } ) ;
150152
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 ( ) ;
153155 const fileContent = getFileContent ( tree , '/projects/material/src/main.ts' ) ;
154156
155157 expect ( fileContent ) . not . toContain ( `import 'hammerjs';` ,
@@ -158,15 +160,15 @@ describe('ng-add schematic', () => {
158160 } ) ;
159161
160162 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 ( ) ;
163165 const fileContent = getFileContent ( tree , '/projects/material/src/app/app.module.ts' ) ;
164166
165167 expect ( fileContent ) . toContain ( 'BrowserAnimationsModule' ,
166168 'Expected the project app module to import the "BrowserAnimationsModule".' ) ;
167169 } ) ;
168170
169- it ( 'should not add BrowserAnimationsModule if NoopAnimationsModule is set up' , ( ) => {
171+ it ( 'should not add BrowserAnimationsModule if NoopAnimationsModule is set up' , async ( ) => {
170172 const workspace = getWorkspace ( appTree ) ;
171173 const project = getProjectFromWorkspace ( workspace ) ;
172174
@@ -178,16 +180,17 @@ describe('ng-add schematic', () => {
178180 '@angular/platform-browser/animations' , project ) ;
179181
180182 spyOn ( console , 'warn' ) ;
181- runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
183+ await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) ;
182184
183185 expect ( console . warn ) . toHaveBeenCalledWith (
184186 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 " / ) ) ;
185187 } ) ;
186188 } ) ;
187189
188190 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 ( ) ;
191194 const fileContent = getFileContent ( tree , '/projects/material/src/app/app.module.ts' ) ;
192195
193196 expect ( fileContent ) . toContain ( 'NoopAnimationsModule' ,
@@ -221,18 +224,25 @@ describe('ng-add schematic', () => {
221224 tree . overwrite ( '/angular.json' , JSON . stringify ( workspace , null , 2 ) ) ;
222225 }
223226
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 ( ) => {
225228 overwriteTargetBuilder ( appTree , 'build' , 'thirdparty-builder' ) ;
226229
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 ) ;
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 / ) ;
229239 } ) ;
230240
231- it ( 'should warn if the "test" target has been changed' , ( ) => {
241+ it ( 'should warn if the "test" target has been changed' , async ( ) => {
232242 overwriteTargetBuilder ( appTree , 'test' , 'thirdparty-test-builder' ) ;
233243
234244 spyOn ( console , 'warn' ) ;
235- runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
245+ await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
236246
237247 expect ( console . warn ) . toHaveBeenCalledWith (
238248 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', () => {
260270 tree . overwrite ( '/angular.json' , JSON . stringify ( workspace , null , 2 ) ) ;
261271 }
262272
263- it ( 'should replace existing prebuilt theme files' , ( ) => {
273+ it ( 'should replace existing prebuilt theme files' , async ( ) => {
264274 const existingThemePath =
265275 './node_modules/@angular/material/prebuilt-themes/purple-green.css' ;
266276 writeStyleFileToWorkspace ( appTree , existingThemePath ) ;
267277
268- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
278+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
269279 const workspace = getWorkspace ( tree ) ;
270280 const project = getProjectFromWorkspace ( workspace ) ;
271281 const styles = getProjectTargetOptions ( project , 'build' ) . styles ;
@@ -276,11 +286,11 @@ describe('ng-add schematic', () => {
276286 'Expected the default prebuilt theme to be added.' ) ;
277287 } ) ;
278288
279- it ( 'should not replace existing custom theme files' , ( ) => {
289+ it ( 'should not replace existing custom theme files' , async ( ) => {
280290 spyOn ( console , 'warn' ) ;
281291 writeStyleFileToWorkspace ( appTree , './projects/material/custom-theme.scss' ) ;
282292
283- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
293+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
284294 const workspace = getWorkspace ( tree ) ;
285295 const project = getProjectFromWorkspace ( workspace ) ;
286296 const styles = getProjectTargetOptions ( project , 'build' ) . styles ;
@@ -291,10 +301,10 @@ describe('ng-add schematic', () => {
291301 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 / ) ) ;
292302 } ) ;
293303
294- it ( 'should not add a theme file multiple times' , ( ) => {
304+ it ( 'should not add a theme file multiple times' , async ( ) => {
295305 writeStyleFileToWorkspace ( appTree , defaultPrebuiltThemePath ) ;
296306
297- const tree = runner . runSchematic ( 'ng-add-setup-project' , { } , appTree ) ;
307+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) ;
298308 const workspace = getWorkspace ( tree ) ;
299309 const project = getProjectFromWorkspace ( workspace ) ;
300310 const styles = getProjectTargetOptions ( project , 'build' ) . styles ;
@@ -303,9 +313,10 @@ describe('ng-add schematic', () => {
303313 'Expected the "styles.css" file and default prebuilt theme to be the only styles' ) ;
304314 } ) ;
305315
306- it ( 'should not overwrite existing custom theme files' , ( ) => {
316+ it ( 'should not overwrite existing custom theme files' , async ( ) => {
307317 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 ( ) ;
309320
310321 expect ( tree . readContent ( '/projects/material/custom-theme.scss' ) ) . toBe ( 'custom-theme' ,
311322 'Expected the old custom theme content to be unchanged.' ) ;
0 commit comments