@@ -19,7 +19,6 @@ interface IChildProcessResultDescription {
1919interface IChildProcessResults {
2020 uname : IChildProcessResultDescription ;
2121 npmV : IChildProcessResultDescription ;
22- javaVersion : IChildProcessResultDescription ;
2322 javacVersion : IChildProcessResultDescription ;
2423 nodeGypVersion : IChildProcessResultDescription ;
2524 xCodeVersion : IChildProcessResultDescription ;
@@ -32,7 +31,7 @@ interface IChildProcessResults {
3231}
3332
3433function getResultFromChildProcess ( childProcessResultDescription : IChildProcessResultDescription , spawnFromEventOpts ?: { throwError : boolean } ) : any {
35- if ( childProcessResultDescription . shouldThrowError ) {
34+ if ( ! childProcessResultDescription || childProcessResultDescription . shouldThrowError ) {
3635 if ( spawnFromEventOpts && ! spawnFromEventOpts . throwError ) {
3736 return {
3837 stderr : "This one throws error." ,
@@ -51,7 +50,6 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
5150 return {
5251 "uname -a" : childProcessResult . uname ,
5352 "npm -v" : childProcessResult . npmV ,
54- "java" : childProcessResult . javaVersion ,
5553 '"javac" -version' : childProcessResult . javacVersion ,
5654 "node-gyp -v" : childProcessResult . nodeGypVersion ,
5755 "xcodebuild -version" : childProcessResult . xCodeVersion ,
@@ -65,7 +63,7 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
6563 } ;
6664}
6765
68- function createTestInjector ( childProcessResult : IChildProcessResults , hostInfoData : { isWindows : boolean , dotNetVersion : string , isDarwin : boolean } , itunesError : string ) : IInjector {
66+ function createTestInjector ( childProcessResult : IChildProcessResults , hostInfoData : { isWindows : boolean , dotNetVersion ? : string , isDarwin : boolean } , itunesError : string ) : IInjector {
6967 const injector = new Yok ( ) ;
7068 const childProcessResultDictionary = createChildProcessResults ( childProcessResult ) ;
7169 injector . register ( "childProcess" , {
@@ -79,7 +77,7 @@ function createTestInjector(childProcessResult: IChildProcessResults, hostInfoDa
7977 } ) ;
8078
8179 injector . register ( "hostInfo" , {
82- dotNetVersion : ( ) => Promise . resolve ( hostInfoData . dotNetVersion ) ,
80+ dotNetVersion : ( ) => Promise . resolve ( hostInfoData . dotNetVersion || "4.5.1" ) ,
8381 isWindows : hostInfoData . isWindows ,
8482 isDarwin : hostInfoData . isDarwin
8583 } ) ;
@@ -123,7 +121,6 @@ describe("sysInfoBase", () => {
123121 childProcessResult = {
124122 uname : { result : "name" } ,
125123 npmV : { result : "2.14.1" } ,
126- javaVersion : { result : { stderr : 'java version "1.8.0_60"' } } ,
127124 javacVersion : { result : { stderr : 'javac 1.8.0_60' } } ,
128125 nodeGypVersion : { result : "2.0.0" } ,
129126 xCodeVersion : { result : "6.4.0" } ,
@@ -142,7 +139,6 @@ describe("sysInfoBase", () => {
142139 describe ( "returns correct results when everything is installed" , ( ) => {
143140 const assertCommonValues = ( result : ISysInfoData ) => {
144141 assert . deepEqual ( result . npmVer , childProcessResult . npmV . result ) ;
145- assert . deepEqual ( result . javaVer , "1.8.0" ) ;
146142 assert . deepEqual ( result . javacVersion , "1.8.0_60" ) ;
147143 assert . deepEqual ( result . nodeGypVer , childProcessResult . nodeGypVersion . result ) ;
148144 assert . deepEqual ( result . adbVer , childProcessResult . adbVersion . result ) ;
@@ -214,12 +210,33 @@ describe("sysInfoBase", () => {
214210 } ) ;
215211 } ) ;
216212
213+ describe ( "getJavaCompilerVersion" , ( ) => {
214+ const verifyJavaCompilerVersion = async ( javaCompilerVersion : string , resultStream : string ) : Promise < void > => {
215+ const javaCompilerChildProcessResult : any = {
216+ [ resultStream ] : `javac ${ javaCompilerVersion } `
217+ } ;
218+
219+ javaCompilerChildProcessResult . javacVersion = { result : javaCompilerChildProcessResult } ;
220+ testInjector = createTestInjector ( javaCompilerChildProcessResult , { isWindows : false , isDarwin : true } , null ) ;
221+ sysInfoBase = testInjector . resolve ( "sysInfoBase" ) ;
222+ const actualJavaCompilerVersion = await sysInfoBase . getJavaCompilerVersion ( ) ;
223+ assert . deepEqual ( actualJavaCompilerVersion , javaCompilerVersion ) ;
224+ } ;
225+
226+ it ( "returns correct javac version when it is printed on stderr (Java 8)" , ( ) => {
227+ return verifyJavaCompilerVersion ( "1.8.0_152" , "stderr" ) ;
228+ } ) ;
229+
230+ it ( "returns correct javac version when it is printed on stdout (Java 9)" , ( ) => {
231+ return verifyJavaCompilerVersion ( "9.0.1" , "stdout" ) ;
232+ } ) ;
233+ } ) ;
234+
217235 describe ( "returns correct results when exceptions are raised during sysInfo data collection" , ( ) => {
218236 beforeEach ( ( ) => {
219237 childProcessResult = {
220238 uname : { shouldThrowError : true } ,
221239 npmV : { shouldThrowError : true } ,
222- javaVersion : { shouldThrowError : true } ,
223240 javacVersion : { shouldThrowError : true } ,
224241 nodeGypVersion : { shouldThrowError : true } ,
225242 xCodeVersion : { shouldThrowError : true } ,
@@ -253,7 +270,6 @@ describe("sysInfoBase", () => {
253270 sysInfoBase = testInjector . resolve ( "sysInfoBase" ) ;
254271 const result = await sysInfoBase . getSysInfo ( toolsPackageJson ) ;
255272 assert . deepEqual ( result . npmVer , null ) ;
256- assert . deepEqual ( result . javaVer , null ) ;
257273 assert . deepEqual ( result . javacVersion , null ) ;
258274 assert . deepEqual ( result . nodeGypVer , null ) ;
259275 assert . deepEqual ( result . xcodeVer , null ) ;
0 commit comments