From fe8f0fe33d5c3177be9f106832d1e931f0ae7a92 Mon Sep 17 00:00:00 2001 From: Flop Date: Wed, 22 Oct 2025 21:14:04 +0800 Subject: [PATCH 1/4] Migrates test --- packages/go_router/test/extra_codec_test.dart | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/packages/go_router/test/extra_codec_test.dart b/packages/go_router/test/extra_codec_test.dart index ebc4f11cf66..26cc282706e 100644 --- a/packages/go_router/test/extra_codec_test.dart +++ b/packages/go_router/test/extra_codec_test.dart @@ -7,6 +7,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import 'test_helpers.dart'; @@ -52,33 +53,40 @@ void main() { expect(find.text(initialString), findsOneWidget); }); - testWidgets('Restores state correctly', (WidgetTester tester) async { - const String initialString = 'some string'; - const String empty = 'empty'; - final List routes = [ - GoRoute( - path: '/', - builder: (_, GoRouterState state) { - return Text((state.extra as ComplexData?)?.data ?? empty); - }, - ), - ]; + testWidgets( + 'Restores state correctly', + // TODO(Flop): Remove when minimum flutter version includes + // https://github.com/flutter/flutter/pull/176519 + experimentalLeakTesting: LeakTesting.settings.withIgnored( + classes: ['TestRestorationManager', 'RestorationBucket'], + ), + (WidgetTester tester) async { + const String initialString = 'some string'; + const String empty = 'empty'; + final List routes = [ + GoRoute( + path: '/', + builder: (_, GoRouterState state) { + return Text((state.extra as ComplexData?)?.data ?? empty); + }, + ), + ]; - await createRouter( - routes, - tester, - initialExtra: ComplexData(initialString), - restorationScopeId: 'test', - extraCodec: ComplexDataCodec(), - ); - expect(find.text(initialString), findsOneWidget); + await createRouter( + routes, + tester, + initialExtra: ComplexData(initialString), + restorationScopeId: 'test', + extraCodec: ComplexDataCodec(), + ); + expect(find.text(initialString), findsOneWidget); - await tester.restartAndRestore(); - addTearDown(tester.binding.restorationManager.dispose); + await tester.restartAndRestore(); - await tester.pumpAndSettle(); - expect(find.text(initialString), findsOneWidget); - }); + await tester.pumpAndSettle(); + expect(find.text(initialString), findsOneWidget); + }, + ); } class ComplexData { From c73a2b5ffda576c6d2ac4fc23d32c6ce9c19232f Mon Sep 17 00:00:00 2001 From: Flop Date: Thu, 23 Oct 2025 18:11:58 +0800 Subject: [PATCH 2/4] Improve test --- packages/go_router/test/extra_codec_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/go_router/test/extra_codec_test.dart b/packages/go_router/test/extra_codec_test.dart index 26cc282706e..656ec7acf9c 100644 --- a/packages/go_router/test/extra_codec_test.dart +++ b/packages/go_router/test/extra_codec_test.dart @@ -53,10 +53,10 @@ void main() { expect(find.text(initialString), findsOneWidget); }); + // TODO(hgraceb): Remove when minimum flutter version includes + // https://github.com/flutter/flutter/pull/176519 testWidgets( 'Restores state correctly', - // TODO(Flop): Remove when minimum flutter version includes - // https://github.com/flutter/flutter/pull/176519 experimentalLeakTesting: LeakTesting.settings.withIgnored( classes: ['TestRestorationManager', 'RestorationBucket'], ), From 8471c5f040466af90564b4d5461ee9220f2939bc Mon Sep 17 00:00:00 2001 From: Flop Date: Thu, 23 Oct 2025 18:17:28 +0800 Subject: [PATCH 3/4] Improve test --- packages/go_router/test/extra_codec_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router/test/extra_codec_test.dart b/packages/go_router/test/extra_codec_test.dart index 656ec7acf9c..1fb45f4f034 100644 --- a/packages/go_router/test/extra_codec_test.dart +++ b/packages/go_router/test/extra_codec_test.dart @@ -58,7 +58,7 @@ void main() { testWidgets( 'Restores state correctly', experimentalLeakTesting: LeakTesting.settings.withIgnored( - classes: ['TestRestorationManager', 'RestorationBucket'], + classes: const ['TestRestorationManager', 'RestorationBucket'], ), (WidgetTester tester) async { const String initialString = 'some string'; From f0e6f83ead775d49f7fbca61885ba024e3520965 Mon Sep 17 00:00:00 2001 From: Flop Date: Thu, 23 Oct 2025 18:20:09 +0800 Subject: [PATCH 4/4] Improve test --- packages/go_router/test/extra_codec_test.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/go_router/test/extra_codec_test.dart b/packages/go_router/test/extra_codec_test.dart index 1fb45f4f034..859fdf7c558 100644 --- a/packages/go_router/test/extra_codec_test.dart +++ b/packages/go_router/test/extra_codec_test.dart @@ -53,13 +53,8 @@ void main() { expect(find.text(initialString), findsOneWidget); }); - // TODO(hgraceb): Remove when minimum flutter version includes - // https://github.com/flutter/flutter/pull/176519 testWidgets( 'Restores state correctly', - experimentalLeakTesting: LeakTesting.settings.withIgnored( - classes: const ['TestRestorationManager', 'RestorationBucket'], - ), (WidgetTester tester) async { const String initialString = 'some string'; const String empty = 'empty'; @@ -86,6 +81,11 @@ void main() { await tester.pumpAndSettle(); expect(find.text(initialString), findsOneWidget); }, + // TODO(hgraceb): Remove when minimum flutter version includes + // https://github.com/flutter/flutter/pull/176519 + experimentalLeakTesting: LeakTesting.settings.withIgnored( + classes: const ['TestRestorationManager', 'RestorationBucket'], + ), ); }