Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run instance tests with frontend server #2160

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## 19.0.2-wip
## 20.0.0-wip

- Allow clients to specify the `basePath` on `AssetReader`. - [#2160](https://github.com/dart-lang/webdev/pull/2160)

## 19.0.1

Expand Down
3 changes: 0 additions & 3 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:dwds/src/dwds_vm_client.dart';
import 'package:dwds/src/events.dart';
import 'package:dwds/src/handlers/injector.dart';
import 'package:dwds/src/handlers/socket_connections.dart';
import 'package:dwds/src/loaders/require.dart';
import 'package:dwds/src/readers/asset_reader.dart';
import 'package:dwds/src/servers/devtools.dart';
import 'package:dwds/src/servers/extension_backend.dart';
Expand Down Expand Up @@ -196,7 +195,6 @@ class DevHandler {
'localhost',
webkitDebugger,
executionContext,
basePathForServerUri(appTab.url),
annagrin marked this conversation as resolved.
Show resolved Hide resolved
_assetReader,
appConnection,
_urlEncoder,
Expand Down Expand Up @@ -587,7 +585,6 @@ class DevHandler {
_hostname,
extensionDebugger,
executionContext,
basePathForServerUri(tabUrl),
_assetReader,
connection,
_urlEncoder,
Expand Down
3 changes: 1 addition & 2 deletions dwds/lib/src/loaders/frontend_server_require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ class FrontendServerRequireStrategyProvider {
this._assetReader,
this._packageUriMapper,
this._digestsProvider,
this._basePath,
this._appEntrypoint,
);
) : _basePath = _assetReader.basePath;

RequireStrategy get strategy => _requireStrategy;

Expand Down
11 changes: 0 additions & 11 deletions dwds/lib/src/loaders/require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ import 'package:dwds/src/services/expression_compiler.dart';
import 'package:path/path.dart' as p;
import 'package:shelf/shelf.dart';

/// Find the path we are serving from the url.
///
/// Example:
/// https://localhost/base/index.html => base
/// https://localhost/base => base
String basePathForServerUri(String url) {
final uri = Uri.parse(url);
var base = uri.path.endsWith('.html') ? p.dirname(uri.path) : uri.path;
return base = base.startsWith('/') ? base.substring(1) : base;
}

String removeJsExtension(String path) =>
path.endsWith('.js') ? p.withoutExtension(path) : path;

Expand Down
12 changes: 12 additions & 0 deletions dwds/lib/src/readers/asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ typedef UrlEncoder = Future<String> Function(String url);

/// A reader for Dart sources and related source maps.
abstract class AssetReader {
/// Base path of the application, for example, set up in the index file:
///
/// ```
/// <html>
/// <head>
/// <base href="/abc/">
/// <script src="main.dart.js"></script>
/// </head>
/// </html>
/// ```
String get basePath;

/// Returns the contents for a source map at the provided server path, or
/// null if the resource does not exist.
Future<String?> sourceMapContents(String serverPath);
Expand Down
17 changes: 12 additions & 5 deletions dwds/lib/src/readers/frontend_server_asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FrontendServerAssetReader implements AssetReader {
final File _jsonIncremental;
final String _packageRoot;
final Future<PackageConfig> _packageConfig;
final String _basePath;

/// Map of Dart module server path to source map contents.
final _mapContents = <String, String>{};
Expand All @@ -37,19 +38,25 @@ class FrontendServerAssetReader implements AssetReader {
///
/// [_packageRoot] is the path to the directory that contains a
/// `.dart_tool/package_config.json` file for the application.
FrontendServerAssetReader(
String outputPath,
this._packageRoot,
) : _mapOriginal = File('$outputPath.map'),
FrontendServerAssetReader({
required String outputPath,
required String packageRoot,
String? basePath,
}) : _packageRoot = packageRoot,
_basePath = basePath ?? '',
_mapOriginal = File('$outputPath.map'),
_mapIncremental = File('$outputPath.incremental.map'),
_jsonOriginal = File('$outputPath.json'),
_jsonIncremental = File('$outputPath.incremental.json'),
_packageConfig = loadPackageConfig(
File(
p.absolute(p.join(_packageRoot, '.dart_tool/package_config.json')),
p.absolute(p.join(packageRoot, '.dart_tool/package_config.json')),
),
);

@override
String get basePath => _basePath;

@override
Future<String?> dartSourceContents(String serverPath) async {
if (serverPath.endsWith('.dart')) {
Expand Down
3 changes: 3 additions & 0 deletions dwds/lib/src/readers/proxy_server_asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ProxyServerAssetReader implements AssetReader {
_handler = proxyHandler(url, client: _client);
}

@override
String get basePath => '';

@override
Future<String?> dartSourceContents(String serverPath) =>
_readResource(serverPath);
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/services/debug_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ class DebugService {
String hostname,
RemoteDebugger remoteDebugger,
ExecutionContext executionContext,
String root,
AssetReader assetReader,
AppConnection appConnection,
UrlEncoder? urlEncoder, {
Expand All @@ -230,6 +229,7 @@ class DebugService {
bool useSse = false,
ExpressionCompiler? expressionCompiler,
}) async {
final root = assetReader.basePath;
final chromeProxyService = await ChromeProxyService.create(
remoteDebugger,
root,
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dwds/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dwds
# Every time this changes you need to run `dart run build_runner build`.
version: 19.0.2-wip
version: 20.0.0-wip
description: >-
A service that proxies between the Chrome debug protocol and the Dart VM
service protocol.
Expand Down
29 changes: 18 additions & 11 deletions dwds/test/evaluate_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,15 @@ void testAll({
scope: scope,
);

getInstanceRef(frame, expr, {scope}) async => await evaluateInFrame(
frame,
expr,
scope: scope,
) as InstanceRef;
getInstanceRef(frame, expr, {scope}) async {
final result = await evaluateInFrame(
frame,
expr,
scope: scope,
);
expect(result, isA<InstanceRef>());
return result as InstanceRef;
}

getInstance(InstanceRef ref) async =>
await context.service.getObject(isolateId, ref.id!) as Instance;
Expand Down Expand Up @@ -675,12 +679,15 @@ void testAll({
libraryId,
expr, {
scope,
}) async =>
await evaluate(
libraryId,
expr,
scope: scope,
) as InstanceRef;
}) async {
final result = await evaluate(
libraryId,
expr,
scope: scope,
);
expect(result, isA<InstanceRef>());
return result as InstanceRef;
}

String getRootLibraryId() {
expect(isolate.rootLib, isNotNull);
Expand Down
15 changes: 10 additions & 5 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class TestContext {
Stream<BuildResults> buildResults;
RequireStrategy requireStrategy;
String basePath = '';
String filePathToServe = project.filePathToServe;

_port = await findUnusedPort();
switch (compilationMode) {
Expand Down Expand Up @@ -279,7 +280,12 @@ class TestContext {
break;
case CompilationMode.frontendServer:
{
_logger.info('Index: ${project.filePathToServe}');
filePathToServe = webCompatiblePath([
project.directoryToServe,
project.filePathToServe,
]);

_logger.info('Serving: $filePathToServe');

final entry = p.toUri(
p.join(project.webAssetsPath, project.dartEntryFileName),
Expand Down Expand Up @@ -311,7 +317,7 @@ class TestContext {
fileSystem,
hostname,
assetServerPort,
p.join(project.directoryToServe, project.filePathToServe),
filePathToServe,
);

if (enableExpressionEvaluation) {
Expand All @@ -326,7 +332,6 @@ class TestContext {
assetReader,
packageUriMapper,
() async => {},
basePath,
project.dartEntryFilePackageUri,
).strategy;

Expand Down Expand Up @@ -393,8 +398,8 @@ class TestContext {
);

_appUrl = basePath.isEmpty
? 'http://localhost:$port/${project.filePathToServe}'
: 'http://localhost:$port/$basePath/${project.filePathToServe}';
? 'http://localhost:$port/$filePathToServe'
: 'http://localhost:$port/$basePath/$filePathToServe';

if (launchChrome) {
await _webDriver?.get(appUrl);
Expand Down
3 changes: 3 additions & 0 deletions dwds/test/fixtures/fakes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ class FakeAssetReader implements AssetReader {
_dartSource = dartSource,
_sourceMap = sourceMap;

@override
String get basePath => '';

@override
Future<String> dartSourceContents(String serverPath) {
return _throwUnimplementedOrReturnContents(_dartSource);
Expand Down
Loading
Loading