Skip to content

Commit cbb0d76

Browse files
author
Anna Gringauze
authored
Run instance tests with frontend server (#2160)
* Run instance tests with frontend server * Cleanup * Try fixing tests * Addressed CR comments and fixed failing tests * update pubspec and build * Require AssetReader to provide a base path * Fix test failures on windows * Merge with master
1 parent b672e98 commit cbb0d76

17 files changed

+410
-334
lines changed

dwds/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## 19.0.3-wip
1+
## 20.0.0-wip
2+
3+
- Require clients to specify the `basePath` on `AssetReader`. - [#2160](https://github.com/dart-lang/webdev/pull/2160)
24

35
## 19.0.2
46

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import 'package:dwds/src/dwds_vm_client.dart';
2323
import 'package:dwds/src/events.dart';
2424
import 'package:dwds/src/handlers/injector.dart';
2525
import 'package:dwds/src/handlers/socket_connections.dart';
26-
import 'package:dwds/src/loaders/require.dart';
2726
import 'package:dwds/src/readers/asset_reader.dart';
2827
import 'package:dwds/src/servers/devtools.dart';
2928
import 'package:dwds/src/servers/extension_backend.dart';
@@ -196,7 +195,6 @@ class DevHandler {
196195
'localhost',
197196
webkitDebugger,
198197
executionContext,
199-
basePathForServerUri(appTab.url),
200198
_assetReader,
201199
appConnection,
202200
_urlEncoder,
@@ -587,7 +585,6 @@ class DevHandler {
587585
_hostname,
588586
extensionDebugger,
589587
executionContext,
590-
basePathForServerUri(tabUrl),
591588
_assetReader,
592589
connection,
593590
_urlEncoder,

dwds/lib/src/loaders/frontend_server_require.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ class FrontendServerRequireStrategyProvider {
3636
this._assetReader,
3737
this._packageUriMapper,
3838
this._digestsProvider,
39-
this._basePath,
4039
this._appEntrypoint,
41-
);
40+
) : _basePath = _assetReader.basePath;
4241

4342
RequireStrategy get strategy => _requireStrategy;
4443

dwds/lib/src/loaders/require.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ import 'package:dwds/src/services/expression_compiler.dart';
1111
import 'package:path/path.dart' as p;
1212
import 'package:shelf/shelf.dart';
1313

14-
/// Find the path we are serving from the url.
15-
///
16-
/// Example:
17-
/// https://localhost/base/index.html => base
18-
/// https://localhost/base => base
19-
String basePathForServerUri(String url) {
20-
final uri = Uri.parse(url);
21-
var base = uri.path.endsWith('.html') ? p.dirname(uri.path) : uri.path;
22-
return base = base.startsWith('/') ? base.substring(1) : base;
23-
}
24-
2514
String removeJsExtension(String path) =>
2615
path.endsWith('.js') ? p.withoutExtension(path) : path;
2716

dwds/lib/src/readers/asset_reader.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ typedef UrlEncoder = Future<String> Function(String url);
1111

1212
/// A reader for Dart sources and related source maps.
1313
abstract class AssetReader {
14+
/// Base path of the application, for example, set up in the index file:
15+
///
16+
/// ```
17+
/// <html>
18+
/// <head>
19+
/// <base href="/abc/">
20+
/// <script src="main.dart.js"></script>
21+
/// </head>
22+
/// </html>
23+
/// ```
24+
String get basePath;
25+
1426
/// Returns the contents for a source map at the provided server path, or
1527
/// null if the resource does not exist.
1628
Future<String?> sourceMapContents(String serverPath);

dwds/lib/src/readers/frontend_server_asset_reader.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class FrontendServerAssetReader implements AssetReader {
2020
final File _jsonIncremental;
2121
final String _packageRoot;
2222
final Future<PackageConfig> _packageConfig;
23+
final String _basePath;
2324

2425
/// Map of Dart module server path to source map contents.
2526
final _mapContents = <String, String>{};
@@ -37,19 +38,25 @@ class FrontendServerAssetReader implements AssetReader {
3738
///
3839
/// [_packageRoot] is the path to the directory that contains a
3940
/// `.dart_tool/package_config.json` file for the application.
40-
FrontendServerAssetReader(
41-
String outputPath,
42-
this._packageRoot,
43-
) : _mapOriginal = File('$outputPath.map'),
41+
FrontendServerAssetReader({
42+
required String outputPath,
43+
required String packageRoot,
44+
String? basePath,
45+
}) : _packageRoot = packageRoot,
46+
_basePath = basePath ?? '',
47+
_mapOriginal = File('$outputPath.map'),
4448
_mapIncremental = File('$outputPath.incremental.map'),
4549
_jsonOriginal = File('$outputPath.json'),
4650
_jsonIncremental = File('$outputPath.incremental.json'),
4751
_packageConfig = loadPackageConfig(
4852
File(
49-
p.absolute(p.join(_packageRoot, '.dart_tool/package_config.json')),
53+
p.absolute(p.join(packageRoot, '.dart_tool/package_config.json')),
5054
),
5155
);
5256

57+
@override
58+
String get basePath => _basePath;
59+
5360
@override
5461
Future<String?> dartSourceContents(String serverPath) async {
5562
if (serverPath.endsWith('.dart')) {

dwds/lib/src/readers/proxy_server_asset_reader.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class ProxyServerAssetReader implements AssetReader {
3838
_handler = proxyHandler(url, client: _client);
3939
}
4040

41+
@override
42+
String get basePath => '';
43+
4144
@override
4245
Future<String?> dartSourceContents(String serverPath) =>
4346
_readResource(serverPath);

dwds/lib/src/services/debug_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ class DebugService {
220220
String hostname,
221221
RemoteDebugger remoteDebugger,
222222
ExecutionContext executionContext,
223-
String root,
224223
AssetReader assetReader,
225224
AppConnection appConnection,
226225
UrlEncoder? urlEncoder, {
@@ -230,6 +229,7 @@ class DebugService {
230229
bool useSse = false,
231230
ExpressionCompiler? expressionCompiler,
232231
}) async {
232+
final root = assetReader.basePath;
233233
final chromeProxyService = await ChromeProxyService.create(
234234
remoteDebugger,
235235
root,

dwds/lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dwds
22
# Every time this changes you need to run `dart run build_runner build`.
3-
version: 19.0.3-wip
3+
version: 20.0.0-wip
44
description: >-
55
A service that proxies between the Chrome debug protocol and the Dart VM
66
service protocol.

dwds/test/evaluate_common.dart

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,15 @@ void testAll({
155155
scope: scope,
156156
);
157157

158-
getInstanceRef(frame, expr, {scope}) async => await evaluateInFrame(
159-
frame,
160-
expr,
161-
scope: scope,
162-
) as InstanceRef;
158+
getInstanceRef(frame, expr, {scope}) async {
159+
final result = await evaluateInFrame(
160+
frame,
161+
expr,
162+
scope: scope,
163+
);
164+
expect(result, isA<InstanceRef>());
165+
return result as InstanceRef;
166+
}
163167

164168
getInstance(InstanceRef ref) async =>
165169
await context.service.getObject(isolateId, ref.id!) as Instance;
@@ -675,12 +679,15 @@ void testAll({
675679
libraryId,
676680
expr, {
677681
scope,
678-
}) async =>
679-
await evaluate(
680-
libraryId,
681-
expr,
682-
scope: scope,
683-
) as InstanceRef;
682+
}) async {
683+
final result = await evaluate(
684+
libraryId,
685+
expr,
686+
scope: scope,
687+
);
688+
expect(result, isA<InstanceRef>());
689+
return result as InstanceRef;
690+
}
684691

685692
String getRootLibraryId() {
686693
expect(isolate.rootLib, isNotNull);

dwds/test/fixtures/context.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class TestContext {
211211
Stream<BuildResults> buildResults;
212212
RequireStrategy requireStrategy;
213213
String basePath = '';
214+
String filePathToServe = project.filePathToServe;
214215

215216
_port = await findUnusedPort();
216217
switch (compilationMode) {
@@ -279,7 +280,12 @@ class TestContext {
279280
break;
280281
case CompilationMode.frontendServer:
281282
{
282-
_logger.info('Index: ${project.filePathToServe}');
283+
filePathToServe = webCompatiblePath([
284+
project.directoryToServe,
285+
project.filePathToServe,
286+
]);
287+
288+
_logger.info('Serving: $filePathToServe');
283289

284290
final entry = p.toUri(
285291
p.join(project.webAssetsPath, project.dartEntryFileName),
@@ -311,7 +317,7 @@ class TestContext {
311317
fileSystem,
312318
hostname,
313319
assetServerPort,
314-
p.join(project.directoryToServe, project.filePathToServe),
320+
filePathToServe,
315321
);
316322

317323
if (enableExpressionEvaluation) {
@@ -326,7 +332,6 @@ class TestContext {
326332
assetReader,
327333
packageUriMapper,
328334
() async => {},
329-
basePath,
330335
project.dartEntryFilePackageUri,
331336
).strategy;
332337

@@ -393,8 +398,8 @@ class TestContext {
393398
);
394399

395400
_appUrl = basePath.isEmpty
396-
? 'http://localhost:$port/${project.filePathToServe}'
397-
: 'http://localhost:$port/$basePath/${project.filePathToServe}';
401+
? 'http://localhost:$port/$filePathToServe'
402+
: 'http://localhost:$port/$basePath/$filePathToServe';
398403

399404
if (launchChrome) {
400405
await _webDriver?.get(appUrl);

dwds/test/fixtures/fakes.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ class FakeAssetReader implements AssetReader {
393393
_dartSource = dartSource,
394394
_sourceMap = sourceMap;
395395

396+
@override
397+
String get basePath => '';
398+
396399
@override
397400
Future<String> dartSourceContents(String serverPath) {
398401
return _throwUnimplementedOrReturnContents(_dartSource);

0 commit comments

Comments
 (0)