Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ class TestFlutterApp extends IntegrationTestApp {
// Set this up now, but we don't await it yet. We want to make sure we don't
// miss it while waiting for debugPort below.
final started = waitFor(
event: FlutterDaemonConstants.appStarted.key,
event: FlutterDaemonConstants.appStartedKey,
timeout: IntegrationTestApp._appStartTimeout,
);

final debugPort = await waitFor(
event: FlutterDaemonConstants.appDebugPort.key,
event: FlutterDaemonConstants.appDebugPortKey,
timeout: IntegrationTestApp._appStartTimeout,
);
final wsUriString =
(debugPort[FlutterDaemonConstants.params.key]!
as Map<String, Object?>)[FlutterDaemonConstants.wsUri.key]
(debugPort[FlutterDaemonConstants.paramsKey]!
as Map<String, Object?>)[FlutterDaemonConstants.wsUriKey]
as String;
_vmServiceWsUri = Uri.parse(wsUriString);

Expand All @@ -63,9 +63,9 @@ class TestFlutterApp extends IntegrationTestApp {
// have already completed.
final startedResult = await started;
final params =
startedResult[FlutterDaemonConstants.params.key]!
startedResult[FlutterDaemonConstants.paramsKey]!
as Map<String, Object?>;
_currentRunningAppId = params[FlutterDaemonConstants.appId.key] as String?;
_currentRunningAppId = params[FlutterDaemonConstants.appIdKey] as String?;
}

@override
Expand All @@ -88,11 +88,7 @@ class TestFlutterApp extends IntegrationTestApp {
}

int _requestId = 1;
// ignore: avoid-dynamic, dynamic by design.
Future<dynamic> _sendFlutterDaemonRequest(
String method,
Object? params,
) async {
Future<void> _sendFlutterDaemonRequest(String method, Object? params) async {
final requestId = _requestId++;
final request = <String, dynamic>{
'id': requestId,
Expand All @@ -115,8 +111,6 @@ class TestFlutterApp extends IntegrationTestApp {
if (response['error'] != null || response['result'] == null) {
throw Exception('Unexpected error response');
}

return response['result'];
}

Future<Map<String, Object?>> waitFor({
Expand Down Expand Up @@ -159,29 +153,26 @@ class TestFlutterApp extends IntegrationTestApp {
final json = _parseFlutterResponse(line);
if (json == null) {
return;
} else if ((event != null &&
json[FlutterDaemonConstants.event.key] == event) ||
(id != null && json[FlutterDaemonConstants.id.key] == id)) {
}
final eventFromJson = json[FlutterDaemonConstants.eventKey];
if ((event != null && eventFromJson == event) ||
(id != null && json[FlutterDaemonConstants.idKey] == id)) {
await subscription.cancel();
response.complete(json);
} else if (!ignoreAppStopEvent &&
json[FlutterDaemonConstants.event.key] ==
FlutterDaemonConstants.appStop.key) {
eventFromJson == FlutterDaemonConstants.appStopKey) {
await subscription.cancel();
final error = StringBuffer();
error.write('Received app.stop event while waiting for ');
error.write(
'${event != null ? '$event event' : 'response to request $id.'}.\n\n',
);
final errorFromJson =
(json[FlutterDaemonConstants.params.key]
as Map<String, Object?>?)?[FlutterDaemonConstants.error.key];
final paramsFromJson = json[FlutterDaemonConstants.paramsKey] as Map?;
final errorFromJson = paramsFromJson?[FlutterDaemonConstants.errorKey];
if (errorFromJson != null) {
error.write('$errorFromJson\n\n');
}
final traceFromJson =
(json[FlutterDaemonConstants.params.key]
as Map<String, Object?>?)?[FlutterDaemonConstants.trace.key];
final traceFromJson = paramsFromJson?[FlutterDaemonConstants.traceKey];
if (traceFromJson != null) {
error.write('$traceFromJson\n\n');
}
Expand Down Expand Up @@ -399,26 +390,19 @@ Uri convertToWebSocketUrl({required Uri serviceProtocolUrl}) {
// TODO(kenz): consider moving these constants to devtools_shared if they are
// used outside of these integration tests. Optionally, we could consider making
// these constants where the flutter daemon is defined in flutter tools.
enum FlutterDaemonConstants {
event,
error,
id,
appId,
params,
trace,
wsUri,
pid,
appStop(nameOverride: 'app.stop'),
appStarted(nameOverride: 'app.started'),
appDebugPort(nameOverride: 'app.debugPort'),
daemonConnected(nameOverride: 'daemon.connected');

const FlutterDaemonConstants({String? nameOverride})
: _nameOverride = nameOverride;

final String? _nameOverride;

String get key => _nameOverride ?? name;
final class FlutterDaemonConstants {
static const eventKey = 'event';
static const errorKey = 'error';
static const idKey = 'id';
static const appIdKey = 'appId';
static const paramsKey = 'params';
static const traceKey = 'trace';
static const wsUriKey = 'wsUri';
static const pidKey = 'pid';
static const appStopKey = 'app.stop';
static const appStartedKey = 'app.started';
static const appDebugPortKey = 'app.debugPort';
static const daemonConnectedKey = 'daemon.connected';
}

enum TestAppDevice {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class DevToolsAppTestRunnerArgs extends IntegrationTestRunnerArgs {
: super(addExtraArgs: _addExtraArgs) {
testAppDevice =
TestAppDevice.fromArgName(
argResults[_testAppDeviceArg] ?? TestAppDevice.flutterTester.argName,
argResults.option(_testAppDeviceArg) ??
TestAppDevice.flutterTester.argName,
)!;
}

Expand All @@ -98,10 +99,10 @@ class DevToolsAppTestRunnerArgs extends IntegrationTestRunnerArgs {
/// The Vm Service URI for the test app to connect devtools to.
///
/// This value will only be used for tests with live connection.
String? get testAppUri => argResults[_testAppUriArg];
String? get testAppUri => argResults.option(_testAppUriArg);

/// Whether golden images should be updated with the result of this test run.
bool get updateGoldens => argResults[_updateGoldensArg];
bool get updateGoldens => argResults.flag(_updateGoldensArg);

static const _testAppUriArg = 'test-app-uri';
static const _testAppDeviceArg = 'test-app-device';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,37 +199,33 @@ class IntegrationTestRunnerArgs {
List<String> args, {
bool verifyValidTarget = true,
void Function(ArgParser)? addExtraArgs,
}) {
final argParser = buildArgParser(addExtraArgs: addExtraArgs);
argResults = argParser.parse(args);
rawArgs = args;

}) : rawArgs = args,
argResults = buildArgParser(addExtraArgs: addExtraArgs).parse(args) {
if (verifyValidTarget) {
final target = argResults[testTargetArg];
assert(
target != null,
'Please specify a test target (e.g. '
'--$testTargetArg=path/to/test.dart',
'Please specify a test target (e.g. --$testTargetArg=path/to/test.dart',
);
}
}

@protected
late final ArgResults argResults;
final ArgResults argResults;

late final List<String> rawArgs;
final List<String> rawArgs;

/// The path to the test target.
String? get testTarget => argResults[testTargetArg];
String? get testTarget => argResults.option(testTargetArg);

/// Whether this integration test should be run on the 'web-server' device
/// instead of 'chrome'.
bool get headless => argResults[_headlessArg];
bool get headless => argResults.flag(_headlessArg);

/// Sharding information for this test run.
({int shardNumber, int totalShards})? get shard {
final shardValue = argResults[_shardArg];
if (shardValue is String) {
final shardValue = argResults.option(_shardArg);
if (shardValue != null) {
final shardParts = shardValue.split('/');
if (shardParts.length == 2) {
final shardNumber = int.tryParse(shardParts[0]);
Expand All @@ -243,7 +239,7 @@ class IntegrationTestRunnerArgs {
}

/// Whether the help flag `-h` was passed to the integration test command.
bool get help => argResults[_helpArg];
bool get help => argResults.flag(_helpArg);

void printHelp() {
print('Run integration tests (one or many) for the Dart DevTools package.');
Expand Down
Loading