Skip to content

Commit

Permalink
reset state of CustomSemanticsAction before running tests (#137697)
Browse files Browse the repository at this point in the history
Fixes flutter/flutter#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.
  • Loading branch information
dnfield authored Nov 1, 2023
1 parent ba75e7a commit d843863
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/flutter/lib/src/semantics/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/flutter_test/lib/src/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
if (registerTestTextInput) {
_testTextInput.register();
}
CustomSemanticsAction.resetForTests(); // ignore: invalid_use_of_visible_for_testing_member
}

@override
Expand Down

0 comments on commit d843863

Please sign in to comment.