|
| 1 | +import 'dart:convert'; |
1 | 2 | import 'dart:io'; |
2 | 3 |
|
| 4 | +import 'package:async/async.dart'; |
3 | 5 | import 'package:path/path.dart' as p; |
4 | 6 | import 'package:pubspec_parse/pubspec_parse.dart'; |
5 | 7 | import 'package:test/test.dart'; |
6 | 8 |
|
7 | 9 | import 'test_utils.dart'; |
8 | 10 |
|
| 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 | + |
9 | 19 | void main() { |
10 | 20 | String? projectPath; |
11 | 21 | setUp(() async { |
@@ -131,7 +141,6 @@ void main() { |
131 | 141 | Duration(minutes: 2), |
132 | 142 | ), |
133 | 143 | ); |
134 | | - |
135 | 144 | test( |
136 | 145 | 'Installs then use --only-pubspec-plugins flag to remove dependency', |
137 | 146 | () async { |
@@ -189,4 +198,88 @@ void main() { |
189 | 198 | Duration(minutes: 2), |
190 | 199 | ), |
191 | 200 | ); |
| 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 | + ); |
192 | 285 | } |
0 commit comments