Skip to content
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
4 changes: 2 additions & 2 deletions packages/shorebird_tests/test/android_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void main() {
testWithShorebirdProject(
'correctly changes the app id',
(projectDirectory) async {
projectDirectory.addAndroidFlavors();
await projectDirectory.addProjectFlavors();
projectDirectory.addShorebirdFlavors();

await projectDirectory.runFlutterBuildApk(flavor: 'internal');
Expand All @@ -64,7 +64,7 @@ void main() {
'correctly changes the app id and adds the public key',
(projectDirectory) async {
const base64PublicKey = 'public_123';
projectDirectory.addAndroidFlavors();
await projectDirectory.addProjectFlavors();
projectDirectory.addShorebirdFlavors();

await projectDirectory.runFlutterBuildApk(
Expand Down
49 changes: 45 additions & 4 deletions packages/shorebird_tests/test/ios_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
await projectDirectory.runFlutterBuildIos();

expect(projectDirectory.iosArchiveFile().existsSync(), isTrue);
expect(projectDirectory.getGeneratedIoShorebirdYaml(), completes);
expect(projectDirectory.getGeneratedIosShorebirdYaml(), completes);
});

group('when passing the public key through the environment variable', () {
Expand All @@ -27,14 +27,13 @@ void main() {
);

final generatedYaml =
await projectDirectory.getGeneratedIoShorebirdYaml();
await projectDirectory.getGeneratedIosShorebirdYaml();

expect(
generatedYaml.keys,
containsAll(originalYaml.keys),
);

print(generatedYaml);
expect(
generatedYaml['patch_public_key'],
equals(base64PublicKey),
Expand All @@ -43,7 +42,49 @@ void main() {
);
});

// TODO(erickzanardo): Add tests for flavors.
group('when building with a flavor', () {
testWithShorebirdProject(
'correctly changes the app id',
(projectDirectory) async {
await projectDirectory.addProjectFlavors();
projectDirectory.addShorebirdFlavors();

await projectDirectory.runFlutterBuildIos(flavor: 'internal');

final generatedYaml =
await projectDirectory.getGeneratedIosShorebirdYaml();

expect(generatedYaml['app_id'], equals('internal_123'));
},
);

group('when public key passed through environment variable', () {
testWithShorebirdProject(
'correctly changes the app id and adds the public key',
(projectDirectory) async {
const base64PublicKey = 'public_123';
await projectDirectory.addProjectFlavors();
projectDirectory.addShorebirdFlavors();

await projectDirectory.runFlutterBuildIos(
flavor: 'internal',
environment: {
'SHOREBIRD_PUBLIC_KEY': base64PublicKey,
},
);

final generatedYaml =
await projectDirectory.getGeneratedIosShorebirdYaml();

expect(generatedYaml['app_id'], equals('internal_123'));
expect(
generatedYaml['patch_public_key'],
equals(base64PublicKey),
);
},
);
});
});
},
testOn: 'mac-os',
);
Expand Down
82 changes: 50 additions & 32 deletions packages/shorebird_tests/test/shorebird_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Future<ProcessResult> _runFlutterCommand(
List<String> arguments, {
required Directory workingDirectory,
Map<String, String>? environment,
}) async {
}) {
return Process.run(
_flutterBinaryFile.absolute.path,
arguments,
Expand Down Expand Up @@ -110,42 +110,59 @@ extension ShorebirdProjectDirectoryOnDirectory on Directory {
path.join(this.path, 'android', 'app', 'build.gradle'),
);

void addAndroidFlavors() {
// TODO(erickzanardo): Maybe in the future make this more dynamic
// and allow the user to pass the flavors, but it is good for now.
const flavors = '''
flavorDimensions "track"
productFlavors {
playStore {
dimension "track"
applicationIdSuffix ".ps"
}
internal {
dimension "track"
applicationIdSuffix ".internal"
}
global {
dimension "track"
applicationIdSuffix ".global"
}
}
''';
Future<void> addPubDependency(String name, {bool dev = false}) {
return _runFlutterCommand(
['pub', 'add', if (dev) '--dev', name],
workingDirectory: this,
);
}

final currentGradleContent = appGradleFile.readAsStringSync();
appGradleFile.writeAsStringSync(
'''
${currentGradleContent.replaceFirst(
' buildTypes {',
' $flavors\n buildTypes {',
)}
''',
Future<void> addProjectFlavors() async {
await addPubDependency('flutter_flavorizr', dev: true);

await File(
path.join(
this.path,
'flavorizr.yaml',
),
).writeAsString('''
flavors:
playStore:
app:
name: "App"

android:
applicationId: "com.example.shorebird_test"
ios:
bundleId: "com.example.shorebird_test"
internal:
app:
name: "App (Internal)"

android:
applicationId: "com.example.shorebird_test.internal"
ios:
bundleId: "com.example.shorebird_test.internal"
global:
app:
name: "App (Global)"

android:
applicationId: "com.example.shorebird_test.global"
ios:
bundleId: "com.example.shorebird_test.global"
''');

await _runFlutterCommand(
['pub', 'run', 'flutter_flavorizr'],
workingDirectory: this,
);
}

void addShorebirdFlavors() {
const flavors = '''
flavors:
global: global_123
global: global_123
internal: internal_123
playStore: playStore_123
''';
Expand Down Expand Up @@ -179,11 +196,12 @@ $flavors

Future<void> runFlutterBuildIos({
Map<String, String>? environment,
String? flavor,
}) async {
final result = await _runFlutterCommand(
// The projects used to test are generated on spot, to make it simpler we don't
// configure any apple accounts on it, so we skip code signing here.
['build', 'ipa', '--no-codesign'],
['build', 'ipa', '--no-codesign', if (flavor != null) '--flavor=$flavor'],
workingDirectory: this,
environment: environment,
);
Expand Down Expand Up @@ -233,7 +251,7 @@ $flavors
return loadYaml(yamlString) as YamlMap;
}

Future<YamlMap> getGeneratedIoShorebirdYaml() async {
Future<YamlMap> getGeneratedIosShorebirdYaml() async {
final yamlString = File(
path.join(
iosArchiveFile().path,
Expand Down