From b3248c9210673621d9245ebe808302ec47eeb487 Mon Sep 17 00:00:00 2001 From: Kilian Schulte Date: Thu, 3 Oct 2024 23:20:51 +0200 Subject: [PATCH] make attachRootComponent synchronous --- docs/concepts/testing.mdx | 2 +- .../lib/widgets/counter.dart | 1 - experiments/mobx_hooks/test/hooks_test.dart | 4 ++-- packages/jaspr/CHANGELOG.md | 1 + packages/jaspr/README.md | 2 +- .../lib/src/browser/browser_binding.dart | 4 ++-- .../jaspr/lib/src/framework/build_owner.dart | 24 ++++++++++++------- .../lib/src/framework/components_binding.dart | 6 ++--- .../lib/src/server/async_build_owner.dart | 8 +++---- .../jaspr/lib/src/server/server_binding.dart | 15 +++++++----- .../browser/basic/basic_browser_test.dart | 2 +- packages/jaspr/test/browser/events_test.dart | 10 ++++---- .../test/browser/head/head_browser_test.dart | 2 +- .../hydration/hydration_browser_test.dart | 2 +- .../test/components/html/content_test.dart | 2 +- .../test/components/html/forms_test.dart | 4 ++-- .../test/components/html/media_test.dart | 2 +- .../test/components/html/other_test.dart | 2 +- .../jaspr/test/components/html/svg_test.dart | 2 +- .../jaspr/test/components/html/text_test.dart | 2 +- .../framework/async/async_component_test.dart | 6 ++--- .../framework/basic/basic_component_test.dart | 2 +- .../global_key_schenanigans_test.dart | 2 +- .../inherited_component_test.dart | 2 +- .../inherited_model/inherited_model_test.dart | 2 +- .../observer_component_test.dart | 2 +- .../reorder_children_test.dart | 2 +- .../stateful_reparenting_test.dart | 2 +- packages/jaspr/test/utils/test_component.dart | 4 ++-- packages/jaspr_flutter_embed/README.md | 4 +++- .../jaspr_riverpod/lib/src/framework.dart | 2 +- .../test/context_listen_test.dart | 8 +++---- .../test/context_read_test.dart | 4 ++-- .../test/context_refresh_test.dart | 4 ++-- .../test/context_watch_test.dart | 6 ++--- .../test/browser/routing/routing_test.dart | 4 ++-- .../test/routing/lazy_routes_test.dart | 4 ++-- .../test/routing/named_routes_test.dart | 4 ++-- .../test/routing/redirect_test.dart | 4 ++-- .../test/routing/route_params_test.dart | 2 +- .../test/routing/routes_test.dart | 6 ++--- packages/jaspr_test/README.md | 2 +- .../lib/src/testers/browser_tester.dart | 4 ++-- .../lib/src/testers/component_tester.dart | 4 ++-- 44 files changed, 95 insertions(+), 88 deletions(-) diff --git a/docs/concepts/testing.mdx b/docs/concepts/testing.mdx index 546e2efb..78b59f3d 100644 --- a/docs/concepts/testing.mdx +++ b/docs/concepts/testing.mdx @@ -30,7 +30,7 @@ void main() { testComponents('renders my component', (tester) async { // We want to test the MyComponent component. // Assume this shows a count and a button to increase it. - await tester.pumpComponent(MyComponent()); + tester.pumpComponent(MyComponent()); // Should render a [Text] component with content 'Count: 0'. expect(find.text('Count: 0'), findsOneComponent); diff --git a/examples/flutter_multi_view/lib/widgets/counter.dart b/examples/flutter_multi_view/lib/widgets/counter.dart index 96075580..5248888b 100644 --- a/examples/flutter_multi_view/lib/widgets/counter.dart +++ b/examples/flutter_multi_view/lib/widgets/counter.dart @@ -9,7 +9,6 @@ class CounterWidget extends StatelessWidget { @override Widget build(BuildContext context) { - var theme = ThemeData.light(); return MaterialApp( debugShowCheckedModeBanner: false, home: Card( diff --git a/experiments/mobx_hooks/test/hooks_test.dart b/experiments/mobx_hooks/test/hooks_test.dart index 80a0ecfb..ee18e113 100644 --- a/experiments/mobx_hooks/test/hooks_test.dart +++ b/experiments/mobx_hooks/test/hooks_test.dart @@ -158,11 +158,11 @@ void main() { group('jaspr context', () { // test('App', () async { - // await tester.pumpComponent(MobXHooksObserverComponent(child: App())); + // tester.pumpComponent(MobXHooksObserverComponent(child: App())); // }); testComponents('custom flow', (tester) async { - await tester.pumpComponent( + tester.pumpComponent( MobXHooksObserverComponent( child: Builder( builder: (context) sync* { diff --git a/packages/jaspr/CHANGELOG.md b/packages/jaspr/CHANGELOG.md index a01a5bda..91e04c22 100644 --- a/packages/jaspr/CHANGELOG.md +++ b/packages/jaspr/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased breaking - **BREAKING** Migrate all packages to `package:web`, replacing `dart:html`. +- **BREAKING** Make `ComponentsBinding.attachRootComponent()` and `ComponentTester.pumpComponent()` synchronous. - Add `InheritedModel` similar to Flutters [InheritedModel](https://api.flutter.dev/flutter/widgets/InheritedModel-class.html) - Improved html formatting on the server to not introduce unwanted whitespaces. diff --git a/packages/jaspr/README.md b/packages/jaspr/README.md index 46be2993..8b279c11 100644 --- a/packages/jaspr/README.md +++ b/packages/jaspr/README.md @@ -189,7 +189,7 @@ void main() { testComponents('renders my component', (tester) async { // We want to test the MyComponent component. // Assume this shows a count and a button to increase it. - await tester.pumpComponent(MyComponent()); + tester.pumpComponent(MyComponent()); // Should render a [Text] component with content 'Count: 0'. expect(find.text('Count: 0'), findsOneComponent); diff --git a/packages/jaspr/lib/src/browser/browser_binding.dart b/packages/jaspr/lib/src/browser/browser_binding.dart index 915336bf..9eab076d 100644 --- a/packages/jaspr/lib/src/browser/browser_binding.dart +++ b/packages/jaspr/lib/src/browser/browser_binding.dart @@ -33,10 +33,10 @@ class BrowserAppBinding extends AppBinding with ComponentsBinding { late (Node, Node)? attachBetween; @override - Future attachRootComponent(Component app, {String attachTo = 'body', (Node, Node)? attachBetween}) { + void attachRootComponent(Component app, {String attachTo = 'body', (Node, Node)? attachBetween}) { attachTarget = attachTo; this.attachBetween = attachBetween; - return super.attachRootComponent(app); + super.attachRootComponent(app); } @override diff --git a/packages/jaspr/lib/src/framework/build_owner.dart b/packages/jaspr/lib/src/framework/build_owner.dart index 59c18b64..d81ed857 100644 --- a/packages/jaspr/lib/src/framework/build_owner.dart +++ b/packages/jaspr/lib/src/framework/build_owner.dart @@ -72,7 +72,7 @@ class BuildOwner { assert(_debugStateLockLevel >= 0); } - Future performInitialBuild(Element element, Future Function() completeBuild) async { + Future performInitialBuild(Element element, void Function() completeBuild) async { assert(_debugStateLockLevel >= 0); assert(!_debugBuilding); @@ -87,16 +87,22 @@ class BuildOwner { element.mount(null, null); element.didMount(); - _isFirstBuild = false; + completeInitialBuild(element, () { + _isFirstBuild = false; - assert(_debugBuilding); - assert(() { - _debugBuilding = false; - _debugStateLockLevel -= 1; - return true; - }()); + assert(_debugBuilding); + assert(() { + _debugBuilding = false; + _debugStateLockLevel -= 1; + return true; + }()); + + completeBuild(); + }); + } - return completeBuild(); + void completeInitialBuild(Element element, void Function() buildCallback) { + buildCallback(); } /// Rebuilds [child] and correctly accounts for any asynchronous operations that can diff --git a/packages/jaspr/lib/src/framework/components_binding.dart b/packages/jaspr/lib/src/framework/components_binding.dart index 1ac7aa69..b7e74b52 100644 --- a/packages/jaspr/lib/src/framework/components_binding.dart +++ b/packages/jaspr/lib/src/framework/components_binding.dart @@ -3,7 +3,7 @@ part of 'framework.dart'; /// Main app binding, controls the root component and global state mixin ComponentsBinding on AppBinding { /// Sets [app] as the new root of the component tree and performs an initial build - Future attachRootComponent(Component app) async { + void attachRootComponent(Component app) async { var buildOwner = _rootElement?._owner ?? createRootBuildOwner(); var element = _Root(child: app).createElement(); @@ -13,9 +13,7 @@ mixin ComponentsBinding on AppBinding { _rootElement = element; - return buildOwner.performInitialBuild(element, () async { - completeInitialFrame(); - }); + buildOwner.performInitialBuild(element, completeInitialFrame); } RenderObject createRootRenderObject(); diff --git a/packages/jaspr/lib/src/server/async_build_owner.dart b/packages/jaspr/lib/src/server/async_build_owner.dart index da76311f..f75406f4 100644 --- a/packages/jaspr/lib/src/server/async_build_owner.dart +++ b/packages/jaspr/lib/src/server/async_build_owner.dart @@ -12,11 +12,9 @@ extension AsyncElement on Element { class AsyncBuildOwner extends BuildOwner { @override - Future performInitialBuild(Element element, Future Function() completeBuild) { - return super.performInitialBuild(element, () async { - await element._asyncBuildLock?.asFuture; - return completeBuild(); - }); + void completeInitialBuild(Element element, void Function() buildCallback) async { + await element._asyncBuildLock?.asFuture; + super.completeInitialBuild(element, buildCallback); } @override diff --git a/packages/jaspr/lib/src/server/server_binding.dart b/packages/jaspr/lib/src/server/server_binding.dart index 4f4e9995..5ac26e75 100644 --- a/packages/jaspr/lib/src/server/server_binding.dart +++ b/packages/jaspr/lib/src/server/server_binding.dart @@ -20,16 +20,19 @@ class ServerAppBinding extends AppBinding with ComponentsBinding { @override bool get isClient => false; - final rootCompleter = Completer.sync(); - @override - Future attachRootComponent(Component app) async { - await super.attachRootComponent(ClientComponentRegistry(child: app)); - rootCompleter.complete(); + void attachRootComponent(Component app) async { + super.attachRootComponent(ClientComponentRegistry(child: app)); } Future render() async { - await rootCompleter.future; + if (rootElement == null) return ''; + + if (rootElement!.owner.isFirstBuild) { + final completer = Completer.sync(); + rootElement!.binding.addPostFrameCallback(completer.complete); + await completer.future; + } var root = rootElement!.renderObject as MarkupRenderObject; var adapters = [ diff --git a/packages/jaspr/test/browser/basic/basic_browser_test.dart b/packages/jaspr/test/browser/basic/basic_browser_test.dart index 268aea59..11021e7e 100644 --- a/packages/jaspr/test/browser/basic/basic_browser_test.dart +++ b/packages/jaspr/test/browser/basic/basic_browser_test.dart @@ -7,7 +7,7 @@ import 'basic_app.dart'; void main() { group('basic browser test', () { testBrowser('should render component', (tester) async { - await tester.pumpComponent(App()); + tester.pumpComponent(App()); expect(find.text('Count: 0'), findsOneComponent); diff --git a/packages/jaspr/test/browser/events_test.dart b/packages/jaspr/test/browser/events_test.dart index ac607e9a..aad948a1 100644 --- a/packages/jaspr/test/browser/events_test.dart +++ b/packages/jaspr/test/browser/events_test.dart @@ -8,7 +8,7 @@ void main() { testBrowser('handle click events', (tester) async { int clicked = 0; - await tester.pumpComponent(button(onClick: () { + tester.pumpComponent(button(onClick: () { clicked++; }, [])); @@ -20,7 +20,7 @@ void main() { bool checkedInput = false; bool checkedChange = false; - await tester.pumpComponent(input( + tester.pumpComponent(input( type: InputType.checkbox, onInput: (value) => checkedInput = value, onChange: (value) => checkedChange = value, @@ -38,7 +38,7 @@ void main() { double numberInput = 0; double numberChange = 0; - await tester.pumpComponent(input( + tester.pumpComponent(input( type: InputType.number, onInput: (value) => numberInput = value, onChange: (value) => numberChange = value, @@ -56,7 +56,7 @@ void main() { String textInput = ""; String textChange = ""; - await tester.pumpComponent(input( + tester.pumpComponent(input( type: InputType.text, onInput: (value) => textInput = value, onChange: (value) => textChange = value, @@ -74,7 +74,7 @@ void main() { String textInput = ""; String textChange = ""; - await tester.pumpComponent(textarea( + tester.pumpComponent(textarea( onInput: (value) => textInput = value, onChange: (value) => textChange = value, [], diff --git a/packages/jaspr/test/browser/head/head_browser_test.dart b/packages/jaspr/test/browser/head/head_browser_test.dart index 22298b47..43fec660 100644 --- a/packages/jaspr/test/browser/head/head_browser_test.dart +++ b/packages/jaspr/test/browser/head/head_browser_test.dart @@ -8,7 +8,7 @@ import 'head_app.dart'; void main() { group('head browser test', () { testBrowser('should serve component', (tester) async { - await tester.pumpComponent(App()); + tester.pumpComponent(App()); var nodes = AttachAdapter.instanceFor(AttachTarget.head).liveNodes.toList(); diff --git a/packages/jaspr/test/browser/hydration/hydration_browser_test.dart b/packages/jaspr/test/browser/hydration/hydration_browser_test.dart index cb21c3e1..aa5c2380 100644 --- a/packages/jaspr/test/browser/hydration/hydration_browser_test.dart +++ b/packages/jaspr/test/browser/hydration/hydration_browser_test.dart @@ -20,7 +20,7 @@ void main() { expect(pElement.parentNode, equals(divElement)); expect(bElement.parentNode, equals(pElement)); - await tester.pumpComponent(div([ + tester.pumpComponent(div([ p([ text('Hello '), b([text('World2')]), diff --git a/packages/jaspr/test/components/html/content_test.dart b/packages/jaspr/test/components/html/content_test.dart index 0f673445..260da410 100644 --- a/packages/jaspr/test/components/html/content_test.dart +++ b/packages/jaspr/test/components/html/content_test.dart @@ -6,7 +6,7 @@ import 'package:jaspr_test/jaspr_test.dart'; void main() { group('html components', () { testComponents('renders content', (tester) async { - await tester.pumpComponent(html([ + tester.pumpComponent(html([ head([]), body([ header([ diff --git a/packages/jaspr/test/components/html/forms_test.dart b/packages/jaspr/test/components/html/forms_test.dart index e4dabec0..260e284e 100644 --- a/packages/jaspr/test/components/html/forms_test.dart +++ b/packages/jaspr/test/components/html/forms_test.dart @@ -6,7 +6,7 @@ import 'package:jaspr_test/jaspr_test.dart'; void main() { group('html components', () { testComponents('renders button', (tester) async { - await tester.pumpComponent(button( + tester.pumpComponent(button( autofocus: false, disabled: false, type: ButtonType.button, @@ -18,7 +18,7 @@ void main() { }); testComponents('renders form', (tester) async { - await tester.pumpComponent(form( + tester.pumpComponent(form( action: "", method: FormMethod.post, encType: FormEncType.text, diff --git a/packages/jaspr/test/components/html/media_test.dart b/packages/jaspr/test/components/html/media_test.dart index 93e25003..632fe29f 100644 --- a/packages/jaspr/test/components/html/media_test.dart +++ b/packages/jaspr/test/components/html/media_test.dart @@ -6,7 +6,7 @@ import 'package:jaspr_test/jaspr_test.dart'; void main() { group('html components', () { testComponents('renders media', (tester) async { - await tester.pumpComponent(div([ + tester.pumpComponent(div([ audio( autoplay: false, controls: false, diff --git a/packages/jaspr/test/components/html/other_test.dart b/packages/jaspr/test/components/html/other_test.dart index ad3d4443..591ab026 100644 --- a/packages/jaspr/test/components/html/other_test.dart +++ b/packages/jaspr/test/components/html/other_test.dart @@ -6,7 +6,7 @@ import 'package:jaspr_test/jaspr_test.dart'; void main() { group('html components', () { testComponents('renders other', (tester) async { - await tester.pumpComponent(div([ + tester.pumpComponent(div([ details(open: false, []), dialog(open: false, []), summary([]), diff --git a/packages/jaspr/test/components/html/svg_test.dart b/packages/jaspr/test/components/html/svg_test.dart index dd80b285..0e8654ab 100644 --- a/packages/jaspr/test/components/html/svg_test.dart +++ b/packages/jaspr/test/components/html/svg_test.dart @@ -6,7 +6,7 @@ import 'package:jaspr_test/jaspr_test.dart'; void main() { group('html components', () { testComponents('renders svg', (tester) async { - await tester.pumpComponent(svg(viewBox: "0 0 100 100", width: 100.px, height: 100.px, [ + tester.pumpComponent(svg(viewBox: "0 0 100 100", width: 100.px, height: 100.px, [ rect( x: "0", y: "0", diff --git a/packages/jaspr/test/components/html/text_test.dart b/packages/jaspr/test/components/html/text_test.dart index 06fe5ea5..a49a2ce6 100644 --- a/packages/jaspr/test/components/html/text_test.dart +++ b/packages/jaspr/test/components/html/text_test.dart @@ -6,7 +6,7 @@ import 'package:jaspr_test/jaspr_test.dart'; void main() { group('html components', () { testComponents('renders text', (tester) async { - await tester.pumpComponent(div([ + tester.pumpComponent(div([ a( download: "", href: "a", diff --git a/packages/jaspr/test/framework/async/async_component_test.dart b/packages/jaspr/test/framework/async/async_component_test.dart index 32b5ea21..763eb5a7 100644 --- a/packages/jaspr/test/framework/async/async_component_test.dart +++ b/packages/jaspr/test/framework/async/async_component_test.dart @@ -11,7 +11,7 @@ void main() { testComponents('should render future with data', (tester) async { var completer = Completer(); - await tester.pumpComponent(FutureTester(completer.future)); + tester.pumpComponent(FutureTester(completer.future)); expect(find.text('LOADING'), findsOneComponent); @@ -24,7 +24,7 @@ void main() { testComponents('should render future with error', (tester) async { var completer = Completer(); - await tester.pumpComponent(FutureTester(completer.future)); + tester.pumpComponent(FutureTester(completer.future)); expect(find.text('LOADING'), findsOneComponent); @@ -37,7 +37,7 @@ void main() { testComponents('should render stream', (tester) async { var controller = StreamController(); - await tester.pumpComponent(StreamTester(controller.stream)); + tester.pumpComponent(StreamTester(controller.stream)); expect(find.text('LOADING'), findsOneComponent); diff --git a/packages/jaspr/test/framework/basic/basic_component_test.dart b/packages/jaspr/test/framework/basic/basic_component_test.dart index 95acdf0d..3d07e8f7 100644 --- a/packages/jaspr/test/framework/basic/basic_component_test.dart +++ b/packages/jaspr/test/framework/basic/basic_component_test.dart @@ -7,7 +7,7 @@ import 'basic_app.dart'; void main() { group('basic component test', () { testComponents('should render component', (tester) async { - await tester.pumpComponent(App()); + tester.pumpComponent(App()); expect(find.text('Count: 0'), findsOneComponent); diff --git a/packages/jaspr/test/framework/global_key_schenanigans/global_key_schenanigans_test.dart b/packages/jaspr/test/framework/global_key_schenanigans/global_key_schenanigans_test.dart index 01fb9164..a24c509b 100644 --- a/packages/jaspr/test/framework/global_key_schenanigans/global_key_schenanigans_test.dart +++ b/packages/jaspr/test/framework/global_key_schenanigans/global_key_schenanigans_test.dart @@ -9,7 +9,7 @@ import 'global_key_schenanigans_app.dart'; void main() { group('global key schenanigans test', () { testComponents('should keep state on reparenting', (tester) async { - var controller = await tester.pumpTestComponent(App()); + var controller = tester.pumpTestComponent(App()); // phase 1: component should be mounted directly expect(find.byType(Child), findsOneComponent); diff --git a/packages/jaspr/test/framework/inherited_component/inherited_component_test.dart b/packages/jaspr/test/framework/inherited_component/inherited_component_test.dart index 4815b0b1..5bcc3fff 100644 --- a/packages/jaspr/test/framework/inherited_component/inherited_component_test.dart +++ b/packages/jaspr/test/framework/inherited_component/inherited_component_test.dart @@ -9,7 +9,7 @@ import 'inherited_component_app.dart'; void main() { group('inherited component test', () { testComponents('should inherit component', (tester) async { - var controller = await tester.pumpTestComponent(App()); + var controller = tester.pumpTestComponent(App()); // phase 1: inherited component should be mounted expect(find.text('Inherited value: 0'), findsOneComponent); diff --git a/packages/jaspr/test/framework/inherited_model/inherited_model_test.dart b/packages/jaspr/test/framework/inherited_model/inherited_model_test.dart index c92c1a75..3990e139 100644 --- a/packages/jaspr/test/framework/inherited_model/inherited_model_test.dart +++ b/packages/jaspr/test/framework/inherited_model/inherited_model_test.dart @@ -20,7 +20,7 @@ void testAgainstDto(MyDto src, {required Set expectedRebuilds}) { void main() { group('inherited model test', () { testComponents('should update dependencies only', (tester) async { - var controller = await tester.pumpTestComponent(App()); + var controller = tester.pumpTestComponent(App()); Future rebuildThenTestAgainstDto( MyDto src, { required Set expectedRebuilds, diff --git a/packages/jaspr/test/framework/observer_component/observer_component_test.dart b/packages/jaspr/test/framework/observer_component/observer_component_test.dart index 193f0f91..7c1e5ae1 100644 --- a/packages/jaspr/test/framework/observer_component/observer_component_test.dart +++ b/packages/jaspr/test/framework/observer_component/observer_component_test.dart @@ -11,7 +11,7 @@ void main() { testComponents('should track elements', (tester) async { ObserverParam params = ObserverParam(renderBoth: true, events: []); final events = params.events; - final controller = await tester.pumpTestComponent(App(params)); + final controller = tester.pumpTestComponent(App(params)); // phase 1: observer component should be mounted expect(find.text('Leaf true false'), findsOneComponent); diff --git a/packages/jaspr/test/framework/reorder_children/reorder_children_test.dart b/packages/jaspr/test/framework/reorder_children/reorder_children_test.dart index 553fa281..0f48cbef 100644 --- a/packages/jaspr/test/framework/reorder_children/reorder_children_test.dart +++ b/packages/jaspr/test/framework/reorder_children/reorder_children_test.dart @@ -10,7 +10,7 @@ import 'reorder_children_app.dart'; void main() { group('reorder children test', () { testComponents('should keep child state on reordering', (tester) async { - var controller = await tester.pumpTestComponent(App()); + var controller = tester.pumpTestComponent(App()); var app = controller.element; expect((app.component as App).child2Key.toString(), equals('[<2>]')); diff --git a/packages/jaspr/test/framework/stateful_reparenting/stateful_reparenting_test.dart b/packages/jaspr/test/framework/stateful_reparenting/stateful_reparenting_test.dart index 1aefe134..71c54d30 100644 --- a/packages/jaspr/test/framework/stateful_reparenting/stateful_reparenting_test.dart +++ b/packages/jaspr/test/framework/stateful_reparenting/stateful_reparenting_test.dart @@ -9,7 +9,7 @@ import 'stateful_reparenting_app.dart'; void main() { group('stateful reparenting test', () { testComponents('should keep state on reparenting', (tester) async { - var controller = await tester.pumpTestComponent(App()); + var controller = tester.pumpTestComponent(App()); // phase 1: component should be mounted directly expect(find.byType(MyStatefulComponent), findsOneComponent); diff --git a/packages/jaspr/test/utils/test_component.dart b/packages/jaspr/test/utils/test_component.dart index 0a79e558..1ad8b887 100644 --- a/packages/jaspr/test/utils/test_component.dart +++ b/packages/jaspr/test/utils/test_component.dart @@ -2,8 +2,8 @@ import 'package:jaspr/jaspr.dart'; import 'package:jaspr_test/jaspr_test.dart'; extension PumpTestComponent on ComponentTester { - Future> pumpTestComponent(TestComponent component) async { - await pumpComponent(component); + TestComponentController pumpTestComponent(TestComponent component) { + pumpComponent(component); late Element testElem; binding.rootElement!.visitChildren((element) { testElem = element; diff --git a/packages/jaspr_flutter_embed/README.md b/packages/jaspr_flutter_embed/README.md index fad49189..b440a7d4 100644 --- a/packages/jaspr_flutter_embed/README.md +++ b/packages/jaspr_flutter_embed/README.md @@ -1 +1,3 @@ -Flutter embedding bindings for [jaspr](pub.dev/packages/jaspr). +Flutter embedding bindings for [Jaspr](https://pub.dev/packages/jaspr). + +See the [Documentation](https://docs.page/schultek/jaspr/going_further/flutter_embedding). diff --git a/packages/jaspr_riverpod/lib/src/framework.dart b/packages/jaspr_riverpod/lib/src/framework.dart index 14f045ae..56d9b557 100644 --- a/packages/jaspr_riverpod/lib/src/framework.dart +++ b/packages/jaspr_riverpod/lib/src/framework.dart @@ -35,7 +35,7 @@ part 'provider_dependencies.dart'; /// /// ```dart /// testComponents('Test example', (tester) async { -/// await tester.pumpComponent( +/// tester.pumpComponent( /// ProviderScope( /// overrides: [ /// // override the behavior of repositoryProvider to provide a fake diff --git a/packages/jaspr_riverpod/test/context_listen_test.dart b/packages/jaspr_riverpod/test/context_listen_test.dart index 4c24b2ca..3e845cf8 100644 --- a/packages/jaspr_riverpod/test/context_listen_test.dart +++ b/packages/jaspr_riverpod/test/context_listen_test.dart @@ -12,7 +12,7 @@ void main() { testComponents('listens to provider state', (tester) async { int? wasCalledWith; - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { context.listen(counter, (prev, next) { wasCalledWith = next; }); @@ -36,7 +36,7 @@ void main() { testComponents('re-listens on rebuild', (tester) async { List wasCalledWith = []; - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { context.listen(counter, (prev, next) { wasCalledWith.add(next); }, fireImmediately: true); @@ -60,7 +60,7 @@ void main() { testComponents('un-listens on dispose', (tester) async { List wasCalledWith = []; - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { if (context.watch(counter.select((cnt) => cnt < 2))) { yield Builder( builder: (context) sync* { @@ -113,7 +113,7 @@ void main() { late Element element; var shouldListen = true; - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { if (shouldListen) { context.listen(counterB, (_, int value) { wasCalledWith.add(value); diff --git a/packages/jaspr_riverpod/test/context_read_test.dart b/packages/jaspr_riverpod/test/context_read_test.dart index df8bd34d..a094f2c7 100644 --- a/packages/jaspr_riverpod/test/context_read_test.dart +++ b/packages/jaspr_riverpod/test/context_read_test.dart @@ -9,7 +9,7 @@ final counter = StateProvider((ref) => 0); void main() { group('context.read', () { testComponents('returns provider state', (tester) async { - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { yield Text('${context.read(counter)}'); })); @@ -18,7 +18,7 @@ void main() { }); testComponents('returns overridden provider state', (tester) async { - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { yield Text('a ${context.read(counter)}'); yield ProviderScope( overrides: [counter.overrideWith((ref) => 1)], diff --git a/packages/jaspr_riverpod/test/context_refresh_test.dart b/packages/jaspr_riverpod/test/context_refresh_test.dart index 4b6bdf3a..1a28b6dc 100644 --- a/packages/jaspr_riverpod/test/context_refresh_test.dart +++ b/packages/jaspr_riverpod/test/context_refresh_test.dart @@ -9,7 +9,7 @@ final counter = StateProvider((ref) => 0); void main() { group('context.refresh', () { testComponents('refreshes provider state', (tester) async { - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { yield Button( label: '${context.watch(counter)}', onPressed: () { @@ -41,7 +41,7 @@ void main() { }); testComponents('refreshes overridden provider state', (tester) async { - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { yield Builder(builder: (context) sync* { yield Button( key: const ValueKey('a'), diff --git a/packages/jaspr_riverpod/test/context_watch_test.dart b/packages/jaspr_riverpod/test/context_watch_test.dart index bda62be8..c7b40c26 100644 --- a/packages/jaspr_riverpod/test/context_watch_test.dart +++ b/packages/jaspr_riverpod/test/context_watch_test.dart @@ -10,7 +10,7 @@ final autoDisposeCounter = StateProvider.autoDispose((ref) => 0); void main() { group('context.watch', () { testComponents('returns provider state and rebuilds on change', (tester) async { - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { yield Button( label: '${context.watch(counter)}', onPressed: () { @@ -28,7 +28,7 @@ void main() { }); testComponents('returns overridden provider state', (tester) async { - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { yield Builder(builder: (context) sync* { yield Button( key: const ValueKey('a'), @@ -69,7 +69,7 @@ void main() { }); testComponents('provider is autodisposed when no longer watched', (tester) async { - await tester.pumpComponent(providerApp((context) sync* { + tester.pumpComponent(providerApp((context) sync* { var showCounter = true; yield StatefulBuilder( builder: (context, setState) sync* { diff --git a/packages/jaspr_router/test/browser/routing/routing_test.dart b/packages/jaspr_router/test/browser/routing/routing_test.dart index 76c8d295..4194d1db 100644 --- a/packages/jaspr_router/test/browser/routing/routing_test.dart +++ b/packages/jaspr_router/test/browser/routing/routing_test.dart @@ -9,7 +9,7 @@ import '../utils.dart'; void main() { group('router', () { testBrowser('should push route', (tester) async { - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a'), ])); @@ -33,7 +33,7 @@ void main() { }); testBrowser('should replace route', (tester) async { - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a'), route('/b'), diff --git a/packages/jaspr_router/test/routing/lazy_routes_test.dart b/packages/jaspr_router/test/routing/lazy_routes_test.dart index 6a753d8a..87141061 100644 --- a/packages/jaspr_router/test/routing/lazy_routes_test.dart +++ b/packages/jaspr_router/test/routing/lazy_routes_test.dart @@ -16,7 +16,7 @@ void main() { testComponents('should push lazy route', (tester) async { var bCompleter = Completer.sync(); - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a'), lazyRoute('/b', bCompleter.future), @@ -43,7 +43,7 @@ void main() { testComponents('should push lazy shell route', (tester) async { var bCompleter = Completer.sync(); - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a'), lazyShellRoute('b', bCompleter.future, [ diff --git a/packages/jaspr_router/test/routing/named_routes_test.dart b/packages/jaspr_router/test/routing/named_routes_test.dart index 620bd15e..f2921771 100644 --- a/packages/jaspr_router/test/routing/named_routes_test.dart +++ b/packages/jaspr_router/test/routing/named_routes_test.dart @@ -12,7 +12,7 @@ void main() { }); testComponents('should push named route', (tester) async { - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a', [], 'alicia'), route('/b', [], 'bob'), @@ -37,7 +37,7 @@ void main() { }); testComponents('should replace named route', (tester) async { - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a', [], 'alicia'), route('/b', [], 'bob'), diff --git a/packages/jaspr_router/test/routing/redirect_test.dart b/packages/jaspr_router/test/routing/redirect_test.dart index d1f05357..572f2570 100644 --- a/packages/jaspr_router/test/routing/redirect_test.dart +++ b/packages/jaspr_router/test/routing/redirect_test.dart @@ -12,7 +12,7 @@ void main() { }); testComponents('should redirect toplevel', (tester) async { - await tester.pumpComponent(Router( + tester.pumpComponent(Router( routes: [ homeRoute(), route('/b'), @@ -37,7 +37,7 @@ void main() { testComponents('should redirect on route', (tester) async { var blocked = true; - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a'), route('/b', [], null, (_, s) { diff --git a/packages/jaspr_router/test/routing/route_params_test.dart b/packages/jaspr_router/test/routing/route_params_test.dart index 9565a0ce..fca6917d 100644 --- a/packages/jaspr_router/test/routing/route_params_test.dart +++ b/packages/jaspr_router/test/routing/route_params_test.dart @@ -12,7 +12,7 @@ void main() { }); testComponents('should resolve route params', (tester) async { - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a/:aId'), ])); diff --git a/packages/jaspr_router/test/routing/routes_test.dart b/packages/jaspr_router/test/routing/routes_test.dart index 55518ddb..c57e1925 100644 --- a/packages/jaspr_router/test/routing/routes_test.dart +++ b/packages/jaspr_router/test/routing/routes_test.dart @@ -12,7 +12,7 @@ void main() { }); testComponents('should push route', (tester) async { - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a'), ])); @@ -36,7 +36,7 @@ void main() { }); testComponents('should replace route', (tester) async { - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a'), route('/b'), @@ -61,7 +61,7 @@ void main() { }); testComponents('should build shell route', (tester) async { - await tester.pumpComponent(Router(routes: [ + tester.pumpComponent(Router(routes: [ homeRoute(), route('/a', [ shellRoute('b', [ diff --git a/packages/jaspr_test/README.md b/packages/jaspr_test/README.md index e1356a8a..65c88fc2 100644 --- a/packages/jaspr_test/README.md +++ b/packages/jaspr_test/README.md @@ -25,7 +25,7 @@ void main() { testComponents('renders my component', (tester) async { // We want to test the MyComponent component. // Assume this shows a count and a button to increase it. - await tester.pumpComponent(MyComponent()); + tester.pumpComponent(MyComponent()); // Should render a [Text] component with content 'Count: 0'. expect(find.text('Count: 0'), findsOneComponent); diff --git a/packages/jaspr_test/lib/src/testers/browser_tester.dart b/packages/jaspr_test/lib/src/testers/browser_tester.dart index cbb0248d..2efbdc10 100644 --- a/packages/jaspr_test/lib/src/testers/browser_tester.dart +++ b/packages/jaspr_test/lib/src/testers/browser_tester.dart @@ -47,8 +47,8 @@ class BrowserTester { final BrowserAppBinding binding; - Future pumpComponent(Component component, {String attachTo = 'body'}) { - return binding.attachRootComponent(component, attachTo: attachTo); + void pumpComponent(Component component, {String attachTo = 'body'}) { + binding.attachRootComponent(component, attachTo: attachTo); } Future click(Finder finder, {bool pump = true}) async { diff --git a/packages/jaspr_test/lib/src/testers/component_tester.dart b/packages/jaspr_test/lib/src/testers/component_tester.dart index f4fc5bcd..ab4f3837 100644 --- a/packages/jaspr_test/lib/src/testers/component_tester.dart +++ b/packages/jaspr_test/lib/src/testers/component_tester.dart @@ -45,8 +45,8 @@ class ComponentTester { final TestComponentsBinding binding; - Future pumpComponent(Component component) { - return binding.attachRootComponent(component); + void pumpComponent(Component component) { + binding.attachRootComponent(component); } /// Simulates a 'click' event on the given element