@@ -61,40 +61,6 @@ class TestContext {
61
61
final NullSafety nullSafety;
62
62
final TestSdkConfigurationProvider sdkConfigurationProvider;
63
63
64
- /// Top level directory in which we run the test server, e.g.
65
- /// "/workstation/webdev/fixtures/_testSound".
66
- String get workingDirectory =>
67
- absolutePath (pathFromFixtures: project.packageDirectory);
68
-
69
- /// The directory to build and serve, e.g. "example".
70
- String get directoryToServe => p.split (project.webAssetsPath).first;
71
-
72
- /// The path to the HTML file to serve, relative to the [directoryToServe] ,
73
- /// e.g. "hello_world/index.html".
74
- String get filePathToServe {
75
- final pathParts = p.split (project.webAssetsPath).where (
76
- (pathPart) => pathPart != directoryToServe,
77
- );
78
- return webCompatiblePath ([...pathParts, project.htmlEntryFileName]);
79
- }
80
-
81
- /// The path to the Dart entry file, e.g,
82
- /// "/workstation/webdev/fixtures/_testSound/example/hello_world/main.dart":
83
- String get _dartEntryFilePath => absolutePath (
84
- pathFromFixtures: p.joinAll (
85
- [
86
- project.packageDirectory,
87
- project.webAssetsPath,
88
- project.dartEntryFileName,
89
- ],
90
- ),
91
- );
92
-
93
- /// The URI for the package_config.json is located in:
94
- /// <project directory>/.dart_tool/package_config
95
- Uri get _packageConfigFile =>
96
- p.toUri (p.join (workingDirectory, '.dart_tool' , 'package_config.json' ));
97
-
98
64
String get appUrl => _appUrl! ;
99
65
late String ? _appUrl;
100
66
@@ -150,14 +116,16 @@ class TestContext {
150
116
151
117
TestContext (this .project, this .sdkConfigurationProvider)
152
118
: nullSafety = project.nullSafety {
153
- DartUri .currentDirectory = workingDirectory ;
119
+ DartUri .currentDirectory = project.absolutePackageDirectory ;
154
120
155
121
project.validate ();
156
122
157
- _logger.info ('Serving: $directoryToServe /$filePathToServe ' );
158
- _logger.info ('Project: $workingDirectory ' );
159
- _logger.info ('Packages: $_packageConfigFile ' );
160
- _logger.info ('Entry: $_dartEntryFilePath ' );
123
+ _logger.info (
124
+ 'Serving: ${project .directoryToServe }/${project .filePathToServe }' ,
125
+ );
126
+ _logger.info ('Project: ${project .absolutePackageDirectory }' );
127
+ _logger.info ('Packages: ${project .packageConfigFile }' );
128
+ _logger.info ('Entry: ${project .dartEntryFilePath }' );
161
129
}
162
130
163
131
Future <void > setUp ({
@@ -187,7 +155,7 @@ class TestContext {
187
155
final configuration = await sdkConfigurationProvider.configuration;
188
156
configuration.validate ();
189
157
190
- DartUri .currentDirectory = workingDirectory ;
158
+ DartUri .currentDirectory = project.absolutePackageDirectory ;
191
159
configureLogWriter ();
192
160
193
161
_client = IOClient (
@@ -234,7 +202,7 @@ class TestContext {
234
202
await Process .run (
235
203
sdkLayout.dartPath,
236
204
['pub' , 'upgrade' ],
237
- workingDirectory: workingDirectory ,
205
+ workingDirectory: project.absolutePackageDirectory ,
238
206
);
239
207
240
208
ExpressionCompiler ? expressionCompiler;
@@ -257,7 +225,8 @@ class TestContext {
257
225
'--verbose' ,
258
226
];
259
227
_daemonClient = await connectClient (
260
- sdkLayout.dartPath, workingDirectory, options, (log) {
228
+ sdkLayout.dartPath, project.absolutePackageDirectory, options,
229
+ (log) {
261
230
final record = log.toLogRecord ();
262
231
final name =
263
232
record.loggerName == '' ? '' : '${record .loggerName }: ' ;
@@ -269,19 +238,22 @@ class TestContext {
269
238
);
270
239
});
271
240
daemonClient.registerBuildTarget (
272
- DefaultBuildTarget ((b) => b..target = directoryToServe),
241
+ DefaultBuildTarget ((b) => b..target = project. directoryToServe),
273
242
);
274
243
daemonClient.startBuild ();
275
244
276
245
await waitForSuccessfulBuild ();
277
246
278
- final assetServerPort = daemonPort (workingDirectory);
247
+ final assetServerPort =
248
+ daemonPort (project.absolutePackageDirectory);
279
249
_assetHandler = proxyHandler (
280
- 'http://localhost:$assetServerPort /$directoryToServe /' ,
250
+ 'http://localhost:$assetServerPort /${ project . directoryToServe } /' ,
281
251
client: client,
282
252
);
283
- assetReader =
284
- ProxyServerAssetReader (assetServerPort, root: directoryToServe);
253
+ assetReader = ProxyServerAssetReader (
254
+ assetServerPort,
255
+ root: project.directoryToServe,
256
+ );
285
257
286
258
if (enableExpressionEvaluation) {
287
259
ddcService = ExpressionCompilerService (
@@ -306,25 +278,25 @@ class TestContext {
306
278
break ;
307
279
case CompilationMode .frontendServer:
308
280
{
309
- _logger.warning ('Index: $filePathToServe ' );
281
+ _logger.warning ('Index: $project . filePathToServe' );
310
282
311
283
final entry = p.toUri (
312
284
p.join (project.webAssetsPath, project.dartEntryFileName),
313
285
);
314
286
final fileSystem = LocalFileSystem ();
315
287
final packageUriMapper = await PackageUriMapper .create (
316
288
fileSystem,
317
- _packageConfigFile ,
289
+ project.packageConfigFile ,
318
290
useDebuggerModuleNames: useDebuggerModuleNames,
319
291
);
320
292
321
293
_webRunner = ResidentWebRunner (
322
294
mainUri: entry,
323
295
urlTunneler: urlEncoder,
324
- projectDirectory: p.toUri (workingDirectory ),
325
- packageConfigFile: _packageConfigFile ,
296
+ projectDirectory: p.toUri (project.absolutePackageDirectory ),
297
+ packageConfigFile: project.packageConfigFile ,
326
298
packageUriMapper: packageUriMapper,
327
- fileSystemRoots: [p.toUri (workingDirectory )],
299
+ fileSystemRoots: [p.toUri (project.absolutePackageDirectory )],
328
300
fileSystemScheme: 'org-dartlang-app' ,
329
301
outputPath: outputDir.path,
330
302
soundNullSafety: nullSafety == NullSafety .sound,
@@ -338,7 +310,7 @@ class TestContext {
338
310
fileSystem,
339
311
hostname,
340
312
assetServerPort,
341
- p.join (directoryToServe, filePathToServe),
313
+ p.join (project. directoryToServe, project. filePathToServe),
342
314
);
343
315
344
316
if (enableExpressionEvaluation) {
@@ -402,7 +374,7 @@ class TestContext {
402
374
assetHandler,
403
375
assetReader,
404
376
requireStrategy,
405
- directoryToServe,
377
+ project. directoryToServe,
406
378
buildResults,
407
379
() async => connection,
408
380
serveDevTools,
@@ -420,8 +392,8 @@ class TestContext {
420
392
);
421
393
422
394
_appUrl = basePath.isEmpty
423
- ? 'http://localhost:$port /$filePathToServe '
424
- : 'http://localhost:$port /$basePath /$filePathToServe ' ;
395
+ ? 'http://localhost:$port /${ project . filePathToServe } '
396
+ : 'http://localhost:$port /$basePath /${ project . filePathToServe } ' ;
425
397
426
398
if (launchChrome) {
427
399
await _webDriver? .get (appUrl);
@@ -483,7 +455,7 @@ class TestContext {
483
455
required String toReplace,
484
456
required String replaceWith,
485
457
}) {
486
- final file = File (_dartEntryFilePath );
458
+ final file = File (project.dartEntryFilePath );
487
459
final fileContents = file.readAsStringSync ();
488
460
file.writeAsStringSync (fileContents.replaceAll (toReplace, replaceWith));
489
461
}
0 commit comments