From c04b359deba4c95588f00e3660d03fb846ba4c8a Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 30 Aug 2024 05:49:12 +0800 Subject: [PATCH 1/7] test: Activate leak tracking for go router --- packages/go_router/pubspec.yaml | 1 + packages/go_router/test/flutter_test_config.dart | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 packages/go_router/test/flutter_test_config.dart diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 4e086f24559..c6b6e4fb05c 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -22,6 +22,7 @@ dev_dependencies: flutter_test: sdk: flutter io: ^1.0.4 + leak_tracker_flutter_testing: any path: ^1.8.2 topics: diff --git a/packages/go_router/test/flutter_test_config.dart b/packages/go_router/test/flutter_test_config.dart new file mode 100644 index 00000000000..20b8087ee34 --- /dev/null +++ b/packages/go_router/test/flutter_test_config.dart @@ -0,0 +1,10 @@ +import 'dart:async'; + +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; + +FutureOr testExecutable(FutureOr Function() testMain) { + LeakTesting.enable(); + LeakTesting.settings = + LeakTesting.settings.withIgnored(createdByTestHelpers: true); + return testMain(); +} From 2a2f8196cdcb36ca771a2344bad883b988c69c96 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 30 Aug 2024 05:49:20 +0800 Subject: [PATCH 2/7] test: Fix leaks in tests --- packages/go_router/test/go_router_test.dart | 1 + packages/go_router/test/information_provider_test.dart | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/packages/go_router/test/go_router_test.dart b/packages/go_router/test/go_router_test.dart index e2c2d1b5cfc..7fd6c4dad48 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -5458,6 +5458,7 @@ void main() { ), ], ); + addTearDown(router.dispose); await tester.pumpWidget( MaterialApp.router( key: UniqueKey(), diff --git a/packages/go_router/test/information_provider_test.dart b/packages/go_router/test/information_provider_test.dart index 59136036666..d47a64520c0 100644 --- a/packages/go_router/test/information_provider_test.dart +++ b/packages/go_router/test/information_provider_test.dart @@ -17,6 +17,7 @@ void main() { late final GoRouteInformationProvider provider = GoRouteInformationProvider( initialLocation: initialRoute, initialExtra: null); + addTearDown(provider.dispose); provider.addListener(expectAsync0(() {})); provider.go(newRoute); }); @@ -26,6 +27,7 @@ void main() { late final GoRouteInformationProvider provider = GoRouteInformationProvider( initialLocation: initialRoute, initialExtra: null); + addTearDown(provider.dispose); provider.addListener(expectAsync0(() {})); provider .didPushRouteInformation(RouteInformation(uri: Uri.parse(newRoute))); @@ -41,6 +43,7 @@ void main() { late final GoRouteInformationProvider provider = GoRouteInformationProvider( initialLocation: initialRoute, initialExtra: null); + addTearDown(provider.dispose); provider.addListener(expectAsync0(() {})); provider.didPushRouteInformation( RouteInformation(uri: Uri.parse(expectedUriString))); @@ -60,6 +63,7 @@ void main() { late final GoRouteInformationProvider provider = GoRouteInformationProvider( initialLocation: initialRoute, initialExtra: null); + addTearDown(provider.dispose); provider.addListener(expectAsync0(() {})); provider.didPushRouteInformation( RouteInformation(uri: Uri.parse(expectedUriString))); From 869d489b49ef1426a0361b3afd035854bd22a5ec Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 30 Aug 2024 22:26:13 +0800 Subject: [PATCH 3/7] doc: Add license --- packages/go_router/test/flutter_test_config.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/go_router/test/flutter_test_config.dart b/packages/go_router/test/flutter_test_config.dart index 20b8087ee34..419d3ddc09b 100644 --- a/packages/go_router/test/flutter_test_config.dart +++ b/packages/go_router/test/flutter_test_config.dart @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + import 'dart:async'; import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; From fb4a414abe09bdccd26200ca156f66623d3313a4 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 30 Aug 2024 22:29:28 +0800 Subject: [PATCH 4/7] test: Don't ignore leaks created by test helpers --- packages/go_router/test/extra_codec_test.dart | 1 + packages/go_router/test/flutter_test_config.dart | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/go_router/test/extra_codec_test.dart b/packages/go_router/test/extra_codec_test.dart index 35291db978d..0005d1d535f 100644 --- a/packages/go_router/test/extra_codec_test.dart +++ b/packages/go_router/test/extra_codec_test.dart @@ -74,6 +74,7 @@ void main() { expect(find.text(initialString), findsOneWidget); await tester.restartAndRestore(); + addTearDown(tester.binding.restorationManager.dispose); await tester.pumpAndSettle(); expect(find.text(initialString), findsOneWidget); diff --git a/packages/go_router/test/flutter_test_config.dart b/packages/go_router/test/flutter_test_config.dart index 419d3ddc09b..ca482a60be6 100644 --- a/packages/go_router/test/flutter_test_config.dart +++ b/packages/go_router/test/flutter_test_config.dart @@ -8,7 +8,5 @@ import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; FutureOr testExecutable(FutureOr Function() testMain) { LeakTesting.enable(); - LeakTesting.settings = - LeakTesting.settings.withIgnored(createdByTestHelpers: true); return testMain(); } From 246857a5c328a99d1c7075e3f626612f6d5a20af Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Mon, 9 Sep 2024 17:13:36 +0800 Subject: [PATCH 5/7] bug: Fix tests on chrome --- packages/go_router/test/flutter_test_config.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/go_router/test/flutter_test_config.dart b/packages/go_router/test/flutter_test_config.dart index ca482a60be6..9907e578b84 100644 --- a/packages/go_router/test/flutter_test_config.dart +++ b/packages/go_router/test/flutter_test_config.dart @@ -6,7 +6,8 @@ import 'dart:async'; import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; -FutureOr testExecutable(FutureOr Function() testMain) { +Future testExecutable(FutureOr Function() testMain) async { LeakTesting.enable(); - return testMain(); + LeakTracking.warnForUnsupportedPlatforms = false; + await testMain(); } From d41a8ea25b1a3f86ac86ed5dd775cbfa9f554b7e Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Fri, 13 Sep 2024 21:38:51 +0800 Subject: [PATCH 6/7] ci: Allow leak_tracker_flutter_testing unpinned dependency --- script/configs/allowed_unpinned_deps.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/script/configs/allowed_unpinned_deps.yaml b/script/configs/allowed_unpinned_deps.yaml index fead5f119d4..0a89e92e6df 100644 --- a/script/configs/allowed_unpinned_deps.yaml +++ b/script/configs/allowed_unpinned_deps.yaml @@ -39,6 +39,7 @@ - io - js - json_serializable +- leak_tracker_flutter_testing - lints - logging - markdown From ffe76a6b0835fd98dd91e91cd77b9a9b86396a4c Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Tue, 15 Oct 2024 20:22:30 +0800 Subject: [PATCH 7/7] test: Fix memory leaks in new tests --- packages/go_router/test/information_provider_test.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/go_router/test/information_provider_test.dart b/packages/go_router/test/information_provider_test.dart index d47a64520c0..2bdb0e6178f 100644 --- a/packages/go_router/test/information_provider_test.dart +++ b/packages/go_router/test/information_provider_test.dart @@ -82,6 +82,7 @@ void main() { initialLocation: initialRoute, initialExtra: null, routerNeglect: true); + addTearDown(provider.dispose); provider.addListener(expectAsync0(() {})); provider.go(newRoute); provider.routerReportsNewRouteInformation( @@ -98,6 +99,7 @@ void main() { late final GoRouteInformationProvider provider = GoRouteInformationProvider( initialLocation: initialRoute, initialExtra: null); + addTearDown(provider.dispose); provider.addListener(expectAsync0(() {})); provider.go(newRoute); provider.routerReportsNewRouteInformation(