From d843863c4aa4f49e557aecbe9bb1e489fa064e8d Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 1 Nov 2023 13:09:41 -0700 Subject: [PATCH] reset state of CustomSemanticsAction before running tests (#137697) Fixes https://github.com/flutter/flutter/issues/137696 This will get the tree green again. The problem is that `CustomSemanticsAction` has static state in it, and todays test seed order makes things unhappy. --- packages/flutter/lib/src/semantics/semantics.dart | 11 +++++++++++ packages/flutter_test/lib/src/binding.dart | 1 + 2 files changed, 12 insertions(+) diff --git a/packages/flutter/lib/src/semantics/semantics.dart b/packages/flutter/lib/src/semantics/semantics.dart index c877d6bf7b6..48f5f735bcd 100644 --- a/packages/flutter/lib/src/semantics/semantics.dart +++ b/packages/flutter/lib/src/semantics/semantics.dart @@ -274,6 +274,17 @@ class CustomSemanticsAction { static CustomSemanticsAction? getAction(int id) { return _actions[id]; } + + /// Resets internal state between tests. Does nothing if asserts are disabled. + @visibleForTesting + static void resetForTests() { + assert(() { + _actions.clear(); + _ids.clear(); + _nextId = 0; + return true; + }()); + } } /// A string that carries a list of [StringAttribute]s. diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 7be1c7a71bb..5a54b24901f 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -251,6 +251,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase if (registerTestTextInput) { _testTextInput.register(); } + CustomSemanticsAction.resetForTests(); // ignore: invalid_use_of_visible_for_testing_member } @override