77@Timeout (Duration (minutes: 5 ))
88library ;
99
10+ import 'dart:async' ;
11+
1012import 'package:dwds/expression_compiler.dart' ;
1113import 'package:test/test.dart' ;
1214import 'package:test_common/logging.dart' ;
@@ -46,6 +48,20 @@ void main() {
4648 await recompile ();
4749 }
4850
51+ /// Wait for `evaluate` to finish executing before checking expectations by
52+ /// checking for a log output.
53+ Future <void > waitForEvaluateToExecute () async {
54+ final completer = Completer <void >();
55+ final expectedString = 'evaluate executed' ;
56+ final subscription = context.webkitDebugger.onConsoleAPICalled.listen ((e) {
57+ if (e.args.first.value == expectedString) {
58+ completer.complete ();
59+ }
60+ });
61+ await completer.future;
62+ await subscription.cancel ();
63+ }
64+
4965 group ('Injected client' , () {
5066 late VmService fakeClient;
5167
@@ -81,8 +97,10 @@ void main() {
8197 expect (source, contains (originalString));
8298 expect (source.contains (newString), false );
8399
100+ final evaluateDone = waitForEvaluateToExecute ();
84101 final rootLib = isolate.rootLib;
85102 await client.evaluate (isolate.id! , rootLib! .id! , 'evaluate()' );
103+ await evaluateDone;
86104 source = await context.webDriver.pageSource;
87105 expect (source, contains (newString));
88106 expect (source.contains (originalString), false );
@@ -99,8 +117,10 @@ void main() {
99117 var report = await fakeClient.reloadSources (isolate.id! );
100118 expect (report.success, true );
101119
120+ var evaluateDone = waitForEvaluateToExecute ();
102121 final rootLib = isolate.rootLib;
103122 await client.evaluate (isolate.id! , rootLib! .id! , 'evaluate()' );
123+ await evaluateDone;
104124 var source = await context.webDriver.pageSource;
105125 expect (source, contains (originalString));
106126 expect (source.contains (newString), false );
@@ -110,7 +130,9 @@ void main() {
110130 report = await fakeClient.reloadSources (isolate.id! );
111131 expect (report.success, true );
112132
133+ evaluateDone = waitForEvaluateToExecute ();
113134 await client.evaluate (isolate.id! , rootLib.id! , 'evaluate()' );
135+ await evaluateDone;
114136 source = await context.webDriver.pageSource;
115137 expect (source, contains (newString));
116138 expect (source.contains (originalString), false );
@@ -120,7 +142,9 @@ void main() {
120142 report = await fakeClient.reloadSources (isolate.id! );
121143 expect (report.success, true );
122144
145+ evaluateDone = waitForEvaluateToExecute ();
123146 await client.evaluate (isolate.id! , rootLib.id! , 'evaluate()' );
147+ await evaluateDone;
124148 source = await context.webDriver.pageSource;
125149 expect (source, contains (newString));
126150 expect (source.contains (originalString), false );
0 commit comments