1
1
import * as assert from "assert" ;
2
2
import * as path from "path" ;
3
+ import { EOL } from "os" ;
3
4
import { SysInfo } from "../lib/sys-info" ;
4
5
import { Helpers } from "../lib/helpers" ;
5
6
import { ChildProcess } from "../lib/wrappers/child-process" ;
@@ -14,7 +15,13 @@ interface IChildProcessResultDescription {
14
15
shouldThrowError ?: boolean ;
15
16
}
16
17
18
+ interface ICLIOutputVersionTestCase {
19
+ testedProperty : string ;
20
+ method : ( sysInfo : SysInfo ) => Promise < string > ;
21
+ }
22
+
17
23
interface IChildProcessResults {
24
+ [ property : string ] : IChildProcessResultDescription ;
18
25
uname : IChildProcessResultDescription ;
19
26
npmV : IChildProcessResultDescription ;
20
27
nodeV : IChildProcessResultDescription ;
@@ -30,6 +37,7 @@ interface IChildProcessResults {
30
37
podVersion : IChildProcessResultDescription ;
31
38
pod : IChildProcessResultDescription ;
32
39
nativeScriptCliVersion : IChildProcessResultDescription ;
40
+ nativeScriptCloudVersion : IChildProcessResultDescription ;
33
41
git : IChildProcessResultDescription ;
34
42
}
35
43
@@ -86,6 +94,7 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
86
94
'"C:\\Program Files/Git/cmd/git.exe" --version' : childProcessResult . gitVersion , // When running Windows test on the Non-Windows platform
87
95
"gradle -v" : childProcessResult . gradleVersion ,
88
96
"tns --version" : childProcessResult . nativeScriptCliVersion ,
97
+ "tns cloud lib version" : childProcessResult . nativeScriptCloudVersion ,
89
98
"emulator" : { shouldThrowError : false } ,
90
99
"which git" : childProcessResult . git
91
100
} ;
@@ -150,6 +159,7 @@ function setStdErr(value: string): { stderr: string } {
150
159
151
160
describe ( "SysInfo unit tests" , ( ) => {
152
161
let sysInfo : SysInfo ;
162
+ const dotNetVersion = "4.5.1" ;
153
163
154
164
beforeEach ( ( ) => {
155
165
// We need to mock this because on Mac the tests in which the platform is mocked to Windows in the process there will be no CommonProgramFiles.
@@ -230,6 +240,7 @@ describe("SysInfo unit tests", () => {
230
240
podVersion : { result : setStdOut ( "0.38.2" ) } ,
231
241
pod : { result : setStdOut ( "success" ) } ,
232
242
nativeScriptCliVersion : { result : setStdOut ( "2.5.0" ) } ,
243
+ nativeScriptCloudVersion : { result : setStdOut ( "0.1.0" ) } ,
233
244
git : { result : setStdOut ( "git" ) }
234
245
} ;
235
246
@@ -264,25 +275,25 @@ describe("SysInfo unit tests", () => {
264
275
it ( "on Windows" , async ( ) => {
265
276
const originalProgramFiles = process . env [ PROGRAM_FILES ] ;
266
277
process . env [ PROGRAM_FILES ] = PROGRAM_FILES_ENV_PATH ;
267
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
268
- let result = await sysInfo . getSysInfo ( ) ;
278
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion } ) ;
279
+ const result = await sysInfo . getSysInfo ( ) ;
269
280
process . env [ PROGRAM_FILES ] = originalProgramFiles ;
270
281
assertCommonValues ( result ) ;
271
282
assert . deepEqual ( result . xcodeVer , null ) ;
272
283
assert . deepEqual ( result . cocoaPodsVer , null ) ;
273
284
} ) ;
274
285
275
286
it ( "on Mac" , async ( ) => {
276
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion : "4.5.1" } ) ;
277
- let result = await sysInfo . getSysInfo ( ) ;
287
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
288
+ const result = await sysInfo . getSysInfo ( ) ;
278
289
assertCommonValues ( result ) ;
279
290
assert . deepEqual ( result . xcodeVer , "6.4.0" ) ;
280
291
assert . deepEqual ( result . cocoaPodsVer , childProcessResult . podVersion . result . stdout ) ;
281
292
} ) ;
282
293
283
294
it ( "on Linux" , async ( ) => {
284
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
285
- let result = await sysInfo . getSysInfo ( ) ;
295
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : false , dotNetVersion } ) ;
296
+ const result = await sysInfo . getSysInfo ( ) ;
286
297
assertCommonValues ( result ) ;
287
298
assert . deepEqual ( result . xcodeVer , null ) ;
288
299
assert . deepEqual ( result . cocoaPodsVer , null ) ;
@@ -293,55 +304,90 @@ describe("SysInfo unit tests", () => {
293
304
it ( "is null when cocoapods are not installed" , async ( ) => {
294
305
// simulate error when pod --version command is executed
295
306
childProcessResult . podVersion = { shouldThrowError : true } ;
296
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion : "4.5.1" } ) ;
297
- let result = await sysInfo . getSysInfo ( ) ;
307
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
308
+ const result = await sysInfo . getSysInfo ( ) ;
298
309
assert . deepEqual ( result . cocoaPodsVer , null ) ;
299
310
} ) ;
300
311
301
312
it ( "is null when OS is not Mac" , async ( ) => {
302
313
const originalProgramFiles = process . env [ PROGRAM_FILES ] ;
303
314
process . env [ PROGRAM_FILES ] = PROGRAM_FILES_ENV_PATH ;
304
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
305
- let result = await sysInfo . getSysInfo ( ) ;
315
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion } ) ;
316
+ const result = await sysInfo . getSysInfo ( ) ;
306
317
process . env [ PROGRAM_FILES ] = originalProgramFiles ;
307
318
assert . deepEqual ( result . cocoaPodsVer , null ) ;
308
319
} ) ;
309
320
310
321
it ( "is correct when cocoapods output has warning after version output" , async ( ) => {
311
322
childProcessResult . podVersion = { result : setStdOut ( "0.38.2\nWARNING:\n" ) } ;
312
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion : "4.5.1" } ) ;
313
- let result = await sysInfo . getSysInfo ( ) ;
323
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
324
+ const result = await sysInfo . getSysInfo ( ) ;
314
325
assert . deepEqual ( result . cocoaPodsVer , "0.38.2" ) ;
315
326
} ) ;
316
327
317
328
it ( "is correct when cocoapods output has warnings before version output" , async ( ) => {
318
329
childProcessResult . podVersion = { result : setStdOut ( "WARNING\nWARNING2\n0.38.2" ) } ;
319
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion : "4.5.1" } ) ;
320
- let result = await sysInfo . getSysInfo ( ) ;
330
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
331
+ const result = await sysInfo . getSysInfo ( ) ;
321
332
assert . deepEqual ( result . cocoaPodsVer , "0.38.2" ) ;
322
333
} ) ;
323
334
} ) ;
324
335
325
- describe ( "nativeScriptCliVersion" , ( ) => {
326
- it ( "is null when tns is not installed" , async ( ) => {
327
- childProcessResult . nativeScriptCliVersion = { shouldThrowError : true } ;
328
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion : "4.5.1" } ) ;
329
- let result = await sysInfo . getSysInfo ( ) ;
330
- assert . deepEqual ( result . nativeScriptCliVersion , null ) ;
331
- } ) ;
336
+ const testData : ICLIOutputVersionTestCase [ ] = [
337
+ {
338
+ testedProperty : "nativeScriptCliVersion" ,
339
+ method : ( currentSysInfo : SysInfo ) => currentSysInfo . getNativeScriptCliVersion ( )
340
+ } ,
341
+ {
342
+ testedProperty : "nativeScriptCloudVersion" ,
343
+ method : ( currentSysInfo : SysInfo ) => currentSysInfo . getNativeScriptCloudVersion ( )
344
+ } ] ;
345
+
346
+ testData . forEach ( ( testCase ) => {
347
+ describe ( testCase . testedProperty , ( ) => {
348
+ it ( "is null when tns is not installed" , async ( ) => {
349
+ childProcessResult [ testCase . testedProperty ] = { shouldThrowError : true } ;
350
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
351
+ const result = await testCase . method ( sysInfo ) ;
352
+ assert . deepEqual ( result , null ) ;
353
+ } ) ;
332
354
333
- it ( "is correct when the version is the only row in `tns --version` output" , async ( ) => {
334
- childProcessResult . nativeScriptCliVersion = { result : setStdOut ( "3.0.0" ) } ;
335
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion : "4.5.1" } ) ;
336
- let result = await sysInfo . getSysInfo ( ) ;
337
- assert . deepEqual ( result . nativeScriptCliVersion , "3.0.0" ) ;
338
- } ) ;
355
+ it ( "is correct when the version is the only row in command output" , async ( ) => {
356
+ childProcessResult [ testCase . testedProperty ] = { result : setStdOut ( "3.0.0" ) } ;
357
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
358
+ const result = await testCase . method ( sysInfo ) ;
359
+ assert . deepEqual ( result , "3.0.0" ) ;
360
+ } ) ;
339
361
340
- it ( "is correct when there are warnings in the `tns --version` output" , async ( ) => {
341
- childProcessResult . nativeScriptCliVersion = { result : setStdOut ( "Some warning due to invalid extensions\\n3.0.0" ) } ;
342
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion : "4.5.1" } ) ;
343
- let result = await sysInfo . getSysInfo ( ) ;
344
- assert . deepEqual ( result . nativeScriptCliVersion , "3.0.0" ) ;
362
+ it ( "is correct when there are warnings in the command's output" , async ( ) => {
363
+ childProcessResult [ testCase . testedProperty ] = { result : setStdOut ( `Some warning due to invalid extensions${ EOL } 3.0.0` ) } ;
364
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
365
+ const result = await testCase . method ( sysInfo ) ;
366
+ assert . deepEqual ( result , "3.0.0" ) ;
367
+ } ) ;
368
+
369
+ it ( "is correct when there are warnings with version in them in the command's output" , async ( ) => {
370
+ const cliOutput = `
371
+ Support for Node.js 7.6.0 is not verified. This CLI might not install or run properly.
372
+
373
+ 3.0.0` ;
374
+ childProcessResult [ testCase . testedProperty ] = { result : setStdOut ( cliOutput ) } ;
375
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
376
+ const result = await testCase . method ( sysInfo ) ;
377
+ assert . deepEqual ( result , "3.0.0" ) ;
378
+ } ) ;
379
+
380
+ it ( "is correct when there are warnings in the command's output and searched version is a prerelease" , async ( ) => {
381
+ const expectedCliVersion = "3.2.0-2017-07-21-9480" ;
382
+ const cliOutput = `
383
+ Support for Node.js 7.6.0 is not verified. This CLI might not install or run properly.
384
+
385
+ ${ expectedCliVersion } `;
386
+ childProcessResult [ testCase . testedProperty ] = { result : setStdOut ( cliOutput ) } ;
387
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
388
+ const result = await testCase . method ( sysInfo ) ;
389
+ assert . deepEqual ( result , expectedCliVersion ) ;
390
+ } ) ;
345
391
} ) ;
346
392
} ) ;
347
393
@@ -363,14 +409,15 @@ describe("SysInfo unit tests", () => {
363
409
podVersion : { shouldThrowError : true } ,
364
410
pod : { shouldThrowError : true } ,
365
411
nativeScriptCliVersion : { shouldThrowError : true } ,
412
+ nativeScriptCloudVersion : { shouldThrowError : true } ,
366
413
git : { shouldThrowError : false }
367
414
} ;
368
415
androidToolsInfo . validateAndroidHomeEnvVariable = ( ) : any [ ] => [ 1 ] ;
369
416
} ) ;
370
417
371
418
describe ( "when all of calls throw" , ( ) => {
372
419
let assertAllValuesAreNull = async ( ) => {
373
- let result = await sysInfo . getSysInfo ( ) ;
420
+ const result = await sysInfo . getSysInfo ( ) ;
374
421
assert . deepEqual ( result . npmVer , null ) ;
375
422
assert . deepEqual ( result . javaVer , null ) ;
376
423
assert . deepEqual ( result . javacVersion , null ) ;
@@ -387,18 +434,18 @@ describe("SysInfo unit tests", () => {
387
434
it ( "on Windows" , async ( ) => {
388
435
const originalProgramFiles = process . env [ PROGRAM_FILES ] ;
389
436
process . env [ PROGRAM_FILES ] = PROGRAM_FILES_ENV_PATH ;
390
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
437
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : true , isDarwin : false , dotNetVersion } ) ;
391
438
process . env [ PROGRAM_FILES ] = originalProgramFiles ;
392
439
await assertAllValuesAreNull ( ) ;
393
440
} ) ;
394
441
395
442
it ( "on Mac" , async ( ) => {
396
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion : "4.5.1" } ) ;
443
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : true , dotNetVersion } ) ;
397
444
await assertAllValuesAreNull ( ) ;
398
445
} ) ;
399
446
400
447
it ( "on Linux" , async ( ) => {
401
- sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : false , dotNetVersion : "4.5.1" } ) ;
448
+ sysInfo = mockSysInfo ( childProcessResult , { isWindows : false , isDarwin : false , dotNetVersion } ) ;
402
449
await assertAllValuesAreNull ( ) ;
403
450
} ) ;
404
451
} ) ;
0 commit comments