Skip to content

Commit 8b2cfb6

Browse files
Merge pull request #21 from NativeScript/vladimirov/fix-getting-cli-version
Fix getting CLI version
2 parents 9b33780 + a0265d9 commit 8b2cfb6

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

lib/sys-info.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
6868
public getJavaCompilerVersion(): Promise<string> {
6969
return this.getValueForProperty(() => this.javaCompilerVerCache, async (): Promise<string> => {
7070
const javaCompileExecutableName = "javac";
71-
const javaHome = process.env.JAVA_HOME;
71+
const javaHome = process.env["JAVA_HOME"];
7272
const pathToJavaCompilerExecutable = javaHome ? path.join(javaHome, "bin", javaCompileExecutableName) : javaCompileExecutableName;
7373
try {
7474
const output = await this.childProcess.exec(`"${pathToJavaCompilerExecutable}" -version`);
@@ -135,7 +135,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
135135
let mobileDeviceDir: string;
136136

137137
if (this.hostInfo.isWindows) {
138-
const commonProgramFiles = this.hostInfo.isWindows64 ? process.env["CommonProgramFiles(x86)"] : process.env.CommonProgramFiles;
138+
const commonProgramFiles = this.hostInfo.isWindows64 ? process.env["CommonProgramFiles(x86)"] : process.env["CommonProgramFiles"];
139139
coreFoundationDir = path.join(commonProgramFiles, "Apple", "Apple Application Support");
140140
mobileDeviceDir = path.join(commonProgramFiles, "Apple", "Mobile Device Support");
141141
} else if (this.hostInfo.isDarwin) {
@@ -298,7 +298,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
298298
public getNativeScriptCliVersion(): Promise<string> {
299299
return this.getValueForProperty(() => this.nativeScriptCliVersionCache, async (): Promise<string> => {
300300
const output = await this.execCommand("tns --version");
301-
return output ? output.trim() : output;
301+
return output ? this.getVersionFromString(output.trim()) : output;
302302
});
303303
}
304304

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-doctor",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "Library that helps identifying if the environment can be used for development of {N} apps.",
55
"main": "lib/index.js",
66
"types": "./typings/nativescript-doctor.d.ts",

test/sys-info.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function mockSysInfo(childProcessResult: IChildProcessResults, hostInfoOptions?:
126126
spawnFromEvent: async (command: string, args: string[], event: string, options: ISpawnFromEventOptions) => {
127127
return getResultFromChildProcess(childProcessResultDictionary[command], command, options);
128128
},
129-
execFile: async () => {
129+
execFile: async (): Promise<any> => {
130130
return undefined;
131131
}
132132
};
@@ -153,7 +153,7 @@ describe("SysInfo unit tests", () => {
153153

154154
beforeEach(() => {
155155
// 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.
156-
process.env.CommonProgramFiles = process.env.CommonProgramFiles || "mocked on mac";
156+
process.env["CommonProgramFiles"] = process.env["CommonProgramFiles"] || "mocked on mac";
157157
process.env["CommonProgramFiles(x86)"] = process.env["CommonProgramFiles(x86)"] || "mocked on mac";
158158
});
159159

@@ -322,6 +322,29 @@ describe("SysInfo unit tests", () => {
322322
});
323323
});
324324

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+
});
332+
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+
});
339+
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");
345+
});
346+
});
347+
325348
describe("returns correct results when exceptions are raised during sysInfo data collection", () => {
326349
beforeEach(() => {
327350
childProcessResult = {

0 commit comments

Comments
 (0)