Adds a new helper resolveTestRelativePath for resolving paths relative to the test dir, which works using the package config instead of Platform.script. This allows it to work via dart test as well as the test runner, or when manually invoked.
Replaced usages of Platform.script.resolve with this utility. Change-Id: I904d281934c3eb42516e891f27a8f3dbe714e7f6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432740 Auto-Submit: Jake Macdonald <jakemac@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
committed by
Commit Queue
parent
495a2bb694
commit
bf9acedc73
@@ -9,6 +9,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io' as io;
|
||||
import 'dart:isolate' as isolate;
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'package:vm_service/vm_service.dart';
|
||||
@@ -31,6 +32,11 @@ const Map<String, String> _TESTEE_SPAWN_ENV = {_TESTEE_ENV_KEY: 'true'};
|
||||
|
||||
late Uri remoteVmServiceUri;
|
||||
|
||||
/// Resolves a path as if it was relative to the `test` dir in this package.
|
||||
Uri resolveTestRelativePath(String relativePath) =>
|
||||
isolate.Isolate.resolvePackageUriSync(Uri.parse('package:dds/'))!
|
||||
.resolve('../test/$relativePath');
|
||||
|
||||
Future<io.Process> spawnDartProcess(
|
||||
String script, {
|
||||
bool serveObservatory = true,
|
||||
@@ -51,7 +57,7 @@ Future<io.Process> spawnDartProcess(
|
||||
if (disableServiceAuthCodes) '--disable-service-auth-codes',
|
||||
'--write-service-info=$serviceInfoUri',
|
||||
...io.Platform.executableArguments,
|
||||
io.Platform.script.resolve(script).toString(),
|
||||
resolveTestRelativePath(script).toFilePath(),
|
||||
];
|
||||
final process = await io.Process.start(executable, arguments);
|
||||
if (subscribeToStdio) {
|
||||
@@ -89,12 +95,8 @@ Future<void> executeUntilNextPause(VmService service) async {
|
||||
}
|
||||
|
||||
/// Returns the resolved URI to the pre-built devtools app.
|
||||
///
|
||||
/// The method caller is responsible for providing the relative [prefix] that
|
||||
/// will resolve to the sdk/ directory (e.g. '../../../').
|
||||
Uri devtoolsAppUri({required String prefix}) {
|
||||
const pathFromSdkDirectory = 'third_party/devtools/web';
|
||||
return io.Platform.script.resolve('$prefix$pathFromSdkDirectory');
|
||||
Uri devtoolsAppUri() {
|
||||
return resolveTestRelativePath('../../../third_party/devtools/web');
|
||||
}
|
||||
|
||||
bool _isTestee() {
|
||||
@@ -113,7 +115,7 @@ Uri _getTestUri(String script) {
|
||||
} else {
|
||||
// Resolve the script to ensure that test will fail if the provided script
|
||||
// name doesn't match the actual script.
|
||||
return io.Platform.script.resolve(script);
|
||||
return resolveTestRelativePath(script);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'common/test_helper.dart';
|
||||
|
||||
// Regression test for https://github.com/dart-lang/sdk/issues/56087
|
||||
|
||||
void main() {
|
||||
@@ -19,10 +21,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('Enabling the VM service with dart on PATH spawns DDS', () async {
|
||||
final script = path.join(
|
||||
path.dirname(Platform.script.toString()),
|
||||
final script = resolveTestRelativePath(
|
||||
'control_web_server_starts_dds_test.dart',
|
||||
);
|
||||
).toFilePath();
|
||||
process = await Process.start(
|
||||
'dart',
|
||||
[script],
|
||||
|
||||
@@ -41,7 +41,7 @@ void main() {
|
||||
remoteVmServiceUri,
|
||||
devToolsConfiguration: DevToolsConfiguration(
|
||||
enable: true,
|
||||
customBuildDirectoryPath: devtoolsAppUri(prefix: '../../../'),
|
||||
customBuildDirectoryPath: devtoolsAppUri(),
|
||||
),
|
||||
);
|
||||
expect(dds!.isRunning, true);
|
||||
|
||||
@@ -12,8 +12,7 @@ void main(List<String> args) async {
|
||||
unawaited(
|
||||
DevToolsServer().serveDevToolsWithArgs(
|
||||
args,
|
||||
customDevToolsPath:
|
||||
devtoolsAppUri(prefix: '../../../../../').toFilePath(),
|
||||
customDevToolsPath: devtoolsAppUri().toFilePath(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import 'package:dds/devtools_server.dart';
|
||||
import 'package:devtools_shared/devtools_test_utils.dart';
|
||||
import 'package:vm_service/vm_service.dart';
|
||||
|
||||
import '../../common/test_helper.dart';
|
||||
|
||||
const verbose = true;
|
||||
|
||||
class DevToolsServerDriver {
|
||||
@@ -76,9 +78,8 @@ class DevToolsServerDriver {
|
||||
int? tryPorts,
|
||||
List<String> additionalArgs = const [],
|
||||
}) async {
|
||||
final script = Platform.script.resolveUri(
|
||||
Uri.parse('utils/serve_devtools.dart'),
|
||||
);
|
||||
final script =
|
||||
resolveTestRelativePath('devtools_server/utils/serve_devtools.dart');
|
||||
final args = [
|
||||
script.toFilePath(),
|
||||
'--machine',
|
||||
@@ -217,9 +218,9 @@ class DevToolsServerTestController {
|
||||
|
||||
Future<void> startApp({bool runPubGet = false}) async {
|
||||
emptyDartAppRoot =
|
||||
Platform.script.resolveUri(Uri.parse('fixtures/empty_dart_app/'));
|
||||
packageWithExtensionsRoot = Platform.script
|
||||
.resolveUri(Uri.parse('fixtures/package_with_extensions/'));
|
||||
resolveTestRelativePath('devtools_server/fixtures/empty_dart_app/');
|
||||
packageWithExtensionsRoot = resolveTestRelativePath(
|
||||
'devtools_server/fixtures/package_with_extensions/');
|
||||
|
||||
if (runPubGet) {
|
||||
final pubResult = await Process.run(
|
||||
@@ -276,7 +277,7 @@ class DevToolsServerTestController {
|
||||
return requiredConnectionState ?? false
|
||||
// If we require a connected client, also require a non-null page.
|
||||
// This avoids a race in tests where we may proceed to send messages
|
||||
// to a client that is not fully initialised.
|
||||
// to a client that is not fully initialized.
|
||||
? (client['hasConnection'] && client['currentPage'] != null)
|
||||
: !client['hasConnection'];
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ void main() {
|
||||
);
|
||||
|
||||
devToolsServer = (await DevToolsServer().serveDevTools(
|
||||
customDevToolsPath: devtoolsAppUri(prefix: '../../../').toFilePath(),
|
||||
customDevToolsPath: devtoolsAppUri().toFilePath(),
|
||||
))!;
|
||||
});
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ void main() {
|
||||
if (Platform.isWindows) {
|
||||
chromedriverPath = '$chromedriverPath.exe';
|
||||
}
|
||||
final chromedriverUri =
|
||||
Platform.script.resolveUri(Uri.parse(chromedriverPath));
|
||||
final chromedriverUri = resolveTestRelativePath(chromedriverPath);
|
||||
try {
|
||||
chromeDriver = await Process.start(chromedriverUri.toFilePath(), [
|
||||
'--port=4444',
|
||||
@@ -58,7 +57,7 @@ void main() {
|
||||
final cascade = shelf.Cascade()
|
||||
.add(handler.handler)
|
||||
.add(_faviconHandler)
|
||||
.add(createStaticHandler(Platform.script.resolve('web').toFilePath(),
|
||||
.add(createStaticHandler(resolveTestRelativePath('web').toFilePath(),
|
||||
listDirectories: true, defaultDocument: 'index.html'));
|
||||
|
||||
server = await io.serve(cascade.handler, 'localhost', 0);
|
||||
|
||||
Reference in New Issue
Block a user