@@ -19,7 +19,6 @@ interface IChildProcessResultDescription {
19
19
interface IChildProcessResults {
20
20
uname : IChildProcessResultDescription ;
21
21
npmV : IChildProcessResultDescription ;
22
- javaVersion : IChildProcessResultDescription ;
23
22
javacVersion : IChildProcessResultDescription ;
24
23
nodeGypVersion : IChildProcessResultDescription ;
25
24
xCodeVersion : IChildProcessResultDescription ;
@@ -32,7 +31,7 @@ interface IChildProcessResults {
32
31
}
33
32
34
33
function getResultFromChildProcess ( childProcessResultDescription : IChildProcessResultDescription , spawnFromEventOpts ?: { throwError : boolean } ) : any {
35
- if ( childProcessResultDescription . shouldThrowError ) {
34
+ if ( ! childProcessResultDescription || childProcessResultDescription . shouldThrowError ) {
36
35
if ( spawnFromEventOpts && ! spawnFromEventOpts . throwError ) {
37
36
return {
38
37
stderr : "This one throws error." ,
@@ -51,7 +50,6 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
51
50
return {
52
51
"uname -a" : childProcessResult . uname ,
53
52
"npm -v" : childProcessResult . npmV ,
54
- "java" : childProcessResult . javaVersion ,
55
53
'"javac" -version' : childProcessResult . javacVersion ,
56
54
"node-gyp -v" : childProcessResult . nodeGypVersion ,
57
55
"xcodebuild -version" : childProcessResult . xCodeVersion ,
@@ -65,7 +63,7 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
65
63
} ;
66
64
}
67
65
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 {
69
67
const injector = new Yok ( ) ;
70
68
const childProcessResultDictionary = createChildProcessResults ( childProcessResult ) ;
71
69
injector . register ( "childProcess" , {
@@ -79,7 +77,7 @@ function createTestInjector(childProcessResult: IChildProcessResults, hostInfoDa
79
77
} ) ;
80
78
81
79
injector . register ( "hostInfo" , {
82
- dotNetVersion : ( ) => Promise . resolve ( hostInfoData . dotNetVersion ) ,
80
+ dotNetVersion : ( ) => Promise . resolve ( hostInfoData . dotNetVersion || "4.5.1" ) ,
83
81
isWindows : hostInfoData . isWindows ,
84
82
isDarwin : hostInfoData . isDarwin
85
83
} ) ;
@@ -123,7 +121,6 @@ describe("sysInfoBase", () => {
123
121
childProcessResult = {
124
122
uname : { result : "name" } ,
125
123
npmV : { result : "2.14.1" } ,
126
- javaVersion : { result : { stderr : 'java version "1.8.0_60"' } } ,
127
124
javacVersion : { result : { stderr : 'javac 1.8.0_60' } } ,
128
125
nodeGypVersion : { result : "2.0.0" } ,
129
126
xCodeVersion : { result : "6.4.0" } ,
@@ -142,7 +139,6 @@ describe("sysInfoBase", () => {
142
139
describe ( "returns correct results when everything is installed" , ( ) => {
143
140
const assertCommonValues = ( result : ISysInfoData ) => {
144
141
assert . deepEqual ( result . npmVer , childProcessResult . npmV . result ) ;
145
- assert . deepEqual ( result . javaVer , "1.8.0" ) ;
146
142
assert . deepEqual ( result . javacVersion , "1.8.0_60" ) ;
147
143
assert . deepEqual ( result . nodeGypVer , childProcessResult . nodeGypVersion . result ) ;
148
144
assert . deepEqual ( result . adbVer , childProcessResult . adbVersion . result ) ;
@@ -214,12 +210,33 @@ describe("sysInfoBase", () => {
214
210
} ) ;
215
211
} ) ;
216
212
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
+
217
235
describe ( "returns correct results when exceptions are raised during sysInfo data collection" , ( ) => {
218
236
beforeEach ( ( ) => {
219
237
childProcessResult = {
220
238
uname : { shouldThrowError : true } ,
221
239
npmV : { shouldThrowError : true } ,
222
- javaVersion : { shouldThrowError : true } ,
223
240
javacVersion : { shouldThrowError : true } ,
224
241
nodeGypVersion : { shouldThrowError : true } ,
225
242
xCodeVersion : { shouldThrowError : true } ,
@@ -253,7 +270,6 @@ describe("sysInfoBase", () => {
253
270
sysInfoBase = testInjector . resolve ( "sysInfoBase" ) ;
254
271
const result = await sysInfoBase . getSysInfo ( toolsPackageJson ) ;
255
272
assert . deepEqual ( result . npmVer , null ) ;
256
- assert . deepEqual ( result . javaVer , null ) ;
257
273
assert . deepEqual ( result . javacVersion , null ) ;
258
274
assert . deepEqual ( result . nodeGypVer , null ) ;
259
275
assert . deepEqual ( result . xcodeVer , null ) ;
0 commit comments