From fb20d03fe33e7bb9030a54f2306a09c237cfc75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=80=E9=9D=99=E5=87=A1?= <30424139+wtto00@users.noreply.github.com> Date: Sun, 17 Sep 2023 22:02:31 +0800 Subject: [PATCH] chore: test --- spec/afterStart.test.ts | 53 +++++++++++++++++++--------------------- spec/emulatorAVD.test.ts | 2 +- src/util.ts | 5 ---- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/spec/afterStart.test.ts b/spec/afterStart.test.ts index 1ed692e..fbb1514 100644 --- a/spec/afterStart.test.ts +++ b/spec/afterStart.test.ts @@ -1,38 +1,35 @@ import path from "path"; import Android from "../src/index.js"; -describe("after start a emulator", () => { - const android = new Android(); +const android = new Android(); - let emulatorId = ""; - beforeAll(async () => { - const avds = await android.listAVDs(); - let avdName = ""; - console.log("avds.length", avds.length); +let emulatorId = ""; +beforeAll(async () => { + const avds = await android.listAVDs(); + let avdName = ""; + if (avds.length === 0) { + avdName = `TestCreate_${Math.random().toString().substring(2)}`; + const images = (await android.listImages()).filter((item) => item.vendor === "default" && item.arch === "x86_64"); + if (images.length === 0) return; + const image = images[images.length - 1].name; + await android.createAVD({ name: avdName, package: image, force: false }); + } else { + avdName = avds[0].Name; + } + const res = await android.start(avdName); + emulatorId = res.id; + if (emulatorId) { + await android.ensureReady(emulatorId); + } +}, 120000); - if (avds.length === 0) { - avdName = `TestCreate_${Math.random().toString().substring(2)}`; - const images = (await android.listImages()).filter((item) => item.vendor === "default" && item.arch === "x86_64"); - if (images.length === 0) return; - const image = images[images.length - 1].name; - console.log("image", image); - - await android.createAVD({ name: avdName, package: image, force: false }); - } else { - avdName = avds[0].Name; - } - const res = await android.start(avdName); - emulatorId = res.id; - if (emulatorId) { - await android.ensureReady(emulatorId); - } - }, 120000); - - afterAll(async () => { - await android.waitForStop(emulatorId); - }, 60000); +afterAll(async () => { + await android.waitForStop(emulatorId); +}, 60000); +describe("after start a emulator", () => { test("list packages", async () => { + console.log("emulatorId", emulatorId); if (emulatorId) { const list = await android.listPackages(emulatorId); expect(list.length).toBeGreaterThan(0); diff --git a/spec/emulatorAVD.test.ts b/spec/emulatorAVD.test.ts index e92348c..e584856 100644 --- a/spec/emulatorAVD.test.ts +++ b/spec/emulatorAVD.test.ts @@ -35,7 +35,7 @@ describe("emulator AVD", () => { test("list targets", async () => { const targets = await android.listTargets(); - expect(targets.length).toBeGreaterThan(0); + expect(Array.isArray(targets)).toBe(true); }); test("list devices", async () => { diff --git a/src/util.ts b/src/util.ts index 7299b8a..bdefd04 100644 --- a/src/util.ts +++ b/src/util.ts @@ -70,8 +70,6 @@ export function spawnWaitFor(command: string, regex: RegExp, timeout = 120000) { matches: RegExpMatchArray; line: string; }>((resolve, reject) => { - console.log("command", command); - const { cmd, args } = transformCommand(command); const proc = spawn(cmd, args, { stdio: ["ignore", "pipe", "ignore"] }); const clock = setTimeout(() => { @@ -80,8 +78,6 @@ export function spawnWaitFor(command: string, regex: RegExp, timeout = 120000) { let output = ""; proc.stdout.setEncoding("utf8"); proc.stdout.on("data", (data: string) => { - console.log("data", command); - output += data; let matches = data.match(regex); if (matches) { @@ -94,7 +90,6 @@ export function spawnWaitFor(command: string, regex: RegExp, timeout = 120000) { } }); proc.on("close", (code, signal) => { - console.log("error", proc.stderr); clearTimeout(clock); reject(Error(output)); });