@@ -31,33 +31,6 @@ import 'examples/example_descriptor.dart';
3131import 'expect.dart' ;
3232
3333extension WidgetTesterExtension on WidgetTester {
34- Future <RunFinishedAnalyticsEvent > waitForRunFinishedAnalyticsEvent ({
35- Duration timeout = const Duration (seconds: 30 ),
36- Duration step = const Duration (milliseconds: 100 ),
37- Object ? previousEvent, // optional guard
38- }) async {
39- final deadline = DateTime .now ().add (timeout);
40-
41- while (DateTime .now ().isBefore (deadline)) {
42- // Drive frames/timers on Web-server device.
43- await pump (step);
44-
45- final e = PlaygroundComponents .analyticsService.lastEvent;
46-
47- // Optional: ensure we don't accept an old event from a previous run.
48- if (previousEvent != null && identical (e, previousEvent)) {
49- continue ;
50- }
51-
52- if (e is RunFinishedAnalyticsEvent ) return e;
53- }
54-
55- throw TestFailure (
56- 'Timed out waiting for RunFinishedAnalyticsEvent. '
57- 'Last event: ${PlaygroundComponents .analyticsService .lastEvent }' ,
58- );
59- }
60-
6134 //workaround for https://github.com/flutter/flutter/issues/120060
6235 Future <void > enterCodeFieldText (String text) async {
6336 final codeField = widget (find.snippetCodeField ());
@@ -175,6 +148,19 @@ extension WidgetTesterExtension on WidgetTester {
175148 expectOutputIfDeployed (example, this );
176149 }
177150
151+ Future <void > pumpUntil (
152+ bool Function () condition, {
153+ Duration timeout = const Duration (seconds: 60 ),
154+ Duration step = const Duration (milliseconds: 100 ),
155+ }) async {
156+ final deadline = DateTime .now ().add (timeout);
157+ while (DateTime .now ().isBefore (deadline)) {
158+ await pump (step);
159+ if (condition ()) return ;
160+ }
161+ throw TestFailure ('Timed out waiting for condition' );
162+ }
163+
178164 Future <void > modifyRunExpectReal (ExampleDescriptor example) async {
179165 modifyCodeController ();
180166
@@ -186,16 +172,12 @@ extension WidgetTesterExtension on WidgetTester {
186172 await tap (find.runOrCancelButton ());
187173 await pump (); // start the click handler
188174
175+ await pumpUntil (() => find.runOrCancelButton ().evaluate ().isNotEmpty);
176+
177+ // Now check output
189178 final actualText = findOutputText ();
190179 expect (actualText, isNot (startsWith (kCachedResultsLog)));
191180 expectOutputIfDeployed (example, this );
192-
193- final finishedEvent = await waitForRunFinishedAnalyticsEvent (
194- previousEvent: before,
195- timeout: const Duration (seconds: 60 ), // optional bump for web
196- );
197-
198- expect (finishedEvent.snippetContext, eventSnippetContext);
199181 }
200182
201183 /// Modifies the code controller in a unique way by inserting timestamp
0 commit comments