@@ -42,26 +42,45 @@ describe("projectData", () => {
42
42
return testInjector ;
43
43
} ;
44
44
45
+ const prepareTest = ( opts ?: { packageJsonData ?: { dependencies ?: IStringDictionary , devDependencies : IStringDictionary } , nsconfigData ?: { shared : boolean } } ) : IProjectData => {
46
+ const testInjector = createTestInjector ( ) ;
47
+ const fs = testInjector . resolve ( "fs" ) ;
48
+ fs . exists = ( filePath : string ) => filePath && ( path . basename ( filePath ) === "package.json" || ( path . basename ( filePath ) === "nsconfig.json" && opts && opts . nsconfigData ) ) ;
49
+
50
+ fs . readText = ( filePath : string ) => {
51
+ if ( path . basename ( filePath ) === "package.json" ) {
52
+ return JSON . stringify ( {
53
+ nativescript : {
54
+ id : "com.test.testid"
55
+ } ,
56
+ dependencies : opts && opts . packageJsonData && opts . packageJsonData . dependencies ,
57
+ devDependencies : opts && opts . packageJsonData && opts . packageJsonData . devDependencies
58
+ } ) ;
59
+ } else if ( path . basename ( filePath ) === "nsconfig.json" && opts && opts . nsconfigData ) {
60
+ return JSON . stringify ( opts . nsconfigData ) ;
61
+ }
62
+
63
+ return null ;
64
+ } ;
65
+
66
+ const projectHelper : IProjectHelper = testInjector . resolve ( "projectHelper" ) ;
67
+ projectHelper . projectDir = "projectDir" ;
68
+
69
+ const projectData : IProjectData = testInjector . resolve ( "projectData" ) ;
70
+ projectData . initializeProjectData ( ) ;
71
+
72
+ return projectData ;
73
+ } ;
74
+
45
75
describe ( "projectType" , ( ) => {
46
76
47
77
const assertProjectType = ( dependencies : any , devDependencies : any , expectedProjecType : string ) => {
48
- const testInjector = createTestInjector ( ) ;
49
- const fs = testInjector . resolve ( "fs" ) ;
50
- fs . exists = ( filePath : string ) => filePath && path . basename ( filePath ) === "package.json" ;
51
-
52
- fs . readText = ( ) => ( JSON . stringify ( {
53
- nativescript : {
54
- id : "com.test.testid"
55
- } ,
56
- dependencies : dependencies ,
57
- devDependencies : devDependencies
58
- } ) ) ;
59
-
60
- const projectHelper : IProjectHelper = testInjector . resolve ( "projectHelper" ) ;
61
- projectHelper . projectDir = "projectDir" ;
62
-
63
- const projectData : IProjectData = testInjector . resolve ( "projectData" ) ;
64
- projectData . initializeProjectData ( ) ;
78
+ const projectData = prepareTest ( {
79
+ packageJsonData : {
80
+ dependencies,
81
+ devDependencies
82
+ }
83
+ } ) ;
65
84
assert . deepEqual ( projectData . projectType , expectedProjecType ) ;
66
85
} ;
67
86
@@ -93,4 +112,26 @@ describe("projectData", () => {
93
112
assertProjectType ( null , null , "Pure JavaScript" ) ;
94
113
} ) ;
95
114
} ) ;
115
+
116
+ describe ( "isShared" , ( ) => {
117
+ it ( "is false when nsconfig.json does not exist" , ( ) => {
118
+ const projectData = prepareTest ( ) ;
119
+ assert . isFalse ( projectData . isShared ) ;
120
+ } ) ;
121
+
122
+ it ( "is false when nsconfig.json exists, but shared value is not populated" , ( ) => {
123
+ const projectData = prepareTest ( { nsconfigData : { shared : undefined } } ) ;
124
+ assert . isFalse ( projectData . isShared ) ;
125
+ } ) ;
126
+
127
+ it ( "is false when nsconfig.json exists and shared value is false" , ( ) => {
128
+ const projectData = prepareTest ( { nsconfigData : { shared : false } } ) ;
129
+ assert . isFalse ( projectData . isShared ) ;
130
+ } ) ;
131
+
132
+ it ( "is true when nsconfig.json exists and shared value is true" , ( ) => {
133
+ const projectData = prepareTest ( { nsconfigData : { shared : true } } ) ;
134
+ assert . isTrue ( projectData . isShared ) ;
135
+ } ) ;
136
+ } ) ;
96
137
} ) ;
0 commit comments