Skip to content

Commit bb9b7ad

Browse files
Fix emulator check and unit tests
1 parent 9a11aac commit bb9b7ad

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

lib/sys-info.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,9 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
178178

179179
public async isAndroidSdkConfiguredCorrectly(): Promise<boolean> {
180180
return this.getValueForProperty(() => this.isAndroidSdkConfiguredCorrectlyCache, async (): Promise<boolean> => {
181-
try {
182-
await this.childProcess.execFile(this.androidToolsInfo.getPathToEmulatorExecutable(), ['-help']);
183-
} catch (err) {
184-
return false;
185-
}
181+
const output = await this.childProcess.spawnFromEvent(this.androidToolsInfo.getPathToEmulatorExecutable(), ['-help'], "close", { ignoreError: true });
186182

187-
return true;
183+
return output && output.stdout.indexOf("usage: emulator") >= 0;
188184
});
189185
}
190186

test/sys-info.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ const androidToolsInfo: NativeScriptDoctor.IAndroidToolsInfo = {
4545
return "adb";
4646
},
4747
getPathToEmulatorExecutable: () => {
48-
return "";
48+
return "emulator";
4949
},
5050
getToolsInfo: () => {
5151
return Object.create(null);
5252
},
53-
validateAndroidHomeEnvVariable: () => {
53+
validateAndroidHomeEnvVariable: (): any[] => {
5454
return [];
5555
},
56-
validateInfo: () => {
56+
validateInfo: (): any[] => {
5757
return [];
5858
},
59-
validateJavacVersion: () => {
59+
validateJavacVersion: (): any[] => {
6060
return [];
6161
}
6262
};
@@ -78,7 +78,8 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
7878
"mono --version": childProcessResult.monoVersion,
7979
"git --version": childProcessResult.gitVersion,
8080
"gradle -v": childProcessResult.gradleVersion,
81-
"tns --version": childProcessResult.nativeScriptCliVersion
81+
"tns --version": childProcessResult.nativeScriptCliVersion,
82+
"emulator": { shouldThrowError: false }
8283
};
8384
}
8485

@@ -110,7 +111,6 @@ function mockSysInfo(childProcessResult: IChildProcessResults, hostInfoOptions?:
110111
exec: async (command: string) => {
111112
return getResultFromChildProcess(childProcessResultDictionary[command], command);
112113
},
113-
114114
spawnFromEvent: async (command: string, args: string[], event: string) => {
115115
return getResultFromChildProcess(childProcessResultDictionary[command], command);
116116
},
@@ -239,6 +239,10 @@ describe("SysInfo unit tests", () => {
239239
assert.deepEqual(result.nativeScriptCliVersion, childProcessResult.nativeScriptCliVersion.result.stdout);
240240
};
241241

242+
beforeEach(() => {
243+
androidToolsInfo.validateAndroidHomeEnvVariable = (): any[] => [];
244+
});
245+
242246
it("on Windows", async () => {
243247
sysInfo = mockSysInfo(childProcessResult, { isWindows: true, isDarwin: false, dotNetVersion: "4.5.1" });
244248
let result = await sysInfo.getSysInfo();
@@ -312,6 +316,7 @@ describe("SysInfo unit tests", () => {
312316
pod: { shouldThrowError: true },
313317
nativeScriptCliVersion: { shouldThrowError: true }
314318
};
319+
androidToolsInfo.validateAndroidHomeEnvVariable = (): any[] => [1];
315320
});
316321

317322
describe("when all of calls throw", () => {
@@ -330,19 +335,19 @@ describe("SysInfo unit tests", () => {
330335
assert.deepEqual(result.cocoaPodsVer, null);
331336
};
332337

333-
it("on Windows", () => {
338+
it("on Windows", async () => {
334339
sysInfo = mockSysInfo(childProcessResult, { isWindows: true, isDarwin: false, dotNetVersion: "4.5.1" });
335-
assertAllValuesAreNull();
340+
await assertAllValuesAreNull();
336341
});
337342

338-
it("on Mac", () => {
343+
it("on Mac", async () => {
339344
sysInfo = mockSysInfo(childProcessResult, { isWindows: false, isDarwin: true, dotNetVersion: "4.5.1" });
340-
assertAllValuesAreNull();
345+
await assertAllValuesAreNull();
341346
});
342347

343-
it("on Linux", () => {
348+
it("on Linux", async () => {
344349
sysInfo = mockSysInfo(childProcessResult, { isWindows: false, isDarwin: false, dotNetVersion: "4.5.1" });
345-
assertAllValuesAreNull();
350+
await assertAllValuesAreNull();
346351
});
347352
});
348353
});

0 commit comments

Comments
 (0)