diff --git a/pkg/dtd/test/example_test.dart b/pkg/dtd/test/example_test.dart index 431b1708654..4416654f47a 100644 --- a/pkg/dtd/test/example_test.dart +++ b/pkg/dtd/test/example_test.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'dart:isolate'; import 'package:dtd/dtd.dart'; import 'package:test/test.dart'; @@ -14,6 +15,16 @@ import 'utils.dart'; void main() { late ToolingDaemonTestProcess toolingDaemonProcess; + /// Gets the URI for [filename] in the example folder. + Uri getExampleFileUri(String filename) { + // Use resolvePackageUriSync and not Platform.script so that this works + // when run through 'dart test'. + return Isolate.resolvePackageUriSync( + Uri.parse('package:dtd/'), + )! + .resolve('../example/$filename'); + } + setUp(() async { toolingDaemonProcess = ToolingDaemonTestProcess(); await toolingDaemonProcess.start(); @@ -31,16 +42,14 @@ void main() { Platform.resolvedExecutable, [ 'run', - Platform.script - .resolve('../example/dtd_stream_example.dart') - .toString(), + getExampleFileUri('dtd_stream_example.dart').toString(), toolingDaemonProcess.uri.toString(), ], ); final lines = []; streamProcess.handle( stdoutLines: (line) { - stdout.write('streamProcess stdout: $line'); + print('streamProcess stdout: $line'); lines.add(line); final json = jsonDecode(line) as Map; if (json['step'] == 'Event A received') { @@ -67,9 +76,7 @@ void main() { Platform.resolvedExecutable, [ 'run', - Platform.script - .resolve('../example/dtd_service_example.dart') - .toString(), + getExampleFileUri('dtd_service_example.dart').toString(), toolingDaemonProcess.uri.toString(), ], ); @@ -77,7 +84,7 @@ void main() { final stdoutMessages = >[]; serviceExampleProcess.handle( stdoutLines: (line) { - stdout.write('serviceExample stdout: $line'); + print('serviceExample stdout: $line'); stdoutMessages.add(jsonDecode(line) as Map); }, stderrLines: (line) => stderr.write('serviceExample stderr: $line'), @@ -132,9 +139,7 @@ void main() { Platform.resolvedExecutable, [ 'run', - Platform.script - .resolve('../example/dtd_file_system_service_example.dart') - .toString(), + getExampleFileUri('dtd_file_system_service_example.dart').toString(), toolingDaemonProcess.uri.toString(), tmpDirectory.uri.toString(), ], @@ -142,7 +147,7 @@ void main() { final lines = []; fileSystemServiceExampleProcess.handle( stdoutLines: (line) { - stdout.write('fileSystemServiceProcess stdout: $line'); + print('fileSystemServiceProcess stdout: $line'); lines.add(line); final json = jsonDecode(line) as Map; if (json['step'] == 'read') { diff --git a/pkg/dtd/test/utils.dart b/pkg/dtd/test/utils.dart index 9cdaa71495f..67d844cf7d6 100644 --- a/pkg/dtd/test/utils.dart +++ b/pkg/dtd/test/utils.dart @@ -28,7 +28,7 @@ class ToolingDaemonTestProcess { ); process!.handle( stdoutLines: (line) { - stdout.write('DTD stdout: $line'); + print('DTD stdout: $line'); try { final json = jsonDecode(line) as Map; final toolingDaemonDetails =