@@ -299,114 +299,113 @@ describe('ng-add', () => {
299
299
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
300
300
} ) ;
301
301
302
- it ( 'generates new files if starting from scratch' , async ( ) => {
303
- const result = await setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
302
+ it ( 'generates new files if starting from scratch' , ( ) => {
303
+ setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
304
304
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
305
305
projectType : PROJECT_TYPE . Static ,
306
306
project : PROJECT_NAME ,
307
307
prerender : false ,
308
- } ) as Tree ;
309
- expect ( result . read ( 'firebase.json' ) . toString ( ) ) . toEqual ( initialFirebaseJson ) ;
310
- expect ( result . read ( '.firebaserc' ) . toString ( ) ) . toEqual ( initialFirebaserc ) ;
311
- expect ( result . read ( 'angular.json' ) . toString ( ) ) . toEqual ( initialAngularJson ) ;
308
+ } ) ;
309
+ expect ( tree . read ( 'firebase.json' ) ? .toString ( ) ) . toEqual ( initialFirebaseJson ) ;
310
+ expect ( tree . read ( '.firebaserc' ) ? .toString ( ) ) . toEqual ( initialFirebaserc ) ;
311
+ expect ( tree . read ( 'angular.json' ) ? .toString ( ) ) . toEqual ( initialAngularJson ) ;
312
312
} ) ;
313
313
314
- it ( 'uses default project' , async ( ) => {
315
- const result = await setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
314
+ it ( 'uses default project' , ( ) => {
315
+ setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
316
316
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
317
317
projectType : PROJECT_TYPE . Static ,
318
318
project : undefined ,
319
319
prerender : false ,
320
- } ) as Tree ;
321
- expect ( result . read ( 'firebase.json' ) . toString ( ) ) . toEqual ( overwriteFirebaseJson ) ;
322
- expect ( result . read ( '.firebaserc' ) . toString ( ) ) . toEqual ( overwriteFirebaserc ) ;
323
- expect ( result . read ( 'angular.json' ) . toString ( ) ) . toEqual ( overwriteAngularJson ) ;
320
+ } ) ;
321
+ expect ( tree . read ( 'firebase.json' ) ? .toString ( ) ) . toEqual ( overwriteFirebaseJson ) ;
322
+ expect ( tree . read ( '.firebaserc' ) ? .toString ( ) ) . toEqual ( overwriteFirebaserc ) ;
323
+ expect ( tree . read ( 'angular.json' ) ? .toString ( ) ) . toEqual ( overwriteAngularJson ) ;
324
324
} ) ;
325
325
326
- it ( 'runs if source root is relative to workspace root' , async ( ) => {
326
+ it ( 'runs if source root is relative to workspace root' , ( ) => {
327
327
const angularJson = generateAngularJson ( ) ;
328
328
const project : { root : string , sourceRoot ?: string } = angularJson . projects [ PROJECT_NAME ] ;
329
329
project . sourceRoot = `${ project . root } /src` ;
330
330
tree . overwrite ( 'angular.json' , JSON . stringify ( angularJson ) ) ;
331
- const promise = setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
331
+ setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
332
332
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
333
333
projectType : PROJECT_TYPE . Static ,
334
334
project : undefined ,
335
335
prerender : false ,
336
336
} ) ;
337
- await expectAsync ( promise ) . toBeResolved ( ) ;
338
337
} ) ;
339
338
340
- it ( 'overrides existing files' , async ( ) => {
341
- await setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
339
+ it ( 'overrides existing files' , ( ) => {
340
+ setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
342
341
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
343
342
projectType : PROJECT_TYPE . Static ,
344
343
project : PROJECT_NAME ,
345
344
prerender : false ,
346
345
} ) ;
347
- const result = await setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
346
+ setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
348
347
firebaseProject : { projectId : OTHER_FIREBASE_PROJECT_NAME } as any ,
349
348
projectType : PROJECT_TYPE . Static ,
350
349
project : OTHER_PROJECT_NAME ,
351
350
prerender : false ,
352
- } ) as Tree ;
353
- expect ( result . read ( 'firebase.json' ) . toString ( ) ) . toEqual ( projectFirebaseJson ) ;
354
- expect ( result . read ( '.firebaserc' ) . toString ( ) ) . toEqual ( projectFirebaserc ) ;
355
- expect ( result . read ( 'angular.json' ) . toString ( ) ) . toEqual ( projectAngularJson ) ;
351
+ } ) ;
352
+ expect ( tree . read ( 'firebase.json' ) ? .toString ( ) ) . toEqual ( projectFirebaseJson ) ;
353
+ expect ( tree . read ( '.firebaserc' ) ? .toString ( ) ) . toEqual ( projectFirebaserc ) ;
354
+ expect ( tree . read ( 'angular.json' ) ? .toString ( ) ) . toEqual ( projectAngularJson ) ;
356
355
} ) ;
357
356
} ) ;
358
357
359
358
describe ( 'error handling' , ( ) => {
360
- it ( 'fails if project not defined' , async ( ) => {
359
+ it ( 'fails if project not defined' , ( ) => {
361
360
const tree = Tree . empty ( ) ;
362
361
const angularJSON = generateAngularJson ( ) ;
363
362
delete angularJSON . defaultProject ;
364
363
tree . create ( 'angular.json' , JSON . stringify ( angularJSON ) ) ;
365
364
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
366
- await expectAsync ( setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
365
+ expect ( ( ) => setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
367
366
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
368
367
projectType : PROJECT_TYPE . Static ,
369
368
project : undefined ,
370
369
prerender : false ,
371
- } ) ) . toBeRejectedWith (
370
+ } ) ) . toThrow (
372
371
new SchematicsException ( 'No Angular project selected and no default project in the workspace' )
373
372
) ;
374
373
} ) ;
375
374
376
- it ( 'Should throw if angular.json not found' , async ( ) => {
377
- await expectAsync ( setupProject ( Tree . empty ( ) , { } as any , [ FEATURES . Hosting ] , {
375
+ it ( 'Should throw if angular.json not found' , ( ) => {
376
+ expect ( ( ) => setupProject ( Tree . empty ( ) , { } as any , [ FEATURES . Hosting ] , {
378
377
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
379
378
projectType : PROJECT_TYPE . Static ,
380
379
project : PROJECT_NAME ,
381
380
prerender : false ,
382
- } ) ) . toBeRejectedWith ( new SchematicsException ( 'Could not find angular.json' ) ) ;
381
+ } ) ) . toThrow ( new SchematicsException ( 'Could not find angular.json' ) ) ;
383
382
} ) ;
384
383
385
- it ( 'Should throw if angular.json can not be parsed' , async ( ) => {
384
+ it ( 'Should throw if angular.json can not be parsed' , ( ) => {
386
385
const tree = Tree . empty ( ) ;
387
386
tree . create ( 'angular.json' , 'hi' ) ;
388
387
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
389
- await expectAsync ( setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
388
+ expect ( ( ) => setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
390
389
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
391
390
projectType : PROJECT_TYPE . Static ,
392
391
project : PROJECT_NAME ,
393
392
prerender : false ,
394
- } ) ) . toBeRejectedWith ( new SchematicsException ( 'Could not parse angular.json' ) ) ;
393
+ } ) ) . toThrow ( new SchematicsException ( 'Could not parse angular.json' ) ) ;
395
394
} ) ;
396
395
397
- it ( 'Should throw if specified project does not exist ' , async ( ) => {
396
+ it ( 'Should throw if specified project does not exist ' , ( ) => {
398
397
const tree = Tree . empty ( ) ;
399
398
tree . create ( 'angular.json' , JSON . stringify ( { projects : { } } ) ) ;
400
399
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
401
- await expectAsync ( setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
400
+ expect ( ( ) => setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
402
401
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
403
402
projectType : PROJECT_TYPE . Static ,
404
403
project : PROJECT_NAME ,
405
404
prerender : false ,
406
- } ) ) . toBeRejectedWith ( new SchematicsException ( 'The specified Angular project is not defined in this workspace' ) ) ;
405
+ } ) ) . toThrow ( new SchematicsException ( 'The specified Angular project is not defined in this workspace' ) ) ;
407
406
} ) ;
408
407
409
- it ( 'Should throw if specified project is not application' , async ( ) => {
408
+ it ( 'Should throw if specified project is not application' , ( ) => {
410
409
const tree = Tree . empty ( ) ;
411
410
tree . create (
412
411
'angular.json' ,
@@ -415,15 +414,15 @@ describe('ng-add', () => {
415
414
} )
416
415
) ;
417
416
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
418
- await expectAsync ( setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
417
+ expect ( ( ) => setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
419
418
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
420
419
projectType : PROJECT_TYPE . Static ,
421
420
project : PROJECT_NAME ,
422
421
prerender : false ,
423
- } ) ) . toBeRejectedWith ( new SchematicsException ( 'Deploy requires an Angular project type of "application" in angular.json' ) ) ;
422
+ } ) ) . toThrow ( new SchematicsException ( 'Deploy requires an Angular project type of "application" in angular.json' ) ) ;
424
423
} ) ;
425
424
426
- it ( 'Should throw if app does not have architect configured' , async ( ) => {
425
+ it ( 'Should throw if app does not have architect configured' , ( ) => {
427
426
const tree = Tree . empty ( ) ;
428
427
tree . create (
429
428
'angular.json' ,
@@ -432,12 +431,12 @@ describe('ng-add', () => {
432
431
} )
433
432
) ;
434
433
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
435
- await expectAsync ( setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
434
+ expect ( ( ) => setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
436
435
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
437
436
projectType : PROJECT_TYPE . Static ,
438
437
project : PROJECT_NAME ,
439
438
prerender : false ,
440
- } ) ) . toBeRejectedWith (
439
+ } ) ) . toThrow (
441
440
new SchematicsException ( 'Angular project "pie-ka-chu" has a malformed angular.json' )
442
441
) ;
443
442
} ) ;
@@ -474,17 +473,17 @@ describe('ng-add', () => {
474
473
).toThrowError(/firebase.json: Unexpected token/);
475
474
});*/
476
475
477
- it ( 'Should throw if .firebaserc is broken' , async ( ) => {
476
+ it ( 'Should throw if .firebaserc is broken' , ( ) => {
478
477
const tree = Tree . empty ( ) ;
479
478
tree . create ( 'angular.json' , JSON . stringify ( generateAngularJson ( ) ) ) ;
480
479
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
481
480
tree . create ( '.firebaserc' , `I'm broken 😔` ) ;
482
- await expectAsync ( setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
481
+ expect ( ( ) => setupProject ( tree , { } as any , [ FEATURES . Hosting ] , {
483
482
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
484
483
projectType : PROJECT_TYPE . Static ,
485
484
project : PROJECT_NAME ,
486
485
prerender : false ,
487
- } ) ) . toBeRejectedWith (
486
+ } ) ) . toThrow (
488
487
parseInt ( process . versions . node , 10 ) >= 20 ?
489
488
new SchematicsException ( `Error when parsing .firebaserc: Unexpected token 'I', "I'm broken 😔" is not valid JSON` ) :
490
489
new SchematicsException ( 'Error when parsing .firebaserc: Unexpected token I in JSON at position 0' )
@@ -532,37 +531,39 @@ describe('ng-add', () => {
532
531
533
532
describe ( 'universal app' , ( ) => {
534
533
535
- it ( 'should add a @angular/fire builder' , async ( ) => {
534
+ it ( 'should add a @angular/fire builder' , ( ) => {
536
535
const tree = Tree . empty ( ) ;
537
536
tree . create ( 'angular.json' , JSON . stringify ( generateAngularJsonWithServer ( ) ) ) ;
538
537
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
539
538
540
539
// TODO mock addTask
541
- const result = await setupProject ( tree , { addTask : ( ) => undefined } as any , [ FEATURES . Hosting ] , {
540
+ setupProject ( tree , { addTask : ( ) => undefined } as any , [ FEATURES . Hosting ] , {
542
541
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
543
542
projectType : PROJECT_TYPE . CloudFunctions ,
544
543
project : PROJECT_NAME ,
545
544
prerender : false ,
546
- } ) as Tree ;
545
+ } ) ;
547
546
548
- const workspace = JSON . parse ( ( result . read ( 'angular.json' ) ) . toString ( ) ) ;
549
- expect ( workspace . projects [ 'pie-ka-chu' ] . architect . deploy ) . toBeTruthy ( ) ;
547
+ const angularJSON = tree . read ( 'angular.json' ) ?. toString ( ) ;
548
+ const workspace = angularJSON && JSON . parse ( angularJSON ) ;
549
+ expect ( workspace ?. projects [ 'pie-ka-chu' ] ?. architect ?. deploy ) . toBeTruthy ( ) ;
550
550
} ) ;
551
551
552
- it ( 'should configure firebase.json' , async ( ) => {
552
+ it ( 'should configure firebase.json' , ( ) => {
553
553
const tree = Tree . empty ( ) ;
554
554
tree . create ( 'angular.json' , JSON . stringify ( generateAngularJsonWithServer ( ) ) ) ;
555
555
tree . create ( 'package.json' , JSON . stringify ( generatePackageJson ( ) ) ) ;
556
556
557
557
// TODO mock addTask
558
- const result = await setupProject ( tree , { addTask : ( ) => undefined } as any , [ FEATURES . Hosting ] , {
558
+ setupProject ( tree , { addTask : ( ) => undefined } as any , [ FEATURES . Hosting ] , {
559
559
firebaseProject : { projectId : FIREBASE_PROJECT } as any ,
560
560
projectType : PROJECT_TYPE . CloudFunctions ,
561
561
project : PROJECT_NAME ,
562
562
prerender : false ,
563
- } ) as Tree ;
563
+ } ) ;
564
564
565
- const firebaseJson = JSON . parse ( ( result . read ( 'firebase.json' ) ) . toString ( ) ) ;
565
+ const firebaseJsonData = tree . read ( 'firebase.json' ) ?. toString ( ) ;
566
+ const firebaseJson = firebaseJsonData && JSON . parse ( firebaseJsonData ) ;
566
567
expect ( firebaseJson ) . toEqual ( universalFirebaseJson ) ;
567
568
} ) ;
568
569
} ) ;
0 commit comments