diff --git a/packages/flutter/test/animation/live_binding_test.dart b/packages/flutter/test/animation/live_binding_test.dart index ae6bafec50..60f8401a19 100644 --- a/packages/flutter/test/animation/live_binding_test.dart +++ b/packages/flutter/test/animation/live_binding_test.dart @@ -80,7 +80,7 @@ void main() { testWidgets('Should show event indicator for pointer events with setSurfaceSize', // TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 -experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), (WidgetTester tester) async { final AnimationSheetBuilder animationSheet = AnimationSheetBuilder(frameSize: const Size(200, 200), allLayers: true); addTearDown(animationSheet.dispose); diff --git a/packages/flutter/test/flutter_test_config.dart b/packages/flutter/test/flutter_test_config.dart index 53049a1e7b..0009b5b1d0 100644 --- a/packages/flutter/test/flutter_test_config.dart +++ b/packages/flutter/test/flutter_test_config.dart @@ -20,7 +20,7 @@ import '_goldens_io.dart' if (dart.library.html) '_goldens_web.dart' /// `--dart-define LEAK_TRACKING=true` or invoke `export LEAK_TRACKING=true`. /// /// See documentation for [testWidgets] on how to except individual tests. -bool isLeakTrackingEnabled() { +bool _isLeakTrackingEnabled() { if (kIsWeb) { return false; } @@ -41,7 +41,7 @@ Future testExecutable(FutureOr Function() testMain) { // receive the event. WidgetController.hitTestWarningShouldBeFatal = true; - if (isLeakTrackingEnabled()) { + if (_isLeakTrackingEnabled()) { LeakTesting.enable(); LeakTracking.warnForUnsupportedPlatforms = false; diff --git a/packages/flutter/test/material/search_anchor_test.dart b/packages/flutter/test/material/search_anchor_test.dart index a0d41cd93b..ffd2b0656a 100644 --- a/packages/flutter/test/material/search_anchor_test.dart +++ b/packages/flutter/test/material/search_anchor_test.dart @@ -2951,6 +2951,7 @@ void main() { testWidgets('Block entering text on disabled widget', (WidgetTester tester) async { const String initValue = 'init'; final TextEditingController controller = TextEditingController(text: initValue); + addTearDown(controller.dispose); await tester.pumpWidget( MaterialApp( @@ -2972,13 +2973,15 @@ void main() { testWidgets('Disabled SearchBar semantics node still contains value', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); + final TextEditingController controller = TextEditingController(text: 'text'); + addTearDown(controller.dispose); await tester.pumpWidget( MaterialApp( home: Material( child: Center( child: SearchBar( - controller: TextEditingController(text: 'text'), + controller: controller, enabled: false, ), ), diff --git a/packages/flutter/test/rendering/memory_allocations_test.dart b/packages/flutter/test/rendering/memory_allocations_test.dart index 8405d02ea0..d4bb309ee4 100644 --- a/packages/flutter/test/rendering/memory_allocations_test.dart +++ b/packages/flutter/test/rendering/memory_allocations_test.dart @@ -7,8 +7,13 @@ import 'dart:ui' as ui; import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; void main() { + // LeakTesting is turned off because it adds subscriptions to + // [FlutterMemoryAllocations], that may interfere with the tests. + LeakTesting.settings = LeakTesting.settings.withIgnoredAll(); + final FlutterMemoryAllocations ma = FlutterMemoryAllocations.instance; setUp(() { diff --git a/packages/flutter/test/widgets/context_menu_controller_test.dart b/packages/flutter/test/widgets/context_menu_controller_test.dart index 1ae40db67d..71ddff6994 100644 --- a/packages/flutter/test/widgets/context_menu_controller_test.dart +++ b/packages/flutter/test/widgets/context_menu_controller_test.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import 'clipboard_utils.dart'; import 'editable_text_utils.dart'; @@ -90,7 +91,10 @@ void main() { expect(find.byKey(key2), findsNothing); }); - testWidgets('A menu can be hidden and then reshown', (WidgetTester tester) async { + testWidgets('A menu can be hidden and then reshown', + // TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { final GlobalKey key1 = GlobalKey(); late final BuildContext context; @@ -178,7 +182,10 @@ void main() { controller.remove(); }); - testWidgets('Calling show when a built-in widget is already showing its context menu hides the built-in menu', (WidgetTester tester) async { + testWidgets('Calling show when a built-in widget is already showing its context menu hides the built-in menu', + // TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { final GlobalKey builtInKey = GlobalKey(); final GlobalKey directKey = GlobalKey(); late final BuildContext context; diff --git a/packages/flutter/test/widgets/image_test.dart b/packages/flutter/test/widgets/image_test.dart index ed2be7943b..801766ad23 100644 --- a/packages/flutter/test/widgets/image_test.dart +++ b/packages/flutter/test/widgets/image_test.dart @@ -1853,7 +1853,10 @@ void main() { skip: kIsWeb, // https://github.com/flutter/flutter/issues/87933. ); - testWidgets('Reports image size when painted', (WidgetTester tester) async { + testWidgets('Reports image size when painted', + // TODO(polina-c): make sure images are disposed, https://github.com/flutter/flutter/issues/141388 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { late ImageSizeInfo imageSizeInfo; int count = 0; debugOnPaintImage = (ImageSizeInfo info) { diff --git a/packages/flutter/test/widgets/memory_allocations_test.dart b/packages/flutter/test/widgets/memory_allocations_test.dart index 6b8bfad9e0..75d12ae847 100644 --- a/packages/flutter/test/widgets/memory_allocations_test.dart +++ b/packages/flutter/test/widgets/memory_allocations_test.dart @@ -5,11 +5,16 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; - int _creations = 0; - int _disposals = 0; +int _creations = 0; +int _disposals = 0; void main() { + // LeakTesting is turned off because it adds subscriptions to + // [FlutterMemoryAllocations], that may interfere with the tests. + LeakTesting.settings = LeakTesting.settings.withIgnoredAll(); + final FlutterMemoryAllocations ma = FlutterMemoryAllocations.instance; test('Publishers dispatch events in debug mode', () async { diff --git a/packages/flutter/test/widgets/nested_scroll_view_test.dart b/packages/flutter/test/widgets/nested_scroll_view_test.dart index 81c8dc25b8..a18a5d9dd1 100644 --- a/packages/flutter/test/widgets/nested_scroll_view_test.dart +++ b/packages/flutter/test/widgets/nested_scroll_view_test.dart @@ -535,9 +535,8 @@ void main() { }); testWidgets('Three NestedScrollViews with one ScrollController', - // TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 - experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), // TODO(polina-c): Remove when PageView is fixed, https://github.com/flutter/flutter/issues/141119 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), (WidgetTester tester) async { final TrackingScrollController controller = TrackingScrollController(); addTearDown(controller.dispose); diff --git a/packages/flutter/test/widgets/page_view_test.dart b/packages/flutter/test/widgets/page_view_test.dart index 6d3717a012..afebbba2df 100644 --- a/packages/flutter/test/widgets/page_view_test.dart +++ b/packages/flutter/test/widgets/page_view_test.dart @@ -419,7 +419,10 @@ void main() { expect(previousPageCompleted, true); }); - testWidgets('PageView in zero-size container', (WidgetTester tester) async { + testWidgets('PageView in zero-size container', + // TODO(polina-c): Remove when PageView is fixed, https://github.com/flutter/flutter/issues/141119 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, child: Center( @@ -599,7 +602,10 @@ void main() { expect(tester.getTopLeft(find.text('Idaho')), const Offset(790.0, 0.0)); }); - testWidgets('Page snapping disable and reenable', (WidgetTester tester) async { + testWidgets('Page snapping disable and reenable', + // TODO(polina-c): Remove when PageView is fixed, https://github.com/flutter/flutter/issues/141119 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { final List log = []; Widget build({ required bool pageSnapping }) { diff --git a/packages/flutter/test/widgets/scroll_aware_image_provider_test.dart b/packages/flutter/test/widgets/scroll_aware_image_provider_test.dart index 7615dffbb2..e5f1e8b6b8 100644 --- a/packages/flutter/test/widgets/scroll_aware_image_provider_test.dart +++ b/packages/flutter/test/widgets/scroll_aware_image_provider_test.dart @@ -34,7 +34,10 @@ void main() { return Scrollable.of(find.byType(TestWidget).evaluate().first).position; } - testWidgets('ScrollAwareImageProvider does not delay if widget is not in scrollable', (WidgetTester tester) async { + testWidgets('ScrollAwareImageProvider does not delay if widget is not in scrollable', + // TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { final GlobalKey key = GlobalKey(); await tester.pumpWidget(TestWidget(key)); @@ -99,7 +102,10 @@ void main() { expect(findPhysics(tester).velocities, [0]); }); - testWidgets('ScrollAwareImageProvider does not delay if in scrollable that is scrolling slowly', (WidgetTester tester) async { + testWidgets('ScrollAwareImageProvider does not delay if in scrollable that is scrolling slowly', + // TODO(polina-c): make sure images are disposed, https://github.com/flutter/flutter/issues/141388 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { final List> keys = >[]; final ScrollController scrollController = ScrollController(); addTearDown(scrollController.dispose); diff --git a/packages/flutter/test/widgets/scrollable_restoration_test.dart b/packages/flutter/test/widgets/scrollable_restoration_test.dart index 1770b653e9..7fc9478077 100644 --- a/packages/flutter/test/widgets/scrollable_restoration_test.dart +++ b/packages/flutter/test/widgets/scrollable_restoration_test.dart @@ -282,7 +282,10 @@ void main() { await pageViewScrollAndRestore(tester); }); - testWidgets('PageView.builder restoration', (WidgetTester tester) async { + testWidgets('PageView.builder restoration', + // TODO(polina-c): Remove when PageView is fixed, https://github.com/flutter/flutter/issues/141119 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { await tester.pumpWidget( TestHarness( child: PageView.builder( @@ -298,7 +301,10 @@ void main() { await pageViewScrollAndRestore(tester); }); - testWidgets('PageView.custom restoration', (WidgetTester tester) async { + testWidgets('PageView.custom restoration', + // TODO(polina-c): Remove when PageView is fixed, https://github.com/flutter/flutter/issues/141119 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { await tester.pumpWidget( TestHarness( child: PageView.custom( diff --git a/packages/flutter/test/widgets/tracking_scroll_controller_test.dart b/packages/flutter/test/widgets/tracking_scroll_controller_test.dart index acddc981af..d9d8cb1a7d 100644 --- a/packages/flutter/test/widgets/tracking_scroll_controller_test.dart +++ b/packages/flutter/test/widgets/tracking_scroll_controller_test.dart @@ -64,7 +64,10 @@ void main() { expect(controller.initialScrollOffset, 0.0); }); - testWidgets('TrackingScrollController saves offset', (WidgetTester tester) async { + testWidgets('TrackingScrollController saves offset', + // TODO(polina-c): Remove when PageView is fixed, https://github.com/flutter/flutter/issues/141119 + experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), + (WidgetTester tester) async { int attach = 0; int detach = 0; final TrackingScrollController controller = TrackingScrollController( diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index b035088f94..75219df01b 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -123,7 +123,7 @@ E? _lastWhereOrNull(Iterable list, bool Function(E) test) { /// during test execution. /// Otherwise [LeakTesting.settings] is used. /// Adjust [LeakTesting.settings] in flutter_test_config.dart -/// (see https://github.com/flutter/flutter/blob/master/packages/flutter_test/lib/flutter_test.dart) +/// (see https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html) /// for the entire package or folder, or in the test's main for a test file /// (don't use [setUp] or [setUpAll]). /// To turn off leak tracking just for one test, set [experimentalLeakTesting] to