From baa375ebb9e118b36ab663edae2e3a307fdd0a19 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 25 Jul 2023 14:34:42 -0500 Subject: [PATCH] refactor(shorebird_cli): adjust `IOSDeploy` to `installAndLaunchApp` (#907) --- .../shorebird_cli/lib/src/ios_deploy.dart | 14 ++-- .../test/src/ios_deploy_test.dart | 80 +++++++++++++------ 2 files changed, 62 insertions(+), 32 deletions(-) diff --git a/packages/shorebird_cli/lib/src/ios_deploy.dart b/packages/shorebird_cli/lib/src/ios_deploy.dart index a5ec072e..cabf7ac6 100644 --- a/packages/shorebird_cli/lib/src/ios_deploy.dart +++ b/packages/shorebird_cli/lib/src/ios_deploy.dart @@ -5,13 +5,15 @@ import 'package:shorebird_cli/src/shorebird_environment.dart'; /// Wrapper around the `ios-deploy` command cached by the Flutter tool. /// https://github.com/ios-control/ios-deploy class IOSDeploy { - /// Installs the .app file at [bundlePath] to the device identified by [deviceId]. + /// Installs the .app file at [bundlePath] + /// to the device identified by [deviceId] + /// and attaches the debugger. /// /// Uses ios-deploy and returns the exit code. - /// `ios-deploy --id [deviceId] --bundle [bundlePath]` - Future installApp({ - required String deviceId, + /// `ios-deploy --id [deviceId] --debug --bundle [bundlePath]` + Future installAndLaunchApp({ required String bundlePath, + String? deviceId, }) async { final iosDeployExecutable = p.join( ShorebirdEnvironment.flutterDirectory.path, @@ -24,8 +26,8 @@ class IOSDeploy { final result = await process.run( iosDeployExecutable, [ - '--id', - deviceId, + '--debug', + if (deviceId != null) ...['--id', deviceId], '--bundle', bundlePath, ], diff --git a/packages/shorebird_cli/test/src/ios_deploy_test.dart b/packages/shorebird_cli/test/src/ios_deploy_test.dart index 31a86326..7997e2a0 100644 --- a/packages/shorebird_cli/test/src/ios_deploy_test.dart +++ b/packages/shorebird_cli/test/src/ios_deploy_test.dart @@ -25,32 +25,60 @@ void main() { iosDeploy = IOSDeploy(); }); - test('executes correct command', () async { - const processResult = ShorebirdProcessResult( - exitCode: 0, - stdout: '', - stderr: '', - ); - when( - () => process.run(any(), any()), - ).thenAnswer((_) async => processResult); - const deviceId = 'test-device-id'; - const bundlePath = 'test-bundle-path'; - final result = await runWithOverrides( - () => iosDeploy.installApp( - deviceId: deviceId, - bundlePath: bundlePath, - ), - ); - expect(result, equals(processResult.exitCode)); - verify( - () => process.run(any(that: endsWith('ios-deploy')), [ - '--id', - deviceId, - '--bundle', - bundlePath, - ]), - ).called(1); + group('installAndLaunchApp', () { + test('executes correct command w/deviceId', () async { + const processResult = ShorebirdProcessResult( + exitCode: 0, + stdout: '', + stderr: '', + ); + when( + () => process.run(any(), any()), + ).thenAnswer((_) async => processResult); + const deviceId = 'test-device-id'; + const bundlePath = 'test-bundle-path'; + final result = await runWithOverrides( + () => iosDeploy.installAndLaunchApp( + deviceId: deviceId, + bundlePath: bundlePath, + ), + ); + expect(result, equals(processResult.exitCode)); + verify( + () => process.run(any(that: endsWith('ios-deploy')), [ + '--debug', + '--id', + deviceId, + '--bundle', + bundlePath, + ]), + ).called(1); + }); + + test('executes correct command w/out deviceId', () async { + const processResult = ShorebirdProcessResult( + exitCode: 0, + stdout: '', + stderr: '', + ); + when( + () => process.run(any(), any()), + ).thenAnswer((_) async => processResult); + const bundlePath = 'test-bundle-path'; + final result = await runWithOverrides( + () => iosDeploy.installAndLaunchApp( + bundlePath: bundlePath, + ), + ); + expect(result, equals(processResult.exitCode)); + verify( + () => process.run(any(that: endsWith('ios-deploy')), [ + '--debug', + '--bundle', + bundlePath, + ]), + ).called(1); + }); }); }); }