Skip to content

Commit 799cf45

Browse files
author
Fatme
authored
Merge pull request #4079 from NativeScript/fatme/fix-emulator-errors
fix: reset errors when fallback to list avds from directory
2 parents e61068c + 8af307c commit 799cf45

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/common/mobile/android/android-virtual-device-service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export class AndroidVirtualDeviceService implements Mobile.IAndroidVirtualDevice
151151
private async getEmulatorImagesCore(): Promise<Mobile.IEmulatorImagesOutput> {
152152
let result: ISpawnResult = null;
153153
let devices: Mobile.IDeviceInfo[] = [];
154+
let errors: string[] = [];
154155

155156
if (this.pathToAvdManagerExecutable && this.$fs.exists(this.pathToAvdManagerExecutable)) {
156157
result = await this.$childProcess.trySpawnFromCloseEvent(this.pathToAvdManagerExecutable, ["list", "avds"]);
@@ -160,11 +161,12 @@ export class AndroidVirtualDeviceService implements Mobile.IAndroidVirtualDevice
160161

161162
if (result && result.stdout) {
162163
devices = this.parseListAvdsOutput(result.stdout);
164+
errors = result && result.stderr ? [result.stderr] : [];
163165
} else {
164166
devices = this.listAvdsFromDirectory();
165167
}
166168

167-
return { devices, errors: result && result.stderr ? [result.stderr] : [] };
169+
return { devices, errors };
168170
}
169171

170172
private async getRunningEmulatorData(runningEmulatorId: string, availableEmulators: Mobile.IDeviceInfo[]): Promise<Mobile.IDeviceInfo> {

lib/common/test/unit-tests/mobile/android-virtual-device-service.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,13 @@ describe("androidVirtualDeviceService", () => {
176176
assert.deepEqual(result.devices, []);
177177
assert.deepEqual(result.errors, []);
178178
});
179-
it("should return an empty array when `avdmanager list avds` command fails", async () => {
179+
it("should return an empty array and no errors when `avdmanager list avds` command fails", async () => {
180180
const avdManagerError = "some error while executing avdmanager list avds";
181181
const avdService = mockAvdService({ avdManagerError });
182182
const result = await avdService.getEmulatorImages([]);
183183
assert.lengthOf(result.devices, 0);
184184
assert.deepEqual(result.devices, []);
185-
assert.lengthOf(result.errors, 1);
186-
assert.deepEqual(result.errors, [avdManagerError]);
185+
assert.lengthOf(result.errors, 0);
187186
});
188187
it("should return all emulators when there are available emulators and no running emulators", async () => {
189188
const avdService = mockAvdService({
@@ -214,6 +213,24 @@ describe("androidVirtualDeviceService", () => {
214213
assert.deepEqual(result[1], getAvailableEmulatorData({ displayName: "Nexus_5X_API_28", imageIdentifier: "Nexus_5X_API_28", version: "9.0.0", model: "Nexus 5X" }));
215214
assert.deepEqual(result[2], getAvailableEmulatorData({ displayName: "Nexus_6P_API_28", imageIdentifier: "Nexus_6P_API_28", version: "9.0.0", model: "Nexus 6P" }));
216215
});
216+
// In this case we should fallback to list avd directory and should't report errors from avdmanager
217+
it("should return devices and no errors when there is an error on avdmanager's stderr", async () => {
218+
const iniFilesData = getIniFilesData();
219+
const testInjector = createTestInjector({
220+
avdManagerOutput: "",
221+
avdManagerError: "my test error",
222+
iniFilesData
223+
});
224+
225+
const fs = testInjector.resolve("fs");
226+
fs.readDirectory = () => _.keys(iniFilesData);
227+
228+
const avdService = testInjector.resolve("androidVirtualDeviceService");
229+
const result = await avdService.getEmulatorImages(["emulator-5554 device"]);
230+
231+
assert.deepEqual(result.devices.length, 3);
232+
assert.deepEqual(result.errors.length, 0);
233+
});
217234
});
218235

219236
describe("when avdmanager is not found", () => {

0 commit comments

Comments
 (0)