Commit 83296e74 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by Danny Tuppeny

Pass --run-forever to flutter-tester to ensure it doesn't prematurely quit

Without this, flutter-tester quits immediately after executing main().
parent 61c71718
...@@ -84,6 +84,9 @@ class FlutterTesterDevice extends Device { ...@@ -84,6 +84,9 @@ class FlutterTesterDevice extends Device {
@override @override
bool isSupported() => true; bool isSupported() => true;
bool _isRunning = false;
bool get isRunning => _isRunning;
@override @override
Future<LaunchResult> startApp( Future<LaunchResult> startApp(
ApplicationPackage package, { ApplicationPackage package, {
...@@ -109,6 +112,7 @@ class FlutterTesterDevice extends Device { ...@@ -109,6 +112,7 @@ class FlutterTesterDevice extends Device {
final List<String> command = <String>[ final List<String> command = <String>[
shellPath, shellPath,
'--run-forever',
'--non-interactive', '--non-interactive',
'--enable-dart-profiling', '--enable-dart-profiling',
'--packages=${PackageMap.globalPackagesPath}', '--packages=${PackageMap.globalPackagesPath}',
...@@ -147,7 +151,9 @@ class FlutterTesterDevice extends Device { ...@@ -147,7 +151,9 @@ class FlutterTesterDevice extends Device {
try { try {
printTrace(command.join(' ')); printTrace(command.join(' '));
_isRunning = true;
_process = await processManager.start(command); _process = await processManager.start(command);
_process.exitCode.then((_) => _isRunning = false);
_process.stdout _process.stdout
.transform(utf8.decoder) .transform(utf8.decoder)
.transform(const LineSplitter()) .transform(const LineSplitter())
......
...@@ -3,14 +3,18 @@ ...@@ -3,14 +3,18 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/process_manager.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/tester/flutter_tester.dart'; import 'package:flutter_tools/src/tester/flutter_tester.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
void main() { void main() {
...@@ -70,6 +74,39 @@ void main() { ...@@ -70,6 +74,39 @@ void main() {
expect(await device.stopApp(null), isTrue); expect(await device.stopApp(null), isTrue);
}); });
testUsingContext('keeps running', () async {
_writePubspec();
_writePackages();
await _getPackages();
final String mainPath = fs.path.join('lib', 'main.dart');
_writeFile(mainPath, r'''
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
home: new Container(),
);
}
}
''');
final LaunchResult result = await start(mainPath);
expect(result.started, isTrue);
expect(result.observatoryUri, isNotNull);
await new Future<void>.delayed(const Duration(seconds: 3));
expect(device.isRunning, true);
expect(await device.stopApp(null), isTrue);
});
}); });
} }
...@@ -93,3 +130,16 @@ dependencies: ...@@ -93,3 +130,16 @@ dependencies:
sdk: flutter sdk: flutter
'''); ''');
} }
Future<void> _getPackages() async {
final List<String> command = <String>[
fs.path.join(getFlutterRoot(), 'bin', 'flutter'),
'packages',
'get'
];
final Process process = await processManager.start(command);
process.stderr.transform(utf8.decoder).listen(print);
final int exitCode = await process.exitCode;
if (exitCode != 0)
throw new Exception('flutter packages get failed');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment