2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- @Skip ('https://github.com/dart-lang/webdev/issues/1845 - Move to cron job.' )
6
5
@TestOn ('vm' )
7
6
@Timeout (Duration (minutes: 5 ))
8
7
import 'package:dwds/src/loaders/strategy.dart' ;
@@ -19,6 +18,9 @@ final context = TestContext.withSoundNullSafety(
19
18
htmlEntryFileName: 'index.html' ,
20
19
);
21
20
21
+ const originalString = 'Hello World!' ;
22
+ const newString = 'Bonjour le monde!' ;
23
+
22
24
void main () {
23
25
// set to true for debug logging.
24
26
final debug = false ;
@@ -32,17 +34,17 @@ void main() {
32
34
});
33
35
34
36
tearDown (() async {
37
+ undoEdit ();
35
38
await context.tearDown ();
36
39
});
37
40
38
41
test ('can live reload changes ' , () async {
39
- await context.changeInput ();
40
-
42
+ await makeEditAndWaitForRebuild ();
41
43
final source = await context.webDriver.pageSource;
42
44
43
45
// A full reload should clear the state.
44
- expect (source.contains ('Hello World!' ), isFalse);
45
- expect (source.contains ('Gary is awesome!' ), isTrue);
46
+ expect (source.contains (originalString ), isFalse);
47
+ expect (source.contains (newString ), isTrue);
46
48
});
47
49
});
48
50
@@ -56,17 +58,18 @@ void main() {
56
58
});
57
59
58
60
tearDown (() async {
61
+ undoEdit ();
59
62
await context.tearDown ();
60
63
});
61
64
62
65
test ('can live reload changes ' , () async {
63
- await context. changeInput ();
66
+ await makeEditAndWaitForRebuild ();
64
67
65
68
final source = await context.webDriver.pageSource;
66
69
67
70
// A full reload should clear the state.
68
- expect (source.contains ('Hello World!' ), isFalse);
69
- expect (source.contains ('Gary is awesome!' ), isTrue);
71
+ expect (source.contains (originalString ), isFalse);
72
+ expect (source.contains (newString ), isTrue);
70
73
});
71
74
});
72
75
@@ -82,16 +85,17 @@ void main() {
82
85
83
86
tearDown (() async {
84
87
await context.tearDown ();
88
+ undoEdit ();
85
89
});
86
90
87
91
test ('can live reload changes ' , () async {
88
- await context. changeInput ();
92
+ await makeEditAndWaitForRebuild ();
89
93
90
94
final source = await context.webDriver.pageSource;
91
95
92
96
// A full reload should clear the state.
93
- expect (source.contains ('Hello World!' ), isFalse);
94
- expect (source.contains ('Gary is awesome!' ), isTrue);
97
+ expect (source.contains (originalString ), isFalse);
98
+ expect (source.contains (newString ), isTrue);
95
99
});
96
100
});
97
101
});
@@ -104,12 +108,13 @@ void main() {
104
108
105
109
tearDown (() async {
106
110
await context.tearDown ();
111
+ undoEdit ();
107
112
});
108
113
109
114
test ('destroys and recreates the isolate during a hot restart' , () async {
110
115
final client = context.debugConnection.vmService;
111
116
await client.streamListen ('Isolate' );
112
- await context. changeInput ();
117
+ await makeEditAndWaitForRebuild ();
113
118
114
119
final eventsDone = expectLater (
115
120
client.onIsolateEvent,
@@ -128,7 +133,7 @@ void main() {
128
133
test ('destroys and recreates the isolate during a page refresh' , () async {
129
134
final client = context.debugConnection.vmService;
130
135
await client.streamListen ('Isolate' );
131
- await context. changeInput ();
136
+ await makeEditAndWaitForRebuild ();
132
137
133
138
final eventsDone = expectLater (
134
139
client.onIsolateEvent,
@@ -146,7 +151,7 @@ void main() {
146
151
test ('can hot restart via the service extension' , () async {
147
152
final client = context.debugConnection.vmService;
148
153
await client.streamListen ('Isolate' );
149
- await context. changeInput ();
154
+ await makeEditAndWaitForRebuild ();
150
155
151
156
final eventsDone = expectLater (
152
157
client.onIsolateEvent,
@@ -163,8 +168,8 @@ void main() {
163
168
164
169
final source = await context.webDriver.pageSource;
165
170
// Main is re-invoked which shouldn't clear the state.
166
- expect (source, contains ('Hello World!' ));
167
- expect (source, contains ('Gary is awesome!' ));
171
+ expect (source, contains (originalString ));
172
+ expect (source, contains (newString ));
168
173
});
169
174
170
175
test ('can send events before and after hot restart' , () async {
@@ -218,7 +223,7 @@ void main() {
218
223
test ('can refresh the page via the fullReload service extension' , () async {
219
224
final client = context.debugConnection.vmService;
220
225
await client.streamListen ('Isolate' );
221
- await context. changeInput ();
226
+ await makeEditAndWaitForRebuild ();
222
227
223
228
final eventsDone = expectLater (
224
229
client.onIsolateEvent,
@@ -234,8 +239,8 @@ void main() {
234
239
235
240
final source = await context.webDriver.pageSource;
236
241
// Should see only the new text
237
- expect (source, isNot ( contains ('Hello World!' )) );
238
- expect (source, contains ('Gary is awesome!' ) );
242
+ expect (source. contains (originalString), isFalse );
243
+ expect (source. contains (newString), isTrue );
239
244
});
240
245
241
246
test ('can hot restart while paused' , () async {
@@ -253,13 +258,13 @@ void main() {
253
258
await stream
254
259
.firstWhere ((event) => event.kind == EventKind .kPauseBreakpoint);
255
260
256
- await context. changeInput ();
261
+ await makeEditAndWaitForRebuild ();
257
262
await client.callServiceExtension ('hotRestart' );
258
263
final source = await context.webDriver.pageSource;
259
264
260
265
// Main is re-invoked which shouldn't clear the state.
261
- expect (source.contains ('Hello World!' ), isTrue);
262
- expect (source.contains ('Gary is awesome!' ), isTrue);
266
+ expect (source.contains (originalString ), isTrue);
267
+ expect (source.contains (newString ), isTrue);
263
268
264
269
vm = await client.getVM ();
265
270
isolateId = vm.isolates! .first.id! ;
@@ -336,19 +341,20 @@ void main() {
336
341
337
342
tearDown (() async {
338
343
await context.tearDown ();
344
+ undoEdit ();
339
345
});
340
346
341
347
test ('can hot restart changes ' , () async {
342
- await context. changeInput ();
348
+ await makeEditAndWaitForRebuild ();
343
349
344
350
final source = await context.webDriver.pageSource;
345
351
346
352
// Main is re-invoked which shouldn't clear the state.
347
- expect (source.contains ('Hello World!' ), isTrue);
348
- expect (source.contains ('Gary is awesome!' ), isTrue);
353
+ expect (source.contains (originalString ), isTrue);
354
+ expect (source.contains (newString ), isTrue);
349
355
// The ext.flutter.disassemble callback is invoked and waited for.
350
- expect (source,
351
- contains ('start disassemble end disassemble Gary is awesome ' ));
356
+ expect (
357
+ source, contains ('start disassemble end disassemble $ newString ' ));
352
358
});
353
359
354
360
test ('fires isolate create/destroy events during hot restart' , () async {
@@ -363,7 +369,7 @@ void main() {
363
369
_hasKind (EventKind .kIsolateRunnable),
364
370
])));
365
371
366
- await context. changeInput ();
372
+ await makeEditAndWaitForRebuild ();
367
373
368
374
await eventsDone;
369
375
});
@@ -380,23 +386,39 @@ void main() {
380
386
381
387
tearDown (() async {
382
388
await context.tearDown ();
389
+ undoEdit ();
383
390
});
384
391
385
392
test ('can hot restart changes ' , () async {
386
- await context. changeInput ();
393
+ await makeEditAndWaitForRebuild ();
387
394
388
395
final source = await context.webDriver.pageSource;
389
396
390
397
// Main is re-invoked which shouldn't clear the state.
391
- expect (source.contains ('Hello World!' ), isTrue);
392
- expect (source.contains ('Gary is awesome!' ), isTrue);
398
+ expect (source.contains (originalString ), isTrue);
399
+ expect (source.contains (newString ), isTrue);
393
400
// The ext.flutter.disassemble callback is invoked and waited for.
394
- expect (source,
395
- contains ('start disassemble end disassemble Gary is awesome ' ));
401
+ expect (
402
+ source, contains ('start disassemble end disassemble $ newString ' ));
396
403
});
397
404
});
398
405
});
399
406
}
400
407
408
+ Future <void > makeEditAndWaitForRebuild () async {
409
+ context.makeEditToDartEntryFile (
410
+ toReplace: originalString,
411
+ replaceWith: newString,
412
+ );
413
+ await context.waitForSuccessfulBuild (propogateToBrowser: true );
414
+ }
415
+
416
+ void undoEdit () {
417
+ context.makeEditToDartEntryFile (
418
+ toReplace: newString,
419
+ replaceWith: originalString,
420
+ );
421
+ }
422
+
401
423
TypeMatcher <Event > _hasKind (String kind) =>
402
424
isA <Event >().having ((e) => e.kind, 'kind' , kind);
0 commit comments