feat(shorebird_cli): add IOSDeploy (#900)

This commit is contained in:
Felix Angelov
2023-07-25 09:04:34 -05:00
committed by GitHub
parent 79abf9b259
commit ddd1513dd8
2 changed files with 91 additions and 0 deletions
@@ -0,0 +1,35 @@
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/process.dart';
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].
///
/// Uses ios-deploy and returns the exit code.
/// `ios-deploy --id [deviceId] --bundle [bundlePath]`
Future<int> installApp({
required String deviceId,
required String bundlePath,
}) async {
final iosDeployExecutable = p.join(
ShorebirdEnvironment.flutterDirectory.path,
'bin',
'cache',
'artifacts',
'ios-deploy',
'ios-deploy',
);
final result = await process.run(
iosDeployExecutable,
[
'--id',
deviceId,
'--bundle',
bundlePath,
],
);
return result.exitCode;
}
}
@@ -0,0 +1,56 @@
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/ios_deploy.dart';
import 'package:shorebird_cli/src/process.dart';
import 'package:test/test.dart';
class _MockShorebirdProcess extends Mock implements ShorebirdProcess {}
void main() {
group(IOSDeploy, () {
late ShorebirdProcess process;
late IOSDeploy iosDeploy;
R runWithOverrides<R>(R Function() body) {
return runScoped(
body,
values: {
processRef.overrideWith(() => process),
},
);
}
setUp(() {
process = _MockShorebirdProcess();
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);
});
});
}