Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
wtto00 committed Sep 17, 2023
1 parent 0ae1d1f commit fb20d03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
53 changes: 25 additions & 28 deletions spec/afterStart.test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion spec/emulatorAVD.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
5 changes: 0 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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) {
Expand All @@ -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));
});
Expand Down

0 comments on commit fb20d03

Please sign in to comment.