From 7f46b261c8e901d12d4145d85a3fc554f7ace8d1 Mon Sep 17 00:00:00 2001 From: Dominik Toton Date: Wed, 5 Jun 2024 11:32:31 +0200 Subject: [PATCH] refactor: cleanup boostrap --- catalyst_voices/integration_test/common.dart | 4 ++-- catalyst_voices/lib/configs/bootstrap.dart | 13 +++++++++++++ catalyst_voices/lib/configs/main_qa_patrol.dart | 10 ---------- 3 files changed, 15 insertions(+), 12 deletions(-) delete mode 100644 catalyst_voices/lib/configs/main_qa_patrol.dart diff --git a/catalyst_voices/integration_test/common.dart b/catalyst_voices/integration_test/common.dart index 54ea707a26..8e1e605a78 100644 --- a/catalyst_voices/integration_test/common.dart +++ b/catalyst_voices/integration_test/common.dart @@ -1,6 +1,6 @@ import 'package:catalyst_voices/app/app.dart'; import 'package:catalyst_voices/app/view/app_page.dart'; -import 'package:catalyst_voices/configs/main_qa_patrol.dart' as app; +import 'package:catalyst_voices/configs/bootstrap.dart' as app; import 'package:flutter_test/flutter_test.dart'; import 'package:patrol/patrol.dart'; @@ -12,7 +12,7 @@ const _nativeAutomatorConfig = NativeAutomatorConfig( ); Future createApp(PatrolIntegrationTester $) async { - await app.main(); + await app.bootstrapForTests(); await $.pumpWidgetAndSettle(const App()); } diff --git a/catalyst_voices/lib/configs/bootstrap.dart b/catalyst_voices/lib/configs/bootstrap.dart index fc4621f63a..6ac5095971 100644 --- a/catalyst_voices/lib/configs/bootstrap.dart +++ b/catalyst_voices/lib/configs/bootstrap.dart @@ -7,6 +7,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:url_strategy/url_strategy.dart'; +/// Initializes and runs the application provided by the [builder]. Future bootstrap(FutureOr Function() builder) async { WidgetsFlutterBinding.ensureInitialized(); @@ -24,3 +25,15 @@ Future bootstrap(FutureOr Function() builder) async { runApp(await builder()); } + +/// Initializer for integration tests, similar to [bootstrap] but: +/// - Must not call [WidgetsFlutterBinding.ensureInitialized]. +/// - Must not call [runApp]. +/// - Must not override [FlutterError.onError]. +/// - Must be synced with [bootstrap], to run exactly the same +/// initialization logic except for the above exclusions. +Future bootstrapForTests() async { + GoRouter.optionURLReflectsImperativeAPIs = true; + setPathUrlStrategy(); + Bloc.observer = AppBlocObserver(); +} diff --git a/catalyst_voices/lib/configs/main_qa_patrol.dart b/catalyst_voices/lib/configs/main_qa_patrol.dart deleted file mode 100644 index 6f62a42032..0000000000 --- a/catalyst_voices/lib/configs/main_qa_patrol.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:catalyst_voices/configs/app_bloc_observer.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:go_router/go_router.dart'; -import 'package:url_strategy/url_strategy.dart'; - -Future main() async { - GoRouter.optionURLReflectsImperativeAPIs = true; - setPathUrlStrategy(); - Bloc.observer = AppBlocObserver(); -}