diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md index 04ef333c1..68519d4d3 100644 --- a/pkgs/test/CHANGELOG.md +++ b/pkgs/test/CHANGELOG.md @@ -4,6 +4,7 @@ * Increase SDK constraint to ^3.5.0-311.0.dev. * Support running Node.js tests compiled with dart2wasm. * Allow `firefox` or `firefox-bin` executable name on macOS. +* Use a DevTools URL instead of a defunct observatory URL. ## 1.25.8 diff --git a/pkgs/test_core/CHANGELOG.md b/pkgs/test_core/CHANGELOG.md index 610311022..34af12c9d 100644 --- a/pkgs/test_core/CHANGELOG.md +++ b/pkgs/test_core/CHANGELOG.md @@ -3,6 +3,7 @@ * Fix dart2wasm tests on windows. * Increase SDK constraint to ^3.5.0-311.0.dev. * Allow passing additional arguments to `dart compile wasm`. +* Use a DevTools URL instead of a defunct observatory URL. ## 0.6.5 diff --git a/pkgs/test_core/lib/src/runner/environment.dart b/pkgs/test_core/lib/src/runner/environment.dart index 7fcba66eb..67e64de1f 100644 --- a/pkgs/test_core/lib/src/runner/environment.dart +++ b/pkgs/test_core/lib/src/runner/environment.dart @@ -12,8 +12,9 @@ abstract class Environment { /// Whether this environment supports interactive debugging. bool get supportsDebugging; - /// The URL of the Dart VM Observatory for this environment, or `null` if this - /// environment doesn't run the Dart VM or the URL couldn't be detected. + /// The URL of the Dart Dev Tools server for this environment, or `null` if + /// this environment doesn't run the Dart VM or the URL couldn't be detected. + // TODO(https://github.com/dart-lang/test/issues/2185) rename to `devToolsUrl` Uri? get observatoryUrl; /// The URL of the remote debugger for this environment, or `null` if it isn't diff --git a/pkgs/test_core/lib/src/runner/vm/platform.dart b/pkgs/test_core/lib/src/runner/vm/platform.dart index 506909db7..23e2565a6 100644 --- a/pkgs/test_core/lib/src/runner/vm/platform.dart +++ b/pkgs/test_core/lib/src/runner/vm/platform.dart @@ -107,6 +107,8 @@ class VMPlatform extends PlatformPlugin { Environment? environment; IsolateRef? isolateRef; + String? isolateID; + Uri? serverUri; if (_config.debug) { if (platform.compiler == Compiler.exe) { throw UnsupportedError( @@ -115,21 +117,17 @@ class VMPlatform extends PlatformPlugin { } var info = await Service.controlWebServer(enable: true, silenceOutput: true); - // ignore: deprecated_member_use, Remove when SDK constraint is at 3.2.0 - var isolateID = Service.getIsolateID(isolate!)!; + serverUri = info.serverUri!; + isolateID = Service.getIsolateId(isolate!)!; - var libraryPath = (await absoluteUri(path)).toString(); - var serverUri = info.serverUri!; - client = await vmServiceConnectUri(_wsUriFor(serverUri).toString()); + var serviceWebsocket = _wsUriFor(serverUri); + client = await vmServiceConnectUri(serviceWebsocket.toString()); var isolateNumber = int.parse(isolateID.split('/').last); isolateRef = (await client.getVM()) .isolates! .firstWhere((isolate) => isolate.number == isolateNumber.toString()); await client.setName(isolateRef.id!, path); - var libraryRef = (await client.getIsolate(isolateRef.id!)) - .libraries! - .firstWhere((library) => library.uri == libraryPath); - var url = _observatoryUrlFor(serverUri, isolateRef.id!, libraryRef.id!); + var url = _devtoolsUriFor(serviceWebsocket); environment = VMEnvironment(url, isolateRef, client); } @@ -137,7 +135,7 @@ class VMPlatform extends PlatformPlugin { var controller = deserializeSuite( path, platform, suiteConfig, environment, channel.cast(), message, - gatherCoverage: () => _gatherCoverage(environment!)); + gatherCoverage: () => _gatherCoverage(serverUri!, isolateID!)); if (isolateRef != null) { await client!.streamListen('Debug'); @@ -331,20 +329,23 @@ stderr: ${processResult.stderr}'''); } } -Future> _gatherCoverage(Environment environment) async { - final isolateId = Uri.parse(environment.observatoryUrl!.fragment) - .queryParameters['isolateId']; - return await collect(environment.observatoryUrl!, false, false, false, {}, - isolateIds: {isolateId!}); +Future> _gatherCoverage( + Uri serviceUri, String isolateId) async { + return await collect(serviceUri, false, false, false, {}, + isolateIds: {isolateId}); } Uri _wsUriFor(Uri observatoryUrl) => observatoryUrl.replace(scheme: 'ws').resolve('ws'); -Uri _observatoryUrlFor(Uri base, String isolateId, String id) => base.replace( - fragment: Uri( - path: '/inspect', - queryParameters: {'isolateId': isolateId, 'objectId': id}).toString()); +Uri _devtoolsUriFor(Uri serviceUri) { + assert(serviceUri.isScheme('ws')); + return serviceUri.resolve('devtools/debugger').replace( + scheme: 'http', + queryParameters: {'uri': '$serviceUri'}, + fragment: '', + ); +} var _hasRegistered = false; void _setupPauseAfterTests() {