Unverified Commit b5cd3ce8 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] test and catch more exception types in web runner (#53183)

parent d6614dba
......@@ -520,6 +520,8 @@ class _ResidentWebRunner extends ResidentWebRunner {
return OperationResult(1, err.toString(), fatal: true);
} on WipError catch (err) {
return OperationResult(1, err.toString(), fatal: true);
} on vmservice.RPCError catch (err) {
return OperationResult(1, err.toString(), fatal: true);
} finally {
status.stop();
}
......
......@@ -513,54 +513,61 @@ void main() {
Usage: () => MockFlutterUsage(),
}));
// TODO(jonahwilliams): re-enable tests once we switch back to DWDS for hot reload/restart.
// test('Fails on vmservice response error for hot restart', () => testbed.run(() async {
// _setupMocks();
// final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
// unawaited(residentWebRunner.run(
// connectionInfoCompleter: connectionInfoCompleter,
// ));
// await connectionInfoCompleter.future;
// when(mockVmService.callServiceExtension('fullReload')).thenAnswer((Invocation _) async {
// return Response.parse(<String, Object>{'type': 'Failed'});
// });
// final OperationResult result = await residentWebRunner.restart(fullRestart: true);
// expect(result.code, 1);
// expect(result.message, contains('Failed'));
// }));
// TODO(jonahwilliams): re-enable tests once we switch back to DWDS for hot reload/restart.
// test('Fails on vmservice response error for hot reload', () => testbed.run(() async {
// _setupMocks();
// final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
// unawaited(residentWebRunner.run(
// connectionInfoCompleter: connectionInfoCompleter,
// ));
// await connectionInfoCompleter.future;
// when(mockVmService.callServiceExtension('hotRestart')).thenAnswer((Invocation _) async {
// return Response.parse(<String, Object>{'type': 'Failed'});
// });
// final OperationResult result = await residentWebRunner.restart(fullRestart: false);
// expect(result.code, 1);
// expect(result.message, contains('Failed'));
// }));
// TODO(jonahwilliams): re-enable tests once we switch back to DWDS for hot reload/restart.
// test('Fails on vmservice RpcError', () => testbed.run(() async {
// _setupMocks();
// final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
// unawaited(residentWebRunner.run(
// connectionInfoCompleter: connectionInfoCompleter,
// ));
// await connectionInfoCompleter.future;
// when(mockVmService.callServiceExtension('hotRestart')).thenThrow(RPCError('', 2, '123'));
// final OperationResult result = await residentWebRunner.restart(fullRestart: false);
// expect(result.code, 1);
// expect(result.message, contains('Page requires refresh'));
// }));
test('Fails non-fatally on vmservice response error for hot restart', () => testbed.run(() async {
_setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
));
await connectionInfoCompleter.future;
when(mockVmService.callMethod('hotRestart')).thenAnswer((Invocation _) async {
return Response.parse(<String, Object>{'type': 'Failed'});
});
final OperationResult result = await residentWebRunner.restart(fullRestart: false);
expect(result.code, 0);
}));
test('Fails fatally on vmservice RpcError', () => testbed.run(() async {
_setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
));
await connectionInfoCompleter.future;
when(mockVmService.callMethod('hotRestart')).thenThrow(RPCError('Something went wrong', 2, '123'));
final OperationResult result = await residentWebRunner.restart(fullRestart: false);
expect(result.code, 1);
expect(result.message, contains('Something went wrong'));
}));
test('Fails fatally on vmservice WipError', () => testbed.run(() async {
_setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
));
await connectionInfoCompleter.future;
when(mockVmService.callMethod('hotRestart')).thenThrow(WipError(<String, String>{}));
final OperationResult result = await residentWebRunner.restart(fullRestart: false);
expect(result.code, 1);
}));
test('Fails fatally on vmservice Exception', () => testbed.run(() async {
_setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
));
await connectionInfoCompleter.future;
when(mockVmService.callMethod('hotRestart')).thenThrow(Exception('Something went wrong'));
final OperationResult result = await residentWebRunner.restart(fullRestart: false);
expect(result.code, 1);
expect(result.message, contains('Something went wrong'));
}));
test('printHelp without details has web warning', () => testbed.run(() async {
residentWebRunner.printHelp(details: false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment