@@ -6,7 +6,8 @@ import { ChildProcess } from "../lib/wrappers/child-process";
6
6
7
7
const JavaHomeName = "JAVA_HOME" ;
8
8
const AndroidHomeName = "ANDROID_HOME" ;
9
- const helpers = new Helpers ( ) ;
9
+ const PROGRAM_FILES = "ProgramFiles" ;
10
+ const PROGRAM_FILES_ENV_PATH = "C:\\Program Files" ;
10
11
11
12
interface IChildProcessResultDescription {
12
13
result ?: any ;
@@ -29,6 +30,7 @@ interface IChildProcessResults {
29
30
podVersion : IChildProcessResultDescription ;
30
31
pod : IChildProcessResultDescription ;
31
32
nativeScriptCliVersion : IChildProcessResultDescription ;
33
+ git : IChildProcessResultDescription ;
32
34
}
33
35
34
36
interface IHostInfoMockOptions {
@@ -73,16 +75,19 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
73
75
"xcodebuild -version" : childProcessResult . xCodeVersion ,
74
76
"pod --version" : childProcessResult . podVersion ,
75
77
"pod" : childProcessResult . pod ,
76
- ' adb' : childProcessResult . adbVersion ,
77
- ' adb version' : childProcessResult . adbVersion ,
78
+ " adb" : childProcessResult . adbVersion ,
79
+ " adb version" : childProcessResult . adbVersion ,
78
80
"'adb' version" : childProcessResult . adbVersion , // for Mac and Linux
79
- ' android' : childProcessResult . androidInstalled ,
80
- ' android.bat' : childProcessResult . androidInstalled , // for Windows
81
+ " android" : childProcessResult . androidInstalled ,
82
+ " android.bat" : childProcessResult . androidInstalled , // for Windows
81
83
"mono --version" : childProcessResult . monoVersion ,
82
- "git --version" : childProcessResult . gitVersion ,
84
+ "'git' --version" : childProcessResult . gitVersion , // for Mac and Linux
85
+ '"C:\\Program Files\\Git\\cmd\\git.exe" --version' : childProcessResult . gitVersion , // for Windows
86
+ '"C:\\Program Files/Git/cmd/git.exe" --version' : childProcessResult . gitVersion , // When running Windows test on the Non-Windows platform
83
87
"gradle -v" : childProcessResult . gradleVersion ,
84
88
"tns --version" : childProcessResult . nativeScriptCliVersion ,
85
- "emulator" : { shouldThrowError : false }
89
+ "emulator" : { shouldThrowError : false } ,
90
+ "which git" : childProcessResult . git
86
91
} ;
87
92
}
88
93
@@ -128,9 +133,11 @@ function mockSysInfo(childProcessResult: IChildProcessResults, hostInfoOptions?:
128
133
129
134
const fileSystem : any = {
130
135
exists : ( ) => Promise . resolve ( ( fileSystemOptions || { } ) . existsResult ) ,
131
- extractZip : ( ) => Promise . resolve ( )
136
+ extractZip : ( ) => Promise . resolve ( ) ,
137
+ readDirectory : ( ) => Promise . resolve ( [ ] )
132
138
} ;
133
139
140
+ const helpers = new Helpers ( hostInfo ) ;
134
141
return new SysInfo ( childProcess , fileSystem , helpers , hostInfo , winreg , androidToolsInfo ) ;
135
142
}
136
143
@@ -169,6 +176,7 @@ describe("SysInfo unit tests", () => {
169
176
}
170
177
} ;
171
178
179
+ const helpers = new Helpers ( null ) ;
172
180
sysInfo = new SysInfo ( childProcess , null , helpers , null , null , androidToolsInfo ) ;
173
181
} ) ;
174
182
@@ -221,7 +229,8 @@ describe("SysInfo unit tests", () => {
221
229
gitVersion : { result : setStdOut ( "git version 1.9.5" ) } ,
222
230
podVersion : { result : setStdOut ( "0.38.2" ) } ,
223
231
pod : { result : setStdOut ( "success" ) } ,
224
- nativeScriptCliVersion : { result : setStdOut ( "2.5.0" ) }
232
+ nativeScriptCliVersion : { result : setStdOut ( "2.5.0" ) } ,
233
+ git : { result : setStdOut ( "git" ) }
225
234
} ;
226
235
227
236
delete process . env [ JavaHomeName ] ;
@@ -253,8 +262,11 @@ describe("SysInfo unit tests", () => {
253
262
} ) ;
254
263
255
264
it ( "on Windows" , async ( ) => {
265
+ const originalProgramFiles = process . env [ PROGRAM_FILES ] ;
266
+ process . env [ PROGRAM_FILES ] = PROGRAM_FILES_ENV_PATH ;
256
267
sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
257
268
let result = await sysInfo . getSysInfo ( ) ;
269
+ process . env [ PROGRAM_FILES ] = originalProgramFiles ;
258
270
assertCommonValues ( result ) ;
259
271
assert . deepEqual ( result . xcodeVer , null ) ;
260
272
assert . deepEqual ( result . cocoaPodsVer , null ) ;
@@ -287,8 +299,11 @@ describe("SysInfo unit tests", () => {
287
299
} ) ;
288
300
289
301
it ( "is null when OS is not Mac" , async ( ) => {
302
+ const originalProgramFiles = process . env [ PROGRAM_FILES ] ;
303
+ process . env [ PROGRAM_FILES ] = PROGRAM_FILES_ENV_PATH ;
290
304
sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
291
305
let result = await sysInfo . getSysInfo ( ) ;
306
+ process . env [ PROGRAM_FILES ] = originalProgramFiles ;
292
307
assert . deepEqual ( result . cocoaPodsVer , null ) ;
293
308
} ) ;
294
309
@@ -324,7 +339,8 @@ describe("SysInfo unit tests", () => {
324
339
gitVersion : { shouldThrowError : true } ,
325
340
podVersion : { shouldThrowError : true } ,
326
341
pod : { shouldThrowError : true } ,
327
- nativeScriptCliVersion : { shouldThrowError : true }
342
+ nativeScriptCliVersion : { shouldThrowError : true } ,
343
+ git : { shouldThrowError : false }
328
344
} ;
329
345
androidToolsInfo . validateAndroidHomeEnvVariable = ( ) : any [ ] => [ 1 ] ;
330
346
} ) ;
@@ -346,7 +362,10 @@ describe("SysInfo unit tests", () => {
346
362
} ;
347
363
348
364
it ( "on Windows" , async ( ) => {
365
+ const originalProgramFiles = process . env [ PROGRAM_FILES ] ;
366
+ process . env [ PROGRAM_FILES ] = PROGRAM_FILES_ENV_PATH ;
349
367
sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
368
+ process . env [ PROGRAM_FILES ] = originalProgramFiles ;
350
369
await assertAllValuesAreNull ( ) ;
351
370
} ) ;
352
371
0 commit comments