Skip to content

Commit 2f7e83e

Browse files
committed
add test
1 parent f30f9a5 commit 2f7e83e

1 file changed

Lines changed: 94 additions & 1 deletion

File tree

packages/flutterfire_cli/test/install_test.dart

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
import 'dart:convert';
12
import 'dart:io';
23

4+
import 'package:async/async.dart';
35
import 'package:path/path.dart' as p;
46
import 'package:pubspec_parse/pubspec_parse.dart';
57
import 'package:test/test.dart';
68

79
import 'test_utils.dart';
810

11+
Future<bool> _waitForLine(StreamQueue<String> queue, String content) async {
12+
while (await queue.hasNext) {
13+
final line = await queue.next;
14+
if (line.contains(content)) return true;
15+
}
16+
return false;
17+
}
18+
919
void main() {
1020
String? projectPath;
1121
setUp(() async {
@@ -131,7 +141,6 @@ void main() {
131141
Duration(minutes: 2),
132142
),
133143
);
134-
135144
test(
136145
'Installs then use --only-pubspec-plugins flag to remove dependency',
137146
() async {
@@ -189,4 +198,88 @@ void main() {
189198
Duration(minutes: 2),
190199
),
191200
);
201+
test(
202+
'Installs from CLI',
203+
() async {
204+
final process = await Process.start(
205+
'flutterfire',
206+
[
207+
'install',
208+
'4.10.0',
209+
],
210+
workingDirectory: projectPath,
211+
runInShell: true,
212+
);
213+
final stdoutLines = StreamQueue(
214+
process.stdout
215+
.transform(utf8.decoder) /*.transform(const LineSplitter())*/,
216+
);
217+
218+
await _waitForLine(
219+
stdoutLines,
220+
'Select the Firebase plugins you would like to install',
221+
);
222+
223+
// Core
224+
process.stdin.write(' ');
225+
226+
// Analytics
227+
process.stdin.write('\x1b[B');
228+
process.stdin.write(' ');
229+
230+
// Crashlytics
231+
process.stdin.write('\x1b[B' * 4);
232+
process.stdin.write(' ');
233+
234+
// Messaging
235+
process.stdin.write('\x1b[B' * 5);
236+
process.stdin.write(' ');
237+
238+
// Performance
239+
process.stdin.write('\x1b[B' * 2);
240+
process.stdin.write(' ');
241+
242+
// Remote Config
243+
process.stdin.write('\x1b[B');
244+
process.stdin.write(' ');
245+
246+
// confirm selection
247+
process.stdin.write('\r');
248+
249+
await process.stdin.flush();
250+
251+
final installSuccess =
252+
await _waitForLine(stdoutLines, 'Successfully installed');
253+
expect(installSuccess, isTrue);
254+
255+
// finish
256+
await process.stdin.flush();
257+
await process.stdin.close();
258+
259+
if (await process.exitCode != 0) {
260+
final errorOutput = await process.stderr.transform(utf8.decoder).join();
261+
fail(errorOutput);
262+
}
263+
264+
final parsedPubspec = Pubspec.parse(
265+
await File(p.join(projectPath!, 'pubspec.yaml')).readAsString(),
266+
);
267+
268+
expect(parsedPubspec.dependencies['firebase_analytics'], isNotNull);
269+
expect(parsedPubspec.dependencies['firebase_core'], isNotNull);
270+
expect(parsedPubspec.dependencies['firebase_performance'], isNotNull);
271+
expect(parsedPubspec.dependencies['firebase_remote_config'], isNotNull);
272+
expect(parsedPubspec.dependencies['firebase_crashlytics'], isNotNull);
273+
expect(parsedPubspec.dependencies['firebase_messaging'], isNotNull);
274+
275+
expect(parsedPubspec.dependencies['firebase_in_app_messaging'], isNull);
276+
expect(
277+
parsedPubspec.dependencies['firebase_ml_model_downloader'],
278+
isNull,
279+
);
280+
},
281+
timeout: const Timeout(
282+
Duration(minutes: 2),
283+
),
284+
);
192285
}

0 commit comments

Comments
 (0)