Pass --run-forever to flutter-tester to ensure it doesn't prematurely quit
Without this, flutter-tester quits immediately after executing main().
This commit is contained in:
committed by
Danny Tuppeny
parent
61c7171872
commit
83296e74a1
@@ -84,6 +84,9 @@ class FlutterTesterDevice extends Device {
|
||||
@override
|
||||
bool isSupported() => true;
|
||||
|
||||
bool _isRunning = false;
|
||||
bool get isRunning => _isRunning;
|
||||
|
||||
@override
|
||||
Future<LaunchResult> startApp(
|
||||
ApplicationPackage package, {
|
||||
@@ -109,6 +112,7 @@ class FlutterTesterDevice extends Device {
|
||||
|
||||
final List<String> command = <String>[
|
||||
shellPath,
|
||||
'--run-forever',
|
||||
'--non-interactive',
|
||||
'--enable-dart-profiling',
|
||||
'--packages=${PackageMap.globalPackagesPath}',
|
||||
@@ -147,7 +151,9 @@ class FlutterTesterDevice extends Device {
|
||||
try {
|
||||
printTrace(command.join(' '));
|
||||
|
||||
_isRunning = true;
|
||||
_process = await processManager.start(command);
|
||||
_process.exitCode.then((_) => _isRunning = false);
|
||||
_process.stdout
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
|
||||
@@ -3,14 +3,18 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:file/file.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/device.dart';
|
||||
import 'package:flutter_tools/src/tester/flutter_tester.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
void main() {
|
||||
@@ -70,6 +74,39 @@ void main() {
|
||||
|
||||
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:
|
||||
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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user