"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:
yjbanov
2016-02-19 16:31:34 -08:00
parent 73ea415a5a
commit a2b1bd4673
10 changed files with 283 additions and 23 deletions

View File

@@ -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();
}

View File

@@ -40,7 +40,7 @@ main() {
tearDown(() async {
await logSub.cancel();
vmServiceConnectFunction = vmServiceClientConnectFunction;
restoreVmServiceConnectFunction();
});
test('connects to isolate paused at start', () async {