Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shorebird_cli): shorebird init handles missing iOS project on non-macos host #983

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/shorebird_cli/lib/src/commands/init_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ For more information about Shorebird, visit ${link(uri: Uri.parse('https://shore
// When running on a non-macOS platform, we can't use `xcodebuild` to
// detect flavors so we fallback to looking for schemes in xcschemes.
// Note: this appears to be identical to the behavior of `xcodebuild`.
final iosDir = Directory(p.join(projectPath, 'ios'));
if (!iosDir.existsSync()) return null;
final xcschemesDir = Directory(
p.join(
projectPath,
'ios',
iosDir.path,
'Runner.xcodeproj',
'xcshareddata',
'xcschemes',
Expand Down
26 changes: 21 additions & 5 deletions packages/shorebird_cli/test/src/commands/init_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''',
when(() => platform.isMacOS).thenReturn(false);
});

test('throws software error when unable to detect schemes (non-macos)',
() async {
test('throws software error when unable to detect schemes', () async {
final tempDir = Directory.systemTemp.createTempSync();
File(
p.join(tempDir.path, 'pubspec.yaml'),
).writeAsStringSync(pubspecYamlContent);
Directory(p.join(tempDir.path, 'ios')).createSync(recursive: true);
final exitCode = await IOOverrides.runZoned(
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
Expand All @@ -279,8 +279,24 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''',
verifyNever(() => xcodeBuild.list(any()));
});

test('creates shorebird for an app without flavors (non-macos)',
() async {
test('creates shorebird for an android-only app', () async {
final tempDir = Directory.systemTemp.createTempSync();
File(
p.join(tempDir.path, 'pubspec.yaml'),
).writeAsStringSync(pubspecYamlContent);
final exitCode = await IOOverrides.runZoned(
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(
File(p.join(tempDir.path, 'shorebird.yaml')).readAsStringSync(),
contains('app_id: $appId'),
);
expect(exitCode, equals(ExitCode.success.code));
verifyNever(() => xcodeBuild.list(any()));
});

test('creates shorebird for an app without flavors', () async {
final tempDir = Directory.systemTemp.createTempSync();
when(
() => gradlew.productFlavors(any()),
Expand Down Expand Up @@ -310,7 +326,7 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''',
verifyNever(() => xcodeBuild.list(any()));
});

test('creates shorebird for an app with flavors (non-macos)', () async {
test('creates shorebird for an app with flavors', () async {
const appIds = ['test-appId-1', 'test-appId-2'];
var index = 0;
when(
Expand Down