diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ee7a86..9e56c31 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,14 +51,10 @@ jobs: shell: bash run: | AVDMANAGER_PATH=$(which avdmanager) - echo $AVDMANAGER_PATH AVDMANAGER_DIR=$(dirname "$AVDMANAGER_PATH") - echo $AVDMANAGER_DIR - ls $AVDMANAGER_DIR mkdir $ANDROID_HOME/cmdline-tools mkdir $ANDROID_HOME/cmdline-tools/latest cp -r $AVDMANAGER_DIR/../* $ANDROID_HOME/cmdline-tools/latest/ - ls $ANDROID_HOME/cmdline-tools/latest/ - name: Run tests 👩🏽‍💻 run: npm run test diff --git a/spec/constructor.test.ts b/spec/constructor.test.ts index 49fdfb1..78a2c89 100644 --- a/spec/constructor.test.ts +++ b/spec/constructor.test.ts @@ -1,34 +1,29 @@ import path from "path"; import Android from "../src/index.js"; -const cmdLinePath = process.env.GITHUB_CI ? "cmdline-tools" : "cmdline-tools/latest"; - -/** - * in Github Action - * avdmanager,adb,sdkmanager has been in PATH - * avdmanager,sdkmanager are not in ANDROID_HOME - * adb,emulator are in ANDROID_HOME - */ - describe("constructor", () => { test("constructor", () => { const androidHome = process.env.ANDROID_HOME || ""; const android = new Android(); expect([android.adbBin, android.avdmanagerBin, android.sdkmanagerBin, android.emulatorBin]).toEqual([ path.resolve(androidHome, "platform-tools/adb"), - "avdmanager", - "sdkmanager", + path.resolve(androidHome, "cmdline-tools/latest/bin/avdmanager"), + path.resolve(androidHome, "cmdline-tools/latest/bin/sdkmanager"), path.resolve(androidHome, "emulator/emulator"), ]); }); - test("constructor with adb error path", () => { + test("constructor with error path", () => { const androidHome = process.env.ANDROID_HOME || ""; - const android = new Android({ adb: "platform-tools/adb111", emulator: "emulator/emulator111" }); + const android = new Android({ + adb: "platform-tools/adb111", + avdmanager: "cmdline-tools/latest/bin/avdmanager11", + emulator: "emulator/emulator111", + }); expect([android.adbBin, android.avdmanagerBin, android.sdkmanagerBin, android.emulatorBin]).toEqual([ "adb", "avdmanager", - "sdkmanager", + path.resolve(androidHome, "cmdline-tools/latest/bin/sdkmanager"), process.env.GITHUB_CI ? path.resolve(androidHome, "emulator/emulator111") : "emulator", ]); }); @@ -37,24 +32,26 @@ describe("constructor", () => { const androidHome = process.env.ANDROID_HOME || ""; const android = new Android({ adb: "platform-tools/adb", + avdmanager: "cmdline-tools/latest/bin/avdmanager", + sdkmanager: "cmdline-tools/latest/bin/sdkmanager", emulator: "emulator/emulator", }); expect([android.adbBin, android.avdmanagerBin, android.sdkmanagerBin, android.emulatorBin]).toEqual([ path.resolve(androidHome, "platform-tools/adb"), - 'avdmanager', - 'sdkmanager', + path.resolve(androidHome, "cmdline-tools/latest/bin/avdmanager"), + path.resolve(androidHome, "cmdline-tools/latest/bin/sdkmanager"), path.resolve(androidHome, "emulator/emulator"), ]); }); test("constructor with custom executable file environment variable", () => { const androidHome = process.env.ANDROID_HOME || ""; - process.env.adbBin = path.resolve(androidHome, 'platform-tools/adb'); + process.env.adbBin = path.resolve(androidHome, "platform-tools/adb"); const android = new Android(); expect([android.adbBin, android.avdmanagerBin, android.sdkmanagerBin, android.emulatorBin]).toEqual([ path.resolve(androidHome, "platform-tools/adb"), - 'avdmanager', - 'sdkmanager', + path.resolve(androidHome, "cmdline-tools/latest/bin/avdmanager"), + path.resolve(androidHome, "cmdline-tools/latest/bin/sdkmanager"), path.resolve(androidHome, "emulator/emulator"), ]); }); diff --git a/src/index.ts b/src/index.ts index 6fa12c4..b9a72ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -134,7 +134,7 @@ class Android { if (execPath) { this.avdmanagerBin = path.resolve(process.env.ANDROID_HOME, execPath); } else if (!this.avdmanagerBin) { - this.avdmanagerBin = path.resolve(process.env.ANDROID_HOME, "./cmdline-tools/bin/avdmanager"); + this.avdmanagerBin = path.resolve(process.env.ANDROID_HOME, "./cmdline-tools/latest/bin/avdmanager"); } } @@ -154,7 +154,7 @@ class Android { if (execPath) { this.sdkmanagerBin = path.resolve(process.env.ANDROID_HOME, execPath); } else if (!this.sdkmanagerBin) { - this.sdkmanagerBin = path.resolve(process.env.ANDROID_HOME, "./cmdline-tools/bin/sdkmanager"); + this.sdkmanagerBin = path.resolve(process.env.ANDROID_HOME, "./cmdline-tools/latest/bin/sdkmanager"); } } const regex = /Usage:/;