diff --git a/lib/src/daemon_client.dart b/lib/src/daemon_client.dart index 2ac00e65..950e37ca 100644 --- a/lib/src/daemon_client.dart +++ b/lib/src/daemon_client.dart @@ -216,7 +216,7 @@ List getIosDevices() { .trim() .split('\n') .sublist(1); - if (iosDeployDevices.isEmpty || iosDeployDevices[0] == noAttachedDevices) { + if (iosDeployDevices[0] == noAttachedDevices) { return []; } return iosDeployDevices.map((line) { diff --git a/test/daemon_client_test.dart b/test/daemon_client_test.dart index 029b5ddb..970c9ad6 100644 --- a/test/daemon_client_test.dart +++ b/test/daemon_client_test.dart @@ -390,6 +390,56 @@ main() { expect(emulator1, isNot(equals(device1))); }); }); + + group('getIosDevices', (){ + FakeProcessManager fakeProcessManager; + FakePlatform fakePlatform; + + setUp(() { + fakeProcessManager = FakeProcessManager(); + fakePlatform = FakePlatform.fromPlatform(const LocalPlatform()) + ..operatingSystem = 'macos'; + }); + + testUsingContext('no real device',(){ + fakeProcessManager.calls = [ + Call( + 'sh -c ios-deploy -c || echo "no attached devices"', + ProcessResult( + 0, + 0, + '[....] Waiting up to 5 seconds for iOS device to be connected\nno attached devices', + '')), + ]; + final iosDevices = getIosDevices(); + expect(iosDevices, isEmpty); + fakeProcessManager.verifyCalls(); + }, overrides: { + ProcessManager: () => fakeProcessManager, + Platform: () => fakePlatform, + }); + + testUsingContext('real device',(){ + final uuid='uuid'; + final model = 'model'; + final expected = [{'id': uuid, 'model': model}]; + fakeProcessManager.calls = [ + Call( + 'sh -c ios-deploy -c || echo "no attached devices"', + ProcessResult( + 0, + 0, + "[....] Waiting up to 5 seconds for iOS device to be connected\n[....] Found $uuid (N69uAP, $model, iphoneos, arm64) a.k.a. 'My iPhone' connected through USB.", + '')), + ]; + final iosDevices = getIosDevices(); + expect(iosDevices, expected); + fakeProcessManager.verifyCalls(); + }, overrides: { + ProcessManager: () => fakeProcessManager, + Platform: () => fakePlatform, + }); + }); } class MockProcess extends Mock implements Process {}