@@ -156,6 +156,23 @@ void main() {
156
156
await client.resume (isolate.id! );
157
157
}
158
158
159
+ // When the program is executing, we want to check that at some point it
160
+ // will execute code that will emit [expectedString].
161
+ Future <void > resumeAndExpectLog (String expectedString) async {
162
+ final completer = Completer <void >();
163
+ final newSubscription = context.webkitDebugger.onConsoleAPICalled.listen ((
164
+ e,
165
+ ) {
166
+ if (e.args.first.value == expectedString) {
167
+ completer.complete ();
168
+ }
169
+ });
170
+ await resume ();
171
+ await completer.future.then ((_) {
172
+ newSubscription.cancel ();
173
+ });
174
+ }
175
+
159
176
Future <List <Breakpoint >> hotReloadAndHandlePausePost (
160
177
List <({String file, String breakpointMarker, Breakpoint ? bp})>
161
178
breakpoints,
@@ -198,6 +215,26 @@ void main() {
198
215
await client.evaluate (isolate.id! , rootLib! .id! , 'evaluate()' );
199
216
}
200
217
218
+ // Much like `resumeAndExpectLog`, we need a completer to ensure the log
219
+ // will eventually occur when code is executing.
220
+ Future <void > callEvaluateAndExpectLog (String expectedString) async {
221
+ final completer = Completer <void >();
222
+ final newSubscription = context.webkitDebugger.onConsoleAPICalled.listen ((
223
+ e,
224
+ ) {
225
+ if (e.args.first.value == expectedString) {
226
+ completer.complete ();
227
+ }
228
+ });
229
+ final vm = await client.getVM ();
230
+ final isolate = await client.getIsolate (vm.isolates! .first.id! );
231
+ final rootLib = isolate.rootLib;
232
+ await client.evaluate (isolate.id! , rootLib! .id! , 'evaluate()' );
233
+ await completer.future.then ((_) {
234
+ newSubscription.cancel ();
235
+ });
236
+ }
237
+
201
238
test ('after edit and hot reload, breakpoint is in new file' , () async {
202
239
final oldString = 'main gen0' ;
203
240
final newString = 'main gen1' ;
@@ -214,8 +251,7 @@ void main() {
214
251
(event) => event.kind == EventKind .kPauseBreakpoint,
215
252
);
216
253
expect (consoleLogs.contains (oldString), false );
217
- await resume ();
218
- expect (consoleLogs.contains (oldString), true );
254
+ await resumeAndExpectLog (oldString);
219
255
220
256
consoleLogs.clear ();
221
257
@@ -233,8 +269,7 @@ void main() {
233
269
(event) => event.kind == EventKind .kPauseBreakpoint,
234
270
);
235
271
expect (consoleLogs.contains (newString), false );
236
- await resume ();
237
- expect (consoleLogs.contains (newString), true );
272
+ await resumeAndExpectLog (newString);
238
273
});
239
274
240
275
test ('after adding line, hot reload, removing line, and hot reload, '
@@ -253,8 +288,7 @@ void main() {
253
288
(event) => event.kind == EventKind .kPauseBreakpoint,
254
289
);
255
290
expect (consoleLogs.contains (genLog), false );
256
- await resume ();
257
- expect (consoleLogs.contains (genLog), true );
291
+ await resumeAndExpectLog (genLog);
258
292
259
293
consoleLogs.clear ();
260
294
@@ -276,8 +310,7 @@ void main() {
276
310
(event) => event.kind == EventKind .kPauseBreakpoint,
277
311
);
278
312
expect (consoleLogs.contains (extraLog), true );
279
- await resume ();
280
- expect (consoleLogs.contains (genLog), true );
313
+ await resumeAndExpectLog (genLog);
281
314
282
315
consoleLogs.clear ();
283
316
@@ -295,8 +328,7 @@ void main() {
295
328
(event) => event.kind == EventKind .kPauseBreakpoint,
296
329
);
297
330
expect (consoleLogs.contains (extraLog), false );
298
- await resume ();
299
- expect (consoleLogs.contains (genLog), true );
331
+ await resumeAndExpectLog (genLog);
300
332
});
301
333
302
334
test (
@@ -317,8 +349,7 @@ void main() {
317
349
(event) => event.kind == EventKind .kPauseBreakpoint,
318
350
);
319
351
expect (consoleLogs.contains (genLog), false );
320
- await resume ();
321
- expect (consoleLogs.contains (genLog), true );
352
+ await resumeAndExpectLog (genLog);
322
353
323
354
consoleLogs.clear ();
324
355
@@ -359,8 +390,7 @@ void main() {
359
390
(event) => event.kind == EventKind .kPauseBreakpoint,
360
391
);
361
392
expect (consoleLogs.contains (libGenLog), false );
362
- await resume ();
363
- expect (consoleLogs.contains (libGenLog), true );
393
+ await resumeAndExpectLog (libGenLog);
364
394
365
395
context.removeLibraryFile (libFileName: libFile);
366
396
},
@@ -390,8 +420,7 @@ void main() {
390
420
final oldCapturedString = 'captured closure gen0' ;
391
421
expect (consoleLogs.contains (oldCapturedString), false );
392
422
// Closure gets evaluated for the first time.
393
- await resume ();
394
- expect (consoleLogs.contains (oldCapturedString), true );
423
+ await resumeAndExpectLog (oldCapturedString);
395
424
396
425
final newCapturedString = 'captured closure gen1' ;
397
426
await makeEditAndRecompile (
@@ -404,20 +433,9 @@ void main() {
404
433
(file: mainFile, breakpointMarker: capturedStringMarker, bp: bp),
405
434
]);
406
435
407
- // Use a completer as we won't hit a pause.
408
- final completer = Completer <void >();
409
- final consoleSubscription = context.webkitDebugger.onConsoleAPICalled
410
- .listen ((e) {
411
- if (e.args.first.value == oldCapturedString) {
412
- completer.complete ();
413
- }
414
- });
415
-
416
- await callEvaluate ();
417
-
418
- // Breakpoint should not have been hit as it's now deleted. We should also
419
- // see the old string still as the closure has not been reevaluated.
420
- await completer.future;
436
+ // Breakpoint should not be hit as it's now deleted. We should also see
437
+ // the old string still as the closure has not been reevaluated.
438
+ await callEvaluateAndExpectLog (oldCapturedString);
421
439
422
440
await consoleSubscription.cancel ();
423
441
});
@@ -445,30 +463,29 @@ void main() {
445
463
await context.tearDown ();
446
464
});
447
465
448
- Future <void > callEvaluate () async {
466
+ Future <void > callEvaluateAndExpectLog (String expectedString) async {
467
+ final completer = Completer <void >();
468
+ final newSubscription = context.webkitDebugger.onConsoleAPICalled.listen ((
469
+ e,
470
+ ) {
471
+ if (e.args.first.value == expectedString) {
472
+ completer.complete ();
473
+ }
474
+ });
449
475
final vm = await client.getVM ();
450
476
final isolate = await client.getIsolate (vm.isolates! .first.id! );
451
477
final rootLib = isolate.rootLib;
452
478
await client.evaluate (isolate.id! , rootLib! .id! , 'evaluate()' );
479
+ await completer.future.then ((_) {
480
+ newSubscription.cancel ();
481
+ });
453
482
}
454
483
455
484
test ('no pause when calling reloadSources' , () async {
456
485
final oldString = 'main gen0' ;
457
486
final newString = 'main gen1' ;
458
487
459
- // Use a completer as we won't hit a pause.
460
- var completer = Completer <void >();
461
- var consoleSubscription = context.webkitDebugger.onConsoleAPICalled
462
- .listen ((e) {
463
- if (e.args.first.value == oldString) {
464
- completer.complete ();
465
- }
466
- });
467
-
468
- await callEvaluate ();
469
- await completer.future;
470
-
471
- await consoleSubscription.cancel ();
488
+ await callEvaluateAndExpectLog (oldString);
472
489
473
490
// Modify the string that gets printed and hot reload.
474
491
await makeEditAndRecompile (mainFile, oldString, newString);
@@ -477,20 +494,8 @@ void main() {
477
494
final report = await client.reloadSources (isolate.id! );
478
495
expect (report.success, true );
479
496
480
- completer = Completer <void >();
481
- consoleSubscription = context.webkitDebugger.onConsoleAPICalled.listen ((
482
- e,
483
- ) {
484
- if (e.args.first.value == newString) {
485
- completer.complete ();
486
- }
487
- });
488
-
489
497
// Program should not be paused, so this should execute.
490
- await callEvaluate ();
491
- await completer.future;
492
-
493
- await consoleSubscription.cancel ();
498
+ await callEvaluateAndExpectLog (newString);
494
499
});
495
500
}, timeout: Timeout .factor (2 ));
496
501
}
0 commit comments