[flutter_tools] Include mode in app.start event, and forward app.start to DAP clients (#121239)
[flutter_tools] Include mode in app.start event, and forward app.start to DAP clients
This commit is contained in:
@@ -107,16 +107,18 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
|
||||
// Simulate the app starting by triggering handling of events that Flutter
|
||||
// would usually write to stdout.
|
||||
if (simulateAppStarted) {
|
||||
simulateStdoutMessage(<String, Object?>{
|
||||
'event': 'app.started',
|
||||
});
|
||||
simulateStdoutMessage(<String, Object?>{
|
||||
'event': 'app.start',
|
||||
'params': <String, Object?>{
|
||||
'appId': 'TEST',
|
||||
'supportsRestart': supportsRestart,
|
||||
'deviceId': 'flutter-tester',
|
||||
'mode': 'debug',
|
||||
}
|
||||
});
|
||||
simulateStdoutMessage(<String, Object?>{
|
||||
'event': 'app.started',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -452,6 +452,30 @@ void main() {
|
||||
await dap.client.terminate();
|
||||
});
|
||||
|
||||
testWithoutContext('provides appStarted events to the client', () async {
|
||||
final BasicProject project = BasicProject();
|
||||
await project.setUpIn(tempDir);
|
||||
|
||||
// Launch the app and wait for it to send a 'flutter.appStart' event.
|
||||
final Future<Event> appStartFuture = dap.client.event('flutter.appStart');
|
||||
await Future.wait(<Future<void>>[
|
||||
appStartFuture,
|
||||
dap.client.start(
|
||||
launch: () => dap.client.launch(
|
||||
cwd: project.dir.path,
|
||||
toolArgs: <String>['-d', 'flutter-tester'],
|
||||
),
|
||||
),
|
||||
], eagerError: true);
|
||||
|
||||
await dap.client.terminate();
|
||||
|
||||
final Event appStart = await appStartFuture;
|
||||
final Map<String, Object?> params = appStart.body! as Map<String, Object?>;
|
||||
expect(params['deviceId'], 'flutter-tester');
|
||||
expect(params['mode'], 'debug');
|
||||
});
|
||||
|
||||
testWithoutContext('provides appStarted events to the client', () async {
|
||||
final BasicProject project = BasicProject();
|
||||
await project.setUpIn(tempDir);
|
||||
|
||||
@@ -68,4 +68,10 @@ void main() {
|
||||
matches: isNotEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('reports deviceId and mode in app.start event', () async {
|
||||
await flutter.run();
|
||||
expect(flutter.currentRunningDeviceId, 'flutter-tester');
|
||||
expect(flutter.currentRunningMode, 'debug');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -496,6 +496,11 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
});
|
||||
|
||||
String? _currentRunningAppId;
|
||||
String? _currentRunningDeviceId;
|
||||
String? _currentRunningMode;
|
||||
|
||||
String? get currentRunningDeviceId => _currentRunningDeviceId;
|
||||
String? get currentRunningMode => _currentRunningMode;
|
||||
|
||||
Future<void> run({
|
||||
bool withDebugger = false,
|
||||
@@ -611,6 +616,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
|
||||
// Set this up now, but we don't wait it yet. We want to make sure we don't
|
||||
// miss it while waiting for debugPort below.
|
||||
final Future<Map<String, Object?>> start = _waitFor(event: 'app.start', timeout: appStartTimeout);
|
||||
final Future<Map<String, Object?>> started = _waitFor(event: 'app.started', timeout: appStartTimeout);
|
||||
|
||||
if (withDebugger) {
|
||||
@@ -630,9 +636,13 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
_attachPort = attachPort;
|
||||
}
|
||||
|
||||
// Now await the started event; if it had already happened the future will
|
||||
// Now await the start/started events; if it had already happened the future will
|
||||
// have already completed.
|
||||
_currentRunningAppId = ((await started)['params'] as Map<String, Object?>?)?['appId'] as String?;
|
||||
final Map<String, Object?>? startParams = (await start)['params'] as Map<String, Object?>?;
|
||||
final Map<String, Object?>? startedParams = (await started)['params'] as Map<String, Object?>?;
|
||||
_currentRunningAppId = startedParams?['appId'] as String?;
|
||||
_currentRunningDeviceId = startParams?['deviceId'] as String?;
|
||||
_currentRunningMode = startParams?['mode'] as String?;
|
||||
prematureExitGuard.complete();
|
||||
} on Exception catch (error, stackTrace) {
|
||||
prematureExitGuard.completeError(Exception(error.toString()), stackTrace);
|
||||
|
||||
Reference in New Issue
Block a user