11
2- import { readJson , readProjectConfiguration , readWorkspaceConfiguration , Tree } from '@nrwl/devkit' ;
2+ import { readJson , readProjectConfiguration , Tree } from '@nrwl/devkit' ;
33import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing' ;
44import { applicationGenerator } from './application' ;
55import { angularVersion , nsAngularVersion , rxjsVersion , zonejsVersion } from '../../utils/versions' ;
66
77describe ( 'app' , ( ) => {
8- let appTree : Tree ;
8+ let tree : Tree ;
99
1010 beforeEach ( ( ) => {
11- appTree = createTreeWithEmptyWorkspace ( ) ;
11+ tree = createTreeWithEmptyWorkspace ( { layout : 'apps-libs' } ) ;
12+ tree . write ( '/apps/.gitignore' , '' ) ;
13+ tree . write ( '/libs/.gitignore' , '' ) ;
1214 } ) ;
1315
14- it ( 'should update workspace .json' , async ( ) => {
15- await applicationGenerator ( appTree , { name : 'myApp' } ) ;
16- const config = readProjectConfiguration ( appTree , 'nativescript-my-app' ) ;
16+ it ( 'should update project .json' , async ( ) => {
17+ await applicationGenerator ( tree , { name : 'myApp' } ) ;
18+ const config = readProjectConfiguration ( tree , 'nativescript-my-app' ) ;
1719
1820 expect ( config . root ) . toEqual ( 'apps/nativescript-my-app' ) ;
1921 } ) ;
2022
2123 it ( 'should generate files' , async ( ) => {
22- await applicationGenerator ( appTree , { name : 'myApp' , framework : 'vanilla' } ) ;
24+ await applicationGenerator ( tree , { name : 'myApp' , framework : 'vanilla' } ) ;
2325 const appPath = 'apps/nativescript-my-app' ;
24- expect ( appTree . exists ( `${ appPath } /src/app-root.xml` ) ) . toBeTruthy ( ) ;
25- expect ( appTree . exists ( `${ appPath } /src/main-page.ts` ) ) . toBeTruthy ( ) ;
26- checkFiles ( appTree , appPath ) ;
26+ expect ( tree . exists ( `${ appPath } /src/app-root.xml` ) ) . toBeTruthy ( ) ;
27+ expect ( tree . exists ( `${ appPath } /src/main-page.ts` ) ) . toBeTruthy ( ) ;
28+ checkFiles ( tree , appPath ) ;
2729 } ) ;
2830
2931 it ( 'nested in directory: should generate files' , async ( ) => {
30- await applicationGenerator ( appTree , { name : 'myApp' , directory : 'mobile' , framework : 'vanilla' } ) ;
32+ await applicationGenerator ( tree , { name : 'myApp' , directory : 'mobile' , framework : 'vanilla' } ) ;
3133 const appPath = 'apps/mobile/nativescript-my-app' ;
32- expect ( appTree . exists ( `${ appPath } /src/app-root.xml` ) ) . toBeTruthy ( ) ;
33- expect ( appTree . exists ( `${ appPath } /src/main-page.ts` ) ) . toBeTruthy ( ) ;
34+ expect ( tree . exists ( `${ appPath } /src/app-root.xml` ) ) . toBeTruthy ( ) ;
35+ expect ( tree . exists ( `${ appPath } /src/main-page.ts` ) ) . toBeTruthy ( ) ;
3436
35- checkFiles ( appTree , appPath , '../../../' ) ;
37+ checkFiles ( tree , appPath , '../../../' ) ;
3638 } ) ;
3739
3840 it ( 'Angular with Routing: should generate files' , async ( ) => {
39- await applicationGenerator ( appTree , { name : 'myApp' , framework : 'angular' , routing : true } ) ;
41+ await applicationGenerator ( tree , { name : 'myApp' , framework : 'angular' , routing : true } ) ;
4042 const appPath = 'apps/nativescript-my-app' ;
41- checkAngularFiles ( appTree , appPath ) ;
43+ checkAngularFiles ( tree , appPath ) ;
4244
43- expect ( appTree . exists ( `${ appPath } /src/app.routing.ts` ) ) . toBeTruthy ( ) ;
44- expect ( appTree . exists ( `${ appPath } /src/features/home/home.module.ts` ) ) . toBeTruthy ( ) ;
45+ expect ( tree . exists ( `${ appPath } /src/app.routing.ts` ) ) . toBeTruthy ( ) ;
46+ expect ( tree . exists ( `${ appPath } /src/features/home/home.module.ts` ) ) . toBeTruthy ( ) ;
4547
4648 // should also save framework as default in plugin settings
47- const packageJson = readJson ( appTree , `package.json` ) ;
49+ const packageJson = readJson ( tree , `package.json` ) ;
4850 expect ( packageJson [ 'nativescript-nx' ] . framework ) . toEqual ( 'angular' ) ;
4951
50- checkFiles ( appTree , appPath ) ;
52+ checkFiles ( tree , appPath ) ;
5153 } ) ;
5254
5355 it ( 'Angular without Routing: should generate files' , async ( ) => {
54- await applicationGenerator ( appTree , { name : 'myApp' , framework : 'angular' , routing : false } ) ;
56+ await applicationGenerator ( tree , { name : 'myApp' , framework : 'angular' , routing : false } ) ;
5557 const appPath = 'apps/nativescript-my-app' ;
56- checkAngularFiles ( appTree , appPath ) ;
58+ checkAngularFiles ( tree , appPath ) ;
5759
58- expect ( appTree . exists ( `${ appPath } /src/app.routing.ts` ) ) . toBeFalsy ( ) ;
59- expect ( appTree . exists ( `${ appPath } /src/features/home/home.module.ts` ) ) . toBeFalsy ( ) ;
60+ expect ( tree . exists ( `${ appPath } /src/app.routing.ts` ) ) . toBeFalsy ( ) ;
61+ expect ( tree . exists ( `${ appPath } /src/features/home/home.module.ts` ) ) . toBeFalsy ( ) ;
6062
61- checkFiles ( appTree , appPath ) ;
63+ checkFiles ( tree , appPath ) ;
6264 } ) ;
6365
6466 it ( 'Angular nested in directory: should generate files' , async ( ) => {
65- await applicationGenerator ( appTree , { name : 'myApp' , framework : 'angular' , directory : 'mobile' , routing : true } ) ;
67+ await applicationGenerator ( tree , { name : 'myApp' , framework : 'angular' , directory : 'mobile' , routing : true } ) ;
6668 const appPath = 'apps/mobile/nativescript-my-app' ;
67- checkAngularFiles ( appTree , appPath ) ;
69+ checkAngularFiles ( tree , appPath ) ;
6870
69- expect ( appTree . exists ( `${ appPath } /src/app.routing.ts` ) ) . toBeTruthy ( ) ;
70- expect ( appTree . exists ( `${ appPath } /src/features/home/home.module.ts` ) ) . toBeTruthy ( ) ;
71+ expect ( tree . exists ( `${ appPath } /src/app.routing.ts` ) ) . toBeTruthy ( ) ;
72+ expect ( tree . exists ( `${ appPath } /src/features/home/home.module.ts` ) ) . toBeTruthy ( ) ;
7173
72- checkFiles ( appTree , appPath , '../../../' ) ;
74+ checkFiles ( tree , appPath , '../../../' ) ;
7375 } ) ;
7476
7577 it ( 'should add angular dependencies when framework is angular' , async ( ) => {
76- await applicationGenerator ( appTree , { name : 'myApp' , framework : 'angular' } ) ;
77- const packageJson = readJson ( appTree , `package.json` ) ;
78+ await applicationGenerator ( tree , { name : 'myApp' , framework : 'angular' } ) ;
79+ const packageJson = readJson ( tree , `package.json` ) ;
7880
7981 expect ( packageJson [ 'dependencies' ] [ '@angular/animations' ] ) . toEqual ( angularVersion ) ;
8082 expect ( packageJson [ 'dependencies' ] [ '@angular/common' ] ) . toEqual ( angularVersion ) ;
@@ -90,8 +92,8 @@ describe('app', () => {
9092 } ) ;
9193
9294 it ( 'should not add angular dependencies when framework is not angular' , async ( ) => {
93- await applicationGenerator ( appTree , { name : 'myApp' , framework : '' } ) ;
94- const packageJson = readJson ( appTree , `package.json` ) ;
95+ await applicationGenerator ( tree , { name : 'myApp' , framework : '' } ) ;
96+ const packageJson = readJson ( tree , `package.json` ) ;
9597
9698 expect ( packageJson [ 'dependencies' ] [ '@angular/animations' ] ) . toBeFalsy ( ) ;
9799 expect ( packageJson [ 'dependencies' ] [ '@angular/common' ] ) . toBeFalsy ( ) ;
0 commit comments