Skip to content
Open
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
11 changes: 6 additions & 5 deletions packages/flutterfire_cli/lib/src/commands/install.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ class InstallCommand extends FlutterFireCommand {
.where(
(element) => listAvailablePluginsInVersion.contains(element.name),
)
.map((plugin) => plugin.displayName)
.toList();
final displayNames = choices.map((plugin) => plugin.displayName).toList();
final defaultSelection = List<bool>.filled(choices.length, false);
for (final dependency in flutterApp!.package.dependencies) {
final enumValue = FlutterFirePlugins.values.firstWhereOrNull(
final enumValue = choices.firstWhereOrNull(
(element) => element.name == dependency,
);
if (enumValue != null) {
final index = choices.indexOf(enumValue.displayName);
final index = choices.indexOf(enumValue);
defaultSelection[index] = true;
}
}
Expand All @@ -161,11 +161,12 @@ class InstallCommand extends FlutterFireCommand {

final selectedChoices = promptMultiSelect(
'Select the Firebase plugins you would like to install',
choices,
displayNames,
defaultSelection: defaultSelection,
);
for (final index in selectedChoices) {
selectedPlugins.add(FlutterFirePlugins.values[index]);
// retrieve plugin based on the choices list
selectedPlugins.add(choices[index]);
}
return selectedPlugins;
}
Expand Down
95 changes: 94 additions & 1 deletion packages/flutterfire_cli/test/install_test.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import 'dart:convert';
import 'dart:io';

import 'package:async/async.dart';
import 'package:path/path.dart' as p;
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:test/test.dart';

import 'test_utils.dart';

Future<bool> _waitForLine(StreamQueue<String> queue, String content) async {
while (await queue.hasNext) {
final line = await queue.next;
if (line.contains(content)) return true;
}
return false;
}

void main() {
String? projectPath;
setUp(() async {
Expand Down Expand Up @@ -131,7 +141,6 @@ void main() {
Duration(minutes: 2),
),
);

test(
'Installs then use --only-pubspec-plugins flag to remove dependency',
() async {
Expand Down Expand Up @@ -189,4 +198,88 @@ void main() {
Duration(minutes: 2),
),
);
test(
'Installs from CLI',
() async {
final process = await Process.start(
'flutterfire',
[
'install',
'4.10.0',
],
workingDirectory: projectPath,
runInShell: true,
);
final stdoutLines = StreamQueue(
process.stdout
.transform(utf8.decoder) /*.transform(const LineSplitter())*/,
);

await _waitForLine(
stdoutLines,
'Select the Firebase plugins you would like to install',
);

// Core
process.stdin.write(' ');

// Analytics
process.stdin.write('\x1b[B');
process.stdin.write(' ');

// Crashlytics
process.stdin.write('\x1b[B' * 4);
process.stdin.write(' ');

// Messaging
process.stdin.write('\x1b[B' * 5);
process.stdin.write(' ');

// Performance
process.stdin.write('\x1b[B' * 2);
process.stdin.write(' ');

// Remote Config
process.stdin.write('\x1b[B');
process.stdin.write(' ');

// confirm selection
process.stdin.write('\r');

await process.stdin.flush();

final installSuccess =
await _waitForLine(stdoutLines, 'Successfully installed');
expect(installSuccess, isTrue);

// finish
await process.stdin.flush();
await process.stdin.close();

if (await process.exitCode != 0) {
final errorOutput = await process.stderr.transform(utf8.decoder).join();
fail(errorOutput);
}

final parsedPubspec = Pubspec.parse(
await File(p.join(projectPath!, 'pubspec.yaml')).readAsString(),
);

expect(parsedPubspec.dependencies['firebase_analytics'], isNotNull);
expect(parsedPubspec.dependencies['firebase_core'], isNotNull);
expect(parsedPubspec.dependencies['firebase_performance'], isNotNull);
expect(parsedPubspec.dependencies['firebase_remote_config'], isNotNull);
expect(parsedPubspec.dependencies['firebase_crashlytics'], isNotNull);
expect(parsedPubspec.dependencies['firebase_messaging'], isNotNull);

expect(parsedPubspec.dependencies['firebase_in_app_messaging'], isNull);
expect(
parsedPubspec.dependencies['firebase_ml_model_downloader'],
isNull,
);
},
timeout: const Timeout(
Duration(minutes: 2),
),
);
}
Loading