db42b359c3
- Adds a parameter to DartDevelopmentServiceLauncher.start, as well as DartDevelopmentService.startDevelopmentService - Adds an `--app-name` command line argument to the DDS cli. - Passes this app name through when registering VmService URIs on DTD. Bug: https://github.com/flutter/flutter/issues/184251 Change-Id: Ica4487214a69a165fe891d4b8de12d72b052783c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491360 Auto-Submit: Jake Macdonald <jakemac@google.com> Commit-Queue: Jake Macdonald <jakemac@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
105 lines
3.3 KiB
Dart
105 lines
3.3 KiB
Dart
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:dds/dds_launcher.dart';
|
|
import 'package:dtd/dtd.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:vm_service/vm_service_io.dart';
|
|
|
|
import 'common/test_helper.dart';
|
|
|
|
void main() {
|
|
group('DDS', () {
|
|
late Process process;
|
|
late DartDevelopmentServiceLauncher dds;
|
|
|
|
setUp(() async {
|
|
process = await spawnDartProcess('smoke.dart');
|
|
});
|
|
|
|
tearDown(() async {
|
|
await dds.shutdown();
|
|
process.kill();
|
|
});
|
|
|
|
void createSmokeTest(bool useAuthCodes) {
|
|
test(
|
|
'Launcher Smoke Test with ${useAuthCodes ? "" : "no"} authentication codes',
|
|
() async {
|
|
dds = await DartDevelopmentServiceLauncher.start(
|
|
remoteVmServiceUri: remoteVmServiceUri,
|
|
enableAuthCodes: useAuthCodes,
|
|
);
|
|
|
|
// Ensure basic websocket requests are forwarded correctly to the VM service.
|
|
final service = await vmServiceConnectUri(dds.wsUri.toString());
|
|
final version = await service.getVersion();
|
|
expect(version.major! > 0, true);
|
|
expect(version.minor! >= 0, true);
|
|
|
|
expect(
|
|
dds.uri.pathSegments,
|
|
useAuthCodes ? isNotEmpty : isEmpty,
|
|
);
|
|
|
|
// Ensure we can still make requests of the VM service via HTTP.
|
|
HttpClient client = HttpClient();
|
|
final request = await client.getUrl(remoteVmServiceUri.replace(
|
|
pathSegments: [
|
|
if (remoteVmServiceUri.pathSegments.isNotEmpty)
|
|
remoteVmServiceUri.pathSegments.first,
|
|
'getVersion',
|
|
],
|
|
));
|
|
final response = await request.close();
|
|
final Map<String, dynamic> jsonResponse = (await response
|
|
.transform(utf8.decoder)
|
|
.transform(json.decoder)
|
|
.single) as Map<String, dynamic>;
|
|
expect(jsonResponse['result']['type'], 'Version');
|
|
expect(jsonResponse['result']['major'] > 0, true);
|
|
expect(jsonResponse['result']['minor'] >= 0, true);
|
|
},
|
|
);
|
|
}
|
|
|
|
test(
|
|
'External DevTools address and appName are reported correctly',
|
|
() async {
|
|
final fakeDevToolsUri =
|
|
Uri.parse('http://localhost:12345/my_devtools/');
|
|
dds = await DartDevelopmentServiceLauncher.start(
|
|
remoteVmServiceUri: remoteVmServiceUri,
|
|
serveDevTools: true,
|
|
devToolsServerAddress: fakeDevToolsUri,
|
|
appName: 'my-app',
|
|
);
|
|
|
|
expect(dds.devToolsUri,
|
|
fakeDevToolsUri.replace(query: 'uri=${dds.wsUri.toString()}'));
|
|
|
|
expect(dds.appName, 'my-app');
|
|
final dtdUri = dds.dtdUri;
|
|
expect(dtdUri, isNotNull);
|
|
|
|
final dtdClient = await DartToolingDaemon.connect(dtdUri!);
|
|
try {
|
|
final response = await dtdClient.getVmServices();
|
|
final vmServiceInfo = response.vmServicesInfos
|
|
.firstWhere((info) => info.name == 'my-app');
|
|
expect(vmServiceInfo.uri, dds.wsUri.toString());
|
|
} finally {
|
|
await dtdClient.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
createSmokeTest(true);
|
|
createSmokeTest(false);
|
|
});
|
|
}
|