feat(shorebird_cli): add IOSDeploy (#900)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user