7
7
@Timeout (Duration (minutes: 5 ))
8
8
library ;
9
9
10
+ import 'dart:async' ;
11
+
10
12
import 'package:dwds/expression_compiler.dart' ;
11
13
import 'package:test/test.dart' ;
12
14
import 'package:test_common/logging.dart' ;
@@ -46,6 +48,20 @@ void main() {
46
48
await recompile ();
47
49
}
48
50
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
+
49
65
group ('Injected client' , () {
50
66
late VmService fakeClient;
51
67
@@ -81,8 +97,10 @@ void main() {
81
97
expect (source, contains (originalString));
82
98
expect (source.contains (newString), false );
83
99
100
+ final evaluateDone = waitForEvaluateToExecute ();
84
101
final rootLib = isolate.rootLib;
85
102
await client.evaluate (isolate.id! , rootLib! .id! , 'evaluate()' );
103
+ await evaluateDone;
86
104
source = await context.webDriver.pageSource;
87
105
expect (source, contains (newString));
88
106
expect (source.contains (originalString), false );
@@ -99,8 +117,10 @@ void main() {
99
117
var report = await fakeClient.reloadSources (isolate.id! );
100
118
expect (report.success, true );
101
119
120
+ var evaluateDone = waitForEvaluateToExecute ();
102
121
final rootLib = isolate.rootLib;
103
122
await client.evaluate (isolate.id! , rootLib! .id! , 'evaluate()' );
123
+ await evaluateDone;
104
124
var source = await context.webDriver.pageSource;
105
125
expect (source, contains (originalString));
106
126
expect (source.contains (newString), false );
@@ -110,7 +130,9 @@ void main() {
110
130
report = await fakeClient.reloadSources (isolate.id! );
111
131
expect (report.success, true );
112
132
133
+ evaluateDone = waitForEvaluateToExecute ();
113
134
await client.evaluate (isolate.id! , rootLib.id! , 'evaluate()' );
135
+ await evaluateDone;
114
136
source = await context.webDriver.pageSource;
115
137
expect (source, contains (newString));
116
138
expect (source.contains (originalString), false );
@@ -120,7 +142,9 @@ void main() {
120
142
report = await fakeClient.reloadSources (isolate.id! );
121
143
expect (report.success, true );
122
144
145
+ evaluateDone = waitForEvaluateToExecute ();
123
146
await client.evaluate (isolate.id! , rootLib.id! , 'evaluate()' );
147
+ await evaluateDone;
124
148
source = await context.webDriver.pageSource;
125
149
expect (source, contains (newString));
126
150
expect (source.contains (originalString), false );
0 commit comments