refactor(shorebird_cli): adjust IOSDeploy to installAndLaunchApp (#907)

This commit is contained in:
Felix Angelov
2023-07-25 14:34:42 -05:00
committed by GitHub
parent ed7eefc212
commit baa375ebb9
2 changed files with 62 additions and 32 deletions
@@ -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<int> installApp({
required String deviceId,
/// `ios-deploy --id [deviceId] --debug --bundle [bundlePath]`
Future<int> 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,
],
@@ -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);
});
});
});
}