Skip to content

Commit bf9aced

Browse files
jakemac53Commit Queue
authored andcommitted
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 <[email protected]> Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 495a2bb commit bf9aced

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

pkg/dds/test/common/test_helper.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import 'dart:async';
1010
import 'dart:convert';
1111
import 'dart:io' as io;
12+
import 'dart:isolate' as isolate;
1213

1314
import 'package:test/test.dart';
1415
import 'package:vm_service/vm_service.dart';
@@ -31,6 +32,11 @@ const Map<String, String> _TESTEE_SPAWN_ENV = {_TESTEE_ENV_KEY: 'true'};
3132

3233
late Uri remoteVmServiceUri;
3334

35+
/// Resolves a path as if it was relative to the `test` dir in this package.
36+
Uri resolveTestRelativePath(String relativePath) =>
37+
isolate.Isolate.resolvePackageUriSync(Uri.parse('package:dds/'))!
38+
.resolve('../test/$relativePath');
39+
3440
Future<io.Process> spawnDartProcess(
3541
String script, {
3642
bool serveObservatory = true,
@@ -51,7 +57,7 @@ Future<io.Process> spawnDartProcess(
5157
if (disableServiceAuthCodes) '--disable-service-auth-codes',
5258
'--write-service-info=$serviceInfoUri',
5359
...io.Platform.executableArguments,
54-
io.Platform.script.resolve(script).toString(),
60+
resolveTestRelativePath(script).toFilePath(),
5561
];
5662
final process = await io.Process.start(executable, arguments);
5763
if (subscribeToStdio) {
@@ -89,12 +95,8 @@ Future<void> executeUntilNextPause(VmService service) async {
8995
}
9096

9197
/// Returns the resolved URI to the pre-built devtools app.
92-
///
93-
/// The method caller is responsible for providing the relative [prefix] that
94-
/// will resolve to the sdk/ directory (e.g. '../../../').
95-
Uri devtoolsAppUri({required String prefix}) {
96-
const pathFromSdkDirectory = 'third_party/devtools/web';
97-
return io.Platform.script.resolve('$prefix$pathFromSdkDirectory');
98+
Uri devtoolsAppUri() {
99+
return resolveTestRelativePath('../../../third_party/devtools/web');
98100
}
99101

100102
bool _isTestee() {
@@ -113,7 +115,7 @@ Uri _getTestUri(String script) {
113115
} else {
114116
// Resolve the script to ensure that test will fail if the provided script
115117
// name doesn't match the actual script.
116-
return io.Platform.script.resolve(script);
118+
return resolveTestRelativePath(script);
117119
}
118120
}
119121

pkg/dds/test/control_web_server_starts_dds_with_dart_on_path_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import 'dart:io';
99
import 'package:path/path.dart' as path;
1010
import 'package:test/test.dart';
1111

12+
import 'common/test_helper.dart';
13+
1214
// Regression test for https://github.com/dart-lang/sdk/issues/56087
1315

1416
void main() {
@@ -19,10 +21,9 @@ void main() {
1921
});
2022

2123
test('Enabling the VM service with dart on PATH spawns DDS', () async {
22-
final script = path.join(
23-
path.dirname(Platform.script.toString()),
24+
final script = resolveTestRelativePath(
2425
'control_web_server_starts_dds_test.dart',
25-
);
26+
).toFilePath();
2627
process = await Process.start(
2728
'dart',
2829
[script],

pkg/dds/test/devtools_observatory_connection_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void main() {
4141
remoteVmServiceUri,
4242
devToolsConfiguration: DevToolsConfiguration(
4343
enable: true,
44-
customBuildDirectoryPath: devtoolsAppUri(prefix: '../../../'),
44+
customBuildDirectoryPath: devtoolsAppUri(),
4545
),
4646
);
4747
expect(dds!.isRunning, true);

pkg/dds/test/devtools_server/utils/serve_devtools.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ void main(List<String> args) async {
1212
unawaited(
1313
DevToolsServer().serveDevToolsWithArgs(
1414
args,
15-
customDevToolsPath:
16-
devtoolsAppUri(prefix: '../../../../../').toFilePath(),
15+
customDevToolsPath: devtoolsAppUri().toFilePath(),
1716
),
1817
);
1918
}

pkg/dds/test/devtools_server/utils/server_driver.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'package:dds/devtools_server.dart';
1010
import 'package:devtools_shared/devtools_test_utils.dart';
1111
import 'package:vm_service/vm_service.dart';
1212

13+
import '../../common/test_helper.dart';
14+
1315
const verbose = true;
1416

1517
class DevToolsServerDriver {
@@ -76,9 +78,8 @@ class DevToolsServerDriver {
7678
int? tryPorts,
7779
List<String> additionalArgs = const [],
7880
}) async {
79-
final script = Platform.script.resolveUri(
80-
Uri.parse('utils/serve_devtools.dart'),
81-
);
81+
final script =
82+
resolveTestRelativePath('devtools_server/utils/serve_devtools.dart');
8283
final args = [
8384
script.toFilePath(),
8485
'--machine',
@@ -217,9 +218,9 @@ class DevToolsServerTestController {
217218

218219
Future<void> startApp({bool runPubGet = false}) async {
219220
emptyDartAppRoot =
220-
Platform.script.resolveUri(Uri.parse('fixtures/empty_dart_app/'));
221-
packageWithExtensionsRoot = Platform.script
222-
.resolveUri(Uri.parse('fixtures/package_with_extensions/'));
221+
resolveTestRelativePath('devtools_server/fixtures/empty_dart_app/');
222+
packageWithExtensionsRoot = resolveTestRelativePath(
223+
'devtools_server/fixtures/package_with_extensions/');
223224

224225
if (runPubGet) {
225226
final pubResult = await Process.run(
@@ -276,7 +277,7 @@ class DevToolsServerTestController {
276277
return requiredConnectionState ?? false
277278
// If we require a connected client, also require a non-null page.
278279
// This avoids a race in tests where we may proceed to send messages
279-
// to a client that is not fully initialised.
280+
// to a client that is not fully initialized.
280281
? (client['hasConnection'] && client['currentPage'] != null)
281282
: !client['hasConnection'];
282283
}

pkg/dds/test/external_devtools_instance_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void main() {
2828
);
2929

3030
devToolsServer = (await DevToolsServer().serveDevTools(
31-
customDevToolsPath: devtoolsAppUri(prefix: '../../../').toFilePath(),
31+
customDevToolsPath: devtoolsAppUri().toFilePath(),
3232
))!;
3333
});
3434

pkg/dds/test/sse_smoke_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ void main() {
3333
if (Platform.isWindows) {
3434
chromedriverPath = '$chromedriverPath.exe';
3535
}
36-
final chromedriverUri =
37-
Platform.script.resolveUri(Uri.parse(chromedriverPath));
36+
final chromedriverUri = resolveTestRelativePath(chromedriverPath);
3837
try {
3938
chromeDriver = await Process.start(chromedriverUri.toFilePath(), [
4039
'--port=4444',
@@ -58,7 +57,7 @@ void main() {
5857
final cascade = shelf.Cascade()
5958
.add(handler.handler)
6059
.add(_faviconHandler)
61-
.add(createStaticHandler(Platform.script.resolve('web').toFilePath(),
60+
.add(createStaticHandler(resolveTestRelativePath('web').toFilePath(),
6261
listDirectories: true, defaultDocument: 'index.html'));
6362

6463
server = await io.serve(cascade.handler, 'localhost', 0);

0 commit comments

Comments
 (0)