// import { DeviceUtils } from "../src/utils/deviceUtils";
//
// describe("DeviceUtils", function() {
//   let deviceUtils: DeviceUtils;
//   let testAvdName: string;
//
//
//   beforeEach(() => {
//     deviceUtils = new DeviceUtils();
//     testAvdName = "Medium_Phone_API_35"; // Use the known test AVD
//   });
//
//   describe("listDeviceImages", () => {
//     it("should list available AVDs", async () => {
//       const avds = await deviceUtils.listDeviceImages();
//       expect(Array.isArray(avds)).toBe(true);
//       // We know there's at least one AVD from our earlier testing
//       expect(avds.length).toBeGreaterThan(0);
//       expect(avds).toContain("Medium_Phone_API_35");
//     });
//   });
//
//   describe("getRunningEmulators", () => {
//     it("should get running emulators", async () => {
//       const runningEmulators = await deviceUtils.getRunningEmulators();
//       expect(Array.isArray(runningEmulators)).toBe(true);
//
//       // Each emulator should have the required properties
//       runningEmulators.forEach(emulator => {
//         expect(emulator).toHaveProperty("name");
//         expect(emulator).toHaveProperty("isRunning");
//         expect(emulator).toHaveProperty("deviceId");
//         expect(emulator.isRunning).toBe(true);
//       });
//     });
//   });
//
//   describe("isAvdRunning", () => {
//     it("should check if specific AVD is running", async () => {
//       // First get the list of running emulators
//       const runningEmulators = await deviceUtils.getRunningEmulators();
//
//       if (runningEmulators.length > 0) {
//         // Test with a running emulator
//         const runningEmulator = runningEmulators[0];
//         const isRunning = await deviceUtils.isAvdRunning(runningEmulator.name);
//         expect(isRunning).toBe(true);
//       } else {
//         // If no emulators are running, test with the known AVD which should be false
//         const isRunning = await deviceUtils.isAvdRunning("Medium_Phone_API_35");
//         expect(isRunning).toBe(false);
//       }
//     });
//
//     it("should return false for non-existent AVD", async () => {
//       const isRunning = await deviceUtils.isAvdRunning("NonExistentAVD");
//       expect(isRunning).toBe(false);
//     });
//   });
//
//   describe("startDevice", () => {
//     it("should fail to start non-existent AVD", async () => {
//       try {
//         await deviceUtils.startDevice("NonExistentAVD");
//         expect.fail("Should have thrown an error for non-existent AVD");
//       } catch (error) {
//         expect(error instanceof Error).toBe(true);
//         expect((error as Error).message).toContain("not found");
//       }
//     });
//
//     it("should fail to start already running AVD", async function() {
//       // First check if any emulator is already running
//       const runningEmulators = await deviceUtils.getRunningEmulators();
//
//       if (runningEmulators.length > 0) {
//         const runningAvd = runningEmulators[0].name;
//         try {
//           await deviceUtils.startDevice(runningAvd);
//           expect.fail("Should have thrown an error for already running AVD");
//         } catch (error) {
//           expect(error instanceof Error).toBe(true);
//           expect((error as Error).message).toContain("already running");
//         }
//       } else {
//         // Skip this test if no emulators are running
//         // Note: Bun does not support dynamic test skipping
//       }
//     });
//
//     it("should return a child process when starting valid AVD", async function() {
//       // Only run this test if the AVD is not already running
//       const isRunning = await deviceUtils.isAvdRunning(testAvdName);
//
//       if (isRunning) {
//         // Note: Bun does not support dynamic test skipping // Skip if already running to avoid conflicts
//         return;
//       }
//
//       const childProcess = await deviceUtils.startDevice(testAvdName);
//       expect(childProcess).toBeDefined();
//       expect(typeof childProcess.pid).toBe("number");
//
//       // Clean up: kill the emulator we just started
//       // Wait a moment for it to register
//       await new Promise(resolve => setTimeout(resolve, 3000));
//
//       try {
//         await deviceUtils.killEmulator(testAvdName);
//       } catch (error) {
//         // If kill fails, try to clean up with adb
//         console.warn("Failed to kill emulator cleanly, it may still be starting up");
//       }
//     });
//   });
//
//   describe("killDevice", () => {
//     it("should kill running AVD", async () => {
//       // Make sure the test AVD is not running
//       const isRunning = await deviceUtils.isAvdRunning(testAvdName);
//
//       if (!isRunning) {
//         // Start the emulator and wait for it to be ready
//         await deviceUtils.startDevice(testAvdName);
//         await deviceUtils.waitForDeviceReady(testAvdName);
//       }
//
//       await deviceUtils.killEmulator(testAvdName);
//       await new Promise(resolve => setTimeout(resolve, 2000));
//
//       // Check if it's truly not running after kill
//       const isStillRunning = await deviceUtils.isAvdRunning(testAvdName);
//       expect(isStillRunning).toBe(false);
//     });
//   });
//
//   describe("waitForDeviceReady", () => {
//     it("should timeout when waiting for non-existent emulator", async () => {
//       try {
//         await deviceUtils.waitForDeviceReady("NonExistentAVD", 5000); // 5 second timeout
//         expect.fail("Should have thrown a timeout error");
//       } catch (error) {
//         expect(error instanceof Error).toBe(true);
//         expect((error as Error).message).toContain("failed to become ready");
//       }
//     });
//
//     it("should return device ID for already running emulator", async function() {
//       // Check if any emulator is running
//       const runningEmulators = await deviceUtils.getRunningEmulators();
//
//       if (runningEmulators.length > 0) {
//         const runningAvd = runningEmulators[0];
//
//         // Should immediately return the device ID since it's already ready
//         const deviceId = await deviceUtils.waitForDeviceReady(runningAvd.name, 10000);
//         expect(typeof deviceId).toBe("string");
//         expect(deviceId).toBe(runningAvd.deviceId);
//       } else {
//         // Skip this test if no emulators are running
//         // Note: Bun does not support dynamic test skipping
//       }
//     });
//   });
// });
