CB-12640: support for android sdk tools 26.0.1. simplified target parsing by using avdmanager instead of sdkmanager. flipped target parsing logic so that it always tries to use avdmanager to retrieve targets first, then falls back to android command if avdmanager cannot be found (and errors with ENOENT). updated tests.

This commit is contained in:
filmaj
2017-04-06 13:13:38 -07:00
parent 814aca2b68
commit 46e47a3c5c
8 changed files with 47 additions and 1217 deletions
+14 -27
View File
@@ -29,7 +29,7 @@ describe("android_sdk", function () {
it("should parse and return results from `android list targets` command", function(done) {
var deferred = Q.defer();
spyOn(superspawn, "spawn").and.returnValue(deferred.promise);
deferred.resolve(fs.readFileSync(path.join("spec", "fixtures", "android_list_targets.txt"), "utf-8"));
deferred.resolve(fs.readFileSync(path.join("spec", "fixtures", "sdk25.2-android_list_targets.txt"), "utf-8"));
return android_sdk.list_targets_with_android()
.then(function(list) {
[ "Google Inc.:Google APIs:23",
@@ -53,26 +53,14 @@ describe("android_sdk", function () {
});
});
});
describe("list_targets_with_sdkmanager", function() {
it("should parse and return results from `sdkmanager --list` command", function(done) {
describe("list_targets_with_avdmanager", function() {
it("should parse and return results from `avdmanager list target` command", function(done) {
var deferred = Q.defer();
spyOn(superspawn, "spawn").and.returnValue(deferred.promise);
deferred.resolve(fs.readFileSync(path.join("spec", "fixtures", "sdkmanager_list.txt"), "utf-8"));
return android_sdk.list_targets_with_sdkmanager()
deferred.resolve(fs.readFileSync(path.join("spec", "fixtures", "sdk25.3-avdmanager_list_target.txt"), "utf-8"));
return android_sdk.list_targets_with_avdmanager()
.then(function(list) {
[ "Google Inc.:Google APIs:19",
"Google Inc.:Google APIs:21",
"Google Inc.:Google APIs:22",
"Google Inc.:Google APIs:23",
"Google Inc.:Google APIs:24",
"android-19",
"android-21",
"android-22",
"android-23",
"android-24",
"android-25" ].forEach(function(target) {
expect(list).toContain(target);
});
expect(list).toContain("android-25");
}).fail(function(err) {
console.log(err);
expect(err).toBeUndefined();
@@ -82,25 +70,24 @@ describe("android_sdk", function () {
});
});
describe("list_targets", function() {
it("should parse Android SDK installed target information with `android` command first", function() {
it("should parse Android SDK installed target information with `avdmanager` command first", function() {
var deferred = Q.defer();
var android_spy = spyOn(android_sdk, "list_targets_with_android").and.returnValue(deferred.promise);
var avdmanager_spy = spyOn(android_sdk, "list_targets_with_avdmanager").and.returnValue(deferred.promise);
android_sdk.list_targets();
expect(android_spy).toHaveBeenCalled();
expect(avdmanager_spy).toHaveBeenCalled();
});
it("should parse Android SDK installed target information with `avdmanager` command if list_targets_with_android fails due to `android` command being obsolete", function(done) {
it("should parse Android SDK installed target information with `android` command if list_targets_with_avdmanager fails with ENOENT", function(done) {
var deferred = Q.defer();
spyOn(android_sdk, "list_targets_with_android").and.returnValue(deferred.promise);
spyOn(android_sdk, "list_targets_with_avdmanager").and.returnValue(deferred.promise);
deferred.reject({
code: 1,
stdout: "The android command is no longer available."
code: "ENOENT"
});
var twoferred = Q.defer();
twoferred.resolve(["target1"]);
var sdkmanager_spy = spyOn(android_sdk, "list_targets_with_sdkmanager").and.returnValue(twoferred.promise);
var avdmanager_spy = spyOn(android_sdk, "list_targets_with_android").and.returnValue(twoferred.promise);
return android_sdk.list_targets()
.then(function(targets) {
expect(sdkmanager_spy).toHaveBeenCalled();
expect(avdmanager_spy).toHaveBeenCalled();
expect(targets[0]).toEqual("target1");
done();
});