diff --git a/packages/sdk-android/src/__tests__/runner.test.ts b/packages/sdk-android/src/__tests__/runner.test.ts index 42a442e07..6045f250d 100644 --- a/packages/sdk-android/src/__tests__/runner.test.ts +++ b/packages/sdk-android/src/__tests__/runner.test.ts @@ -16,6 +16,42 @@ afterEach(() => { }); describe('getAndroidDeviceToRunOn', () => { + it('should fail if a device is provided but no active device exists', async () => { + //GIVEN + const ctx = getContext(); + ctx.platform = 'android'; + ctx.program.target = true; + ctx.program.device = 'device1'; + ctx.runtime.target = 'defaultTarget'; + const mockFoundDevice = { name: 'simulator1', isActive: false, udid: '', isDevice: false }; + + jest.mocked(getAndroidTargets).mockResolvedValue([mockFoundDevice]); + + //WHEN + await expect(getAndroidDeviceToRunOn(ctx)).resolves.toBe(undefined); + + //THEN + }); + it('should fail if targetToConnectWiFi is not a valid IP address - npx rnv -p android -t -d ', async () => { + //GIVEN + const targetToConnectWiFi = 'invalidIPAdress'; + const ctx = getContext(); + ctx.platform = 'android'; + ctx.program.target = true; + ctx.runtime.target = 'defaultTarget'; + ctx.program.device = targetToConnectWiFi; + const mockFoundDevice = { name: 'simulator1', isActive: false, udid: '', isDevice: false }; + + net.isIP = jest.fn().mockReturnValue(false); + + jest.mocked(getAndroidTargets).mockResolvedValue([mockFoundDevice]); + + //WHEN + await expect(getAndroidDeviceToRunOn(ctx)).resolves.toBe(undefined); + + //THEN + expect(connectToWifiDevice).not.toHaveBeenCalled(); + }); it('should connect to WiFi device if targetToConnectWiFi is a string and a valid IP address', async () => { //GIVEN const targetToConnectWiFi = '192.168.0.1'; @@ -38,6 +74,20 @@ describe('getAndroidDeviceToRunOn', () => { expect(connectToWifiDevice).toHaveBeenCalledWith(ctx, targetToConnectWiFi); expect(result).toEqual(mockFoundDevice); }); + it('should return defaultTarget if it exists and -t is not specified', async () => { + //GIVEN + const ctx = getContext(); + ctx.platform = 'android'; + ctx.program.target = undefined; + ctx.runtime.target = 'defaultTarget'; + const mockFoundDevice = { name: 'defaultTarget', isActive: true, udid: '', isDevice: false }; + + jest.mocked(getAndroidTargets).mockResolvedValue([mockFoundDevice]); + + const result = await getAndroidDeviceToRunOn(ctx); + //THEN + expect(result).toEqual(mockFoundDevice); + }); it('should return found sim if target is provided and found - npx rnv -p android -t ', async () => { //GIVEN const ctx = getContext(); diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 07233bed2..729d65a39 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -86,13 +86,11 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { } const devicesAndEmulators = await getAndroidTargets(c, false, false, !!device); - console.log('devicesAndEmulators', devicesAndEmulators); const activeDevices = devicesAndEmulators.filter((d) => d.isActive); const inactiveDevices = devicesAndEmulators.filter((d) => !d.isActive); const foundDevice = devicesAndEmulators.find( (d) => d.udid.includes(target) || d.name.includes(target) || d.udid.includes(device) || d.name.includes(device) ); - console.log('foundDevice', foundDevice); const askWhereToRun = async () => { if (activeDevices.length || inactiveDevices.length) {