"flutter drive" command
Runs a test app and a driver test simultaneously, then stops the app. Usage: ``` flutter drive --target=/path/to/test/app.dart ``` This command will look for `/path/to/test/app_test.dart` by convention. We will expand into other ways of discovering tests in the future.
This commit is contained in:
@@ -12,25 +12,12 @@ import 'gesture.dart';
|
||||
import 'health.dart';
|
||||
import 'message.dart';
|
||||
|
||||
/// A function that connects to a Dart VM service given the [url].
|
||||
typedef Future<VMServiceClient> VMServiceConnectFunction(String url);
|
||||
|
||||
/// Connects to a real Dart VM service using the [VMServiceClient].
|
||||
final VMServiceConnectFunction vmServiceClientConnectFunction =
|
||||
VMServiceClient.connect;
|
||||
|
||||
/// The connection function used by [FlutterDriver.connect].
|
||||
///
|
||||
/// Overwrite this function if you require a different method for connecting to
|
||||
/// the VM service.
|
||||
VMServiceConnectFunction vmServiceConnectFunction =
|
||||
vmServiceClientConnectFunction;
|
||||
final Logger _log = new Logger('FlutterDriver');
|
||||
|
||||
/// Drives a Flutter Application running in another process.
|
||||
class FlutterDriver {
|
||||
|
||||
static const String _flutterExtensionMethod = 'ext.flutter_driver';
|
||||
static final Logger _log = new Logger('FlutterDriver');
|
||||
|
||||
/// Connects to a Flutter application.
|
||||
///
|
||||
@@ -174,3 +161,42 @@ class FlutterDriver {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/// A function that connects to a Dart VM service given the [url].
|
||||
typedef Future<VMServiceClient> VMServiceConnectFunction(String url);
|
||||
|
||||
/// The connection function used by [FlutterDriver.connect].
|
||||
///
|
||||
/// Overwrite this function if you require a custom method for connecting to
|
||||
/// the VM service.
|
||||
VMServiceConnectFunction vmServiceConnectFunction = _waitAndConnect;
|
||||
|
||||
/// Restores [vmServiceConnectFunction] to its default value.
|
||||
void restoreVmServiceConnectFunction() {
|
||||
vmServiceConnectFunction = _waitAndConnect;
|
||||
}
|
||||
|
||||
/// Waits for a real Dart VM service to become available, then connects using
|
||||
/// the [VMServiceClient].
|
||||
///
|
||||
/// Times out after 30 seconds.
|
||||
Future<VMServiceClient> _waitAndConnect(String url) async {
|
||||
Stopwatch timer = new Stopwatch();
|
||||
Future<VMServiceClient> attemptConnection() {
|
||||
return VMServiceClient.connect(url)
|
||||
.catchError((e) async {
|
||||
if (timer.elapsed < const Duration(seconds: 30)) {
|
||||
_log.info('Waiting for application to start');
|
||||
await new Future.delayed(const Duration(seconds: 1));
|
||||
return attemptConnection();
|
||||
} else {
|
||||
_log.critical(
|
||||
'Application has not started in 30 seconds. '
|
||||
'Giving up.'
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
return attemptConnection();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ main() {
|
||||
|
||||
tearDown(() async {
|
||||
await logSub.cancel();
|
||||
vmServiceConnectFunction = vmServiceClientConnectFunction;
|
||||
restoreVmServiceConnectFunction();
|
||||
});
|
||||
|
||||
test('connects to isolate paused at start', () async {
|
||||
|
||||
Reference in New Issue
Block a user