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 { ...@@ -520,6 +520,8 @@ class _ResidentWebRunner extends ResidentWebRunner {
return OperationResult(1, err.toString(), fatal: true); return OperationResult(1, err.toString(), fatal: true);
} on WipError catch (err) { } on WipError catch (err) {
return OperationResult(1, err.toString(), fatal: true); return OperationResult(1, err.toString(), fatal: true);
} on vmservice.RPCError catch (err) {
return OperationResult(1, err.toString(), fatal: true);
} finally { } finally {
status.stop(); status.stop();
} }
......
...@@ -513,54 +513,61 @@ void main() { ...@@ -513,54 +513,61 @@ void main() {
Usage: () => MockFlutterUsage(), Usage: () => MockFlutterUsage(),
})); }));
// TODO(jonahwilliams): re-enable tests once we switch back to DWDS for hot reload/restart. test('Fails non-fatally on vmservice response error for hot restart', () => testbed.run(() async {
// test('Fails on vmservice response error for hot restart', () => testbed.run(() async { _setupMocks();
// _setupMocks(); final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
// final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>(); unawaited(residentWebRunner.run(
// unawaited(residentWebRunner.run( connectionInfoCompleter: connectionInfoCompleter,
// connectionInfoCompleter: connectionInfoCompleter, ));
// )); await connectionInfoCompleter.future;
// await connectionInfoCompleter.future; when(mockVmService.callMethod('hotRestart')).thenAnswer((Invocation _) async {
// when(mockVmService.callServiceExtension('fullReload')).thenAnswer((Invocation _) async { return Response.parse(<String, Object>{'type': 'Failed'});
// return Response.parse(<String, Object>{'type': 'Failed'}); });
// }); final OperationResult result = await residentWebRunner.restart(fullRestart: false);
// final OperationResult result = await residentWebRunner.restart(fullRestart: true);
expect(result.code, 0);
// expect(result.code, 1); }));
// expect(result.message, contains('Failed'));
// })); test('Fails fatally on vmservice RpcError', () => testbed.run(() async {
_setupMocks();
// TODO(jonahwilliams): re-enable tests once we switch back to DWDS for hot reload/restart. final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
// test('Fails on vmservice response error for hot reload', () => testbed.run(() async { unawaited(residentWebRunner.run(
// _setupMocks(); connectionInfoCompleter: connectionInfoCompleter,
// final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>(); ));
// unawaited(residentWebRunner.run( await connectionInfoCompleter.future;
// connectionInfoCompleter: connectionInfoCompleter, when(mockVmService.callMethod('hotRestart')).thenThrow(RPCError('Something went wrong', 2, '123'));
// )); final OperationResult result = await residentWebRunner.restart(fullRestart: false);
// await connectionInfoCompleter.future;
// when(mockVmService.callServiceExtension('hotRestart')).thenAnswer((Invocation _) async { expect(result.code, 1);
// return Response.parse(<String, Object>{'type': 'Failed'}); expect(result.message, contains('Something went wrong'));
// }); }));
// final OperationResult result = await residentWebRunner.restart(fullRestart: false);
test('Fails fatally on vmservice WipError', () => testbed.run(() async {
// expect(result.code, 1); _setupMocks();
// expect(result.message, contains('Failed')); final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
// })); unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
// TODO(jonahwilliams): re-enable tests once we switch back to DWDS for hot reload/restart. ));
// test('Fails on vmservice RpcError', () => testbed.run(() async { await connectionInfoCompleter.future;
// _setupMocks(); when(mockVmService.callMethod('hotRestart')).thenThrow(WipError(<String, String>{}));
// final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>(); final OperationResult result = await residentWebRunner.restart(fullRestart: false);
// unawaited(residentWebRunner.run(
// connectionInfoCompleter: connectionInfoCompleter, expect(result.code, 1);
// )); }));
// await connectionInfoCompleter.future;
// when(mockVmService.callServiceExtension('hotRestart')).thenThrow(RPCError('', 2, '123')); test('Fails fatally on vmservice Exception', () => testbed.run(() async {
// final OperationResult result = await residentWebRunner.restart(fullRestart: false); _setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
// expect(result.code, 1); unawaited(residentWebRunner.run(
// expect(result.message, contains('Page requires refresh')); 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 { test('printHelp without details has web warning', () => testbed.run(() async {
residentWebRunner.printHelp(details: false); 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