@@ -6,7 +6,8 @@ import { ChildProcess } from "../lib/wrappers/child-process";
66
77const JavaHomeName = "JAVA_HOME" ;
88const AndroidHomeName = "ANDROID_HOME" ;
9- const helpers = new Helpers ( ) ;
9+ const PROGRAM_FILES = "ProgramFiles" ;
10+ const PROGRAM_FILES_ENV_PATH = "C:\\Program Files" ;
1011
1112interface IChildProcessResultDescription {
1213 result ?: any ;
@@ -29,6 +30,7 @@ interface IChildProcessResults {
2930 podVersion : IChildProcessResultDescription ;
3031 pod : IChildProcessResultDescription ;
3132 nativeScriptCliVersion : IChildProcessResultDescription ;
33+ git : IChildProcessResultDescription ;
3234}
3335
3436interface IHostInfoMockOptions {
@@ -73,16 +75,19 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
7375 "xcodebuild -version" : childProcessResult . xCodeVersion ,
7476 "pod --version" : childProcessResult . podVersion ,
7577 "pod" : childProcessResult . pod ,
76- ' adb' : childProcessResult . adbVersion ,
77- ' adb version' : childProcessResult . adbVersion ,
78+ " adb" : childProcessResult . adbVersion ,
79+ " adb version" : childProcessResult . adbVersion ,
7880 "'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
8183 "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
8387 "gradle -v" : childProcessResult . gradleVersion ,
8488 "tns --version" : childProcessResult . nativeScriptCliVersion ,
85- "emulator" : { shouldThrowError : false }
89+ "emulator" : { shouldThrowError : false } ,
90+ "which git" : childProcessResult . git
8691 } ;
8792}
8893
@@ -128,9 +133,11 @@ function mockSysInfo(childProcessResult: IChildProcessResults, hostInfoOptions?:
128133
129134 const fileSystem : any = {
130135 exists : ( ) => Promise . resolve ( ( fileSystemOptions || { } ) . existsResult ) ,
131- extractZip : ( ) => Promise . resolve ( )
136+ extractZip : ( ) => Promise . resolve ( ) ,
137+ readDirectory : ( ) => Promise . resolve ( [ ] )
132138 } ;
133139
140+ const helpers = new Helpers ( hostInfo ) ;
134141 return new SysInfo ( childProcess , fileSystem , helpers , hostInfo , winreg , androidToolsInfo ) ;
135142}
136143
@@ -169,6 +176,7 @@ describe("SysInfo unit tests", () => {
169176 }
170177 } ;
171178
179+ const helpers = new Helpers ( null ) ;
172180 sysInfo = new SysInfo ( childProcess , null , helpers , null , null , androidToolsInfo ) ;
173181 } ) ;
174182
@@ -221,7 +229,8 @@ describe("SysInfo unit tests", () => {
221229 gitVersion : { result : setStdOut ( "git version 1.9.5" ) } ,
222230 podVersion : { result : setStdOut ( "0.38.2" ) } ,
223231 pod : { result : setStdOut ( "success" ) } ,
224- nativeScriptCliVersion : { result : setStdOut ( "2.5.0" ) }
232+ nativeScriptCliVersion : { result : setStdOut ( "2.5.0" ) } ,
233+ git : { result : setStdOut ( "git" ) }
225234 } ;
226235
227236 delete process . env [ JavaHomeName ] ;
@@ -253,8 +262,11 @@ describe("SysInfo unit tests", () => {
253262 } ) ;
254263
255264 it ( "on Windows" , async ( ) => {
265+ const originalProgramFiles = process . env [ PROGRAM_FILES ] ;
266+ process . env [ PROGRAM_FILES ] = PROGRAM_FILES_ENV_PATH ;
256267 sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
257268 let result = await sysInfo . getSysInfo ( ) ;
269+ process . env [ PROGRAM_FILES ] = originalProgramFiles ;
258270 assertCommonValues ( result ) ;
259271 assert . deepEqual ( result . xcodeVer , null ) ;
260272 assert . deepEqual ( result . cocoaPodsVer , null ) ;
@@ -287,8 +299,11 @@ describe("SysInfo unit tests", () => {
287299 } ) ;
288300
289301 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 ;
290304 sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
291305 let result = await sysInfo . getSysInfo ( ) ;
306+ process . env [ PROGRAM_FILES ] = originalProgramFiles ;
292307 assert . deepEqual ( result . cocoaPodsVer , null ) ;
293308 } ) ;
294309
@@ -324,7 +339,8 @@ describe("SysInfo unit tests", () => {
324339 gitVersion : { shouldThrowError : true } ,
325340 podVersion : { shouldThrowError : true } ,
326341 pod : { shouldThrowError : true } ,
327- nativeScriptCliVersion : { shouldThrowError : true }
342+ nativeScriptCliVersion : { shouldThrowError : true } ,
343+ git : { shouldThrowError : false }
328344 } ;
329345 androidToolsInfo . validateAndroidHomeEnvVariable = ( ) : any [ ] => [ 1 ] ;
330346 } ) ;
@@ -346,7 +362,10 @@ describe("SysInfo unit tests", () => {
346362 } ;
347363
348364 it ( "on Windows" , async ( ) => {
365+ const originalProgramFiles = process . env [ PROGRAM_FILES ] ;
366+ process . env [ PROGRAM_FILES ] = PROGRAM_FILES_ENV_PATH ;
349367 sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
368+ process . env [ PROGRAM_FILES ] = originalProgramFiles ;
350369 await assertAllValuesAreNull ( ) ;
351370 } ) ;
352371
0 commit comments