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
- // @dart = 2.9
6
-
7
5
import 'dart:async' ;
8
6
import 'dart:convert' ;
9
7
import 'dart:io' ;
@@ -56,45 +54,53 @@ enum IndexBaseMode { noBase, base }
56
54
enum NullSafety { weak, sound }
57
55
58
56
class TestContext {
59
- String appUrl;
60
- WipConnection tabConnection;
61
- WipConnection extensionConnection;
62
- TestServer testServer;
63
- BuildDaemonClient daemonClient;
64
- ResidentWebRunner webRunner;
65
- WebDriver webDriver;
66
- Process chromeDriver;
67
- AppConnection appConnection;
68
- DebugConnection debugConnection;
69
- WebkitDebugger webkitDebugger;
70
- Client client;
71
- ExpressionCompilerService ddcService;
72
- int port;
73
- Directory _outputDir;
74
- File _entryFile;
75
- Uri _packageConfigFile;
76
- Uri _projectDirectory;
77
- String _entryContents;
78
-
79
- /// Null safety mode for the frontend server.
80
- ///
81
- /// Note: flutter's frontend server is always launched with
82
- /// the null safety setting inferred from project configurations
83
- /// or the source code. We skip this inference and just set it
84
- /// here to the desired value manually.
85
- ///
86
- /// Note: build_runner-based setups ignore this setting and read
87
- /// this value from the ddc debug metadata and pass it to the
88
- /// expression compiler worker initialization API.
89
- ///
90
- /// TODO(annagrin): Currently setting sound null safety for frontend
91
- /// server tests fails due to missing sound SDK JavaScript and maps.
92
- /// Issue: https://github.com/dart-lang/webdev/issues/1591
93
- NullSafety nullSafety;
57
+ String get appUrl => _appUrl! ;
58
+ late String ? _appUrl;
59
+
60
+ WipConnection get tabConnection => _tabConnection! ;
61
+ late WipConnection ? _tabConnection;
62
+
63
+ TestServer get testServer => _testServer! ;
64
+ TestServer ? _testServer;
65
+
66
+ BuildDaemonClient get daemonClient => _daemonClient! ;
67
+ BuildDaemonClient ? _daemonClient;
68
+
69
+ ResidentWebRunner get webRunner => _webRunner! ;
70
+ ResidentWebRunner ? _webRunner;
71
+
72
+ WebDriver get webDriver => _webDriver! ;
73
+ WebDriver ? _webDriver;
74
+
75
+ Process get chromeDriver => _chromeDriver! ;
76
+ late Process ? _chromeDriver;
77
+
78
+ WebkitDebugger get webkitDebugger => _webkitDebugger! ;
79
+ late WebkitDebugger ? _webkitDebugger;
80
+
81
+ Client get client => _client! ;
82
+ late Client ? _client;
83
+
84
+ ExpressionCompilerService ? ddcService;
85
+
86
+ int get port => _port! ;
87
+ late int ? _port;
88
+
89
+ Directory get outputDir => _outputDir! ;
90
+ late Directory ? _outputDir;
91
+
92
+ late WipConnection extensionConnection;
93
+ late AppConnection appConnection;
94
+ late DebugConnection debugConnection;
95
+ late File _entryFile;
96
+ late Uri _packageConfigFile;
97
+ late Uri _projectDirectory;
98
+ late String _entryContents;
99
+
94
100
final _logger = logging.Logger ('Context' );
95
101
96
102
/// Top level directory in which we run the test server..
97
- String workingDirectory;
103
+ late String workingDirectory;
98
104
99
105
/// The path to build and serve.
100
106
String pathToServe;
@@ -103,8 +109,8 @@ class TestContext {
103
109
String path;
104
110
105
111
TestContext (
106
- {String directory,
107
- String entry,
112
+ {String ? directory,
113
+ String ? entry,
108
114
this .path = 'hello_world/index.html' ,
109
115
this .pathToServe = 'example' }) {
110
116
final relativeDirectory = p.join ('..' , 'fixtures' , '_test' );
@@ -144,19 +150,19 @@ class TestContext {
144
150
bool spawnDds = true ,
145
151
String hostname = 'localhost' ,
146
152
bool waitToDebug = false ,
147
- UrlEncoder urlEncoder,
153
+ UrlEncoder ? urlEncoder,
148
154
CompilationMode compilationMode = CompilationMode .buildDaemon,
149
155
NullSafety nullSafety = NullSafety .weak,
150
156
bool enableExpressionEvaluation = false ,
151
157
bool verboseCompiler = false ,
152
- SdkConfigurationProvider sdkConfigurationProvider,
158
+ SdkConfigurationProvider ? sdkConfigurationProvider,
153
159
}) async {
154
160
sdkConfigurationProvider ?? = DefaultSdkConfigurationProvider ();
155
161
156
162
try {
157
163
configureLogWriter ();
158
164
159
- client = IOClient (HttpClient ()
165
+ _client = IOClient (HttpClient ()
160
166
..maxConnectionsPerHost = 200
161
167
..idleTimeout = const Duration (seconds: 30 )
162
168
..connectionTimeout = const Duration (seconds: 30 ));
@@ -167,7 +173,7 @@ class TestContext {
167
173
final chromeDriverPort = await findUnusedPort ();
168
174
final chromeDriverUrlBase = 'wd/hub' ;
169
175
try {
170
- chromeDriver = await Process .start ('chromedriver$_exeExt ' ,
176
+ _chromeDriver = await Process .start ('chromedriver$_exeExt ' ,
171
177
['--port=$chromeDriverPort ' , '--url-base=$chromeDriverUrlBase ' ]);
172
178
// On windows this takes a while to boot up, wait for the first line
173
179
// of stdout as a signal that it is ready.
@@ -195,14 +201,14 @@ class TestContext {
195
201
await Process .run (dartPath, ['pub' , 'upgrade' ],
196
202
workingDirectory: workingDirectory);
197
203
198
- ExpressionCompiler expressionCompiler;
204
+ ExpressionCompiler ? expressionCompiler;
199
205
AssetReader assetReader;
200
206
Handler assetHandler;
201
207
Stream <BuildResults > buildResults;
202
208
RequireStrategy requireStrategy;
203
209
String basePath = '' ;
204
210
205
- port = await findUnusedPort ();
211
+ _port = await findUnusedPort ();
206
212
switch (compilationMode) {
207
213
case CompilationMode .buildDaemon:
208
214
{
@@ -213,7 +219,7 @@ class TestContext {
213
219
],
214
220
'--verbose' ,
215
221
];
216
- daemonClient =
222
+ _daemonClient =
217
223
await connectClient (workingDirectory, options, (log) {
218
224
final record = log.toLogRecord ();
219
225
final name =
@@ -263,14 +269,14 @@ class TestContext {
263
269
final entry = p.toUri (_entryFile.path
264
270
.substring (_projectDirectory.toFilePath ().length + 1 ));
265
271
266
- webRunner = ResidentWebRunner (
272
+ _webRunner = ResidentWebRunner (
267
273
entry,
268
274
urlEncoder,
269
275
_projectDirectory,
270
276
_packageConfigFile,
271
277
[_projectDirectory],
272
278
'org-dartlang-app' ,
273
- _outputDir .path,
279
+ outputDir .path,
274
280
nullSafety == NullSafety .sound,
275
281
verboseCompiler,
276
282
);
@@ -315,14 +321,14 @@ class TestContext {
315
321
]
316
322
}
317
323
});
318
- webDriver = await createDriver (
324
+ _webDriver = await createDriver (
319
325
spec: WebDriverSpec .JsonWire ,
320
326
desired: capabilities,
321
327
uri: Uri .parse (
322
328
'http://127.0.0.1:$chromeDriverPort /$chromeDriverUrlBase /' ));
323
329
final connection = ChromeConnection ('localhost' , debugPort);
324
330
325
- testServer = await TestServer .start (
331
+ _testServer = await TestServer .start (
326
332
hostname,
327
333
port,
328
334
assetHandler,
@@ -342,13 +348,14 @@ class TestContext {
342
348
ddcService,
343
349
);
344
350
345
- appUrl = basePath.isEmpty
351
+ _appUrl = basePath.isEmpty
346
352
? 'http://localhost:$port /$path '
347
353
: 'http://localhost:$port /$basePath /$path ' ;
348
354
349
- await webDriver.get (appUrl);
350
- final tab = await connection.getTab ((t) => t.url == appUrl);
351
- tabConnection = await tab.connect ();
355
+ await _webDriver? .get (appUrl);
356
+ final tab = await (connection.getTab ((t) => t.url == appUrl)
357
+ as FutureOr <ChromeTab >);
358
+ _tabConnection = await tab.connect ();
352
359
await tabConnection.runtime.enable ();
353
360
await tabConnection.debugger.enable ();
354
361
@@ -370,30 +377,30 @@ class TestContext {
370
377
371
378
Future <void > startDebugging () async {
372
379
debugConnection = await testServer.dwds.debugConnection (appConnection);
373
- webkitDebugger = WebkitDebugger (WipDebugger (tabConnection));
380
+ _webkitDebugger = WebkitDebugger (WipDebugger (tabConnection));
374
381
}
375
382
376
383
Future <void > tearDown () async {
377
- await webDriver ? .quit (closeSession: true );
378
- chromeDriver ? .kill ();
384
+ await _webDriver ? .quit (closeSession: true );
385
+ _chromeDriver ? .kill ();
379
386
DartUri .currentDirectory = p.current;
380
387
_entryFile.writeAsStringSync (_entryContents);
381
- await daemonClient ? .close ();
388
+ await _daemonClient ? .close ();
382
389
await ddcService? .stop ();
383
- await webRunner ? .stop ();
384
- await testServer ? .stop ();
385
- client ? .close ();
390
+ await _webRunner ? .stop ();
391
+ await _testServer ? .stop ();
392
+ _client ? .close ();
386
393
await _outputDir? .delete (recursive: true );
387
394
stopLogWriter ();
388
395
389
396
// clear the state for next setup
390
- webDriver = null ;
391
- chromeDriver = null ;
392
- daemonClient = null ;
397
+ _webDriver = null ;
398
+ _chromeDriver = null ;
399
+ _daemonClient = null ;
393
400
ddcService = null ;
394
- webRunner = null ;
395
- testServer = null ;
396
- client = null ;
401
+ _webRunner = null ;
402
+ _testServer = null ;
403
+ _client = null ;
397
404
_outputDir = null ;
398
405
}
399
406
@@ -402,7 +409,7 @@ class TestContext {
402
409
_entryContents.replaceAll ('Hello World!' , 'Gary is awesome!' ));
403
410
404
411
// Wait for the build.
405
- await daemonClient .buildResults.firstWhere ((results) => results.results
412
+ await _daemonClient ? .buildResults.firstWhere ((results) => results.results
406
413
.any ((result) => result.status == BuildStatus .succeeded));
407
414
408
415
// Allow change to propagate to the browser.
@@ -438,8 +445,8 @@ class TestContext {
438
445
Future <int > findBreakpointLine (
439
446
String breakpointId, String isolateId, ScriptRef scriptRef) async {
440
447
final script = await debugConnection.vmService
441
- .getObject (isolateId, scriptRef.id) as Script ;
442
- final lines = LineSplitter .split (script.source).toList ();
448
+ .getObject (isolateId, scriptRef.id! ) as Script ;
449
+ final lines = LineSplitter .split (script.source! ).toList ();
443
450
final lineNumber =
444
451
lines.indexWhere ((l) => l.endsWith ('// Breakpoint: $breakpointId ' ));
445
452
if (lineNumber == - 1 ) {
0 commit comments