diff --git a/packages/shorebird_cli/lib/src/executables/open.dart b/packages/shorebird_cli/lib/src/executables/open.dart index 1f6eae8b..4e8c82f8 100644 --- a/packages/shorebird_cli/lib/src/executables/open.dart +++ b/packages/shorebird_cli/lib/src/executables/open.dart @@ -17,23 +17,22 @@ class Open { /// Opens a new application at the provided [path] and streams the stdout and /// stderr. Future>> newApplication({required String path}) async { - final tmp = Directory.systemTemp.createTempSync(); - final stdout = File(p.join(tmp.path, 'stdout.log'))..createSync(); - await process.start( - 'open', + final app = Directory(p.join(path, 'Contents', 'MacOS')) + .listSync() + .firstWhere((f) => f is File); + + await process.start('open', ['-n', path]); + + final logStreamProcess = await process.start( + 'log', [ - '-n', - path, - '--stdout=${stdout.path}', - '--stderr=${stdout.path}', + 'stream', + '--style=compact', + '--process', + p.basenameWithoutExtension(app.path), ], ); - final stdoutProcess = await process.start( - 'tail', - ['-fn+1', stdout.path], - ); - - return stdoutProcess.stdout; + return logStreamProcess.stdout; } } diff --git a/packages/shorebird_cli/test/src/executables/open_test.dart b/packages/shorebird_cli/test/src/executables/open_test.dart index 122314dc..c4e2ee2e 100644 --- a/packages/shorebird_cli/test/src/executables/open_test.dart +++ b/packages/shorebird_cli/test/src/executables/open_test.dart @@ -1,6 +1,8 @@ import 'dart:convert'; +import 'dart:io'; import 'package:mocktail/mocktail.dart'; +import 'package:path/path.dart' as p; import 'package:scoped_deps/scoped_deps.dart'; import 'package:shorebird_cli/src/executables/executables.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; @@ -28,26 +30,41 @@ void main() { }); group('newApplication', () { + late Directory workingDirectory; + + setUp(() { + workingDirectory = Directory.systemTemp.createTempSync(); + File(p.join(workingDirectory.path, 'Contents', 'MacOS', 'test')) + .createSync(recursive: true); + }); + test('executes correct command and streams logs', () async { final openProcess = MockProcess(); - final tailProcess = MockProcess(); + final logProcess = MockProcess(); when(() => process.start('open', any())).thenAnswer((_) async { return openProcess; }); - when(() => process.start('tail', any())).thenAnswer((_) async { - return tailProcess; + when(() => process.start('log', any())).thenAnswer((_) async { + return logProcess; }); - when(() => tailProcess.stdout).thenAnswer( + when(() => logProcess.stdout).thenAnswer( (_) => Stream.fromIterable([utf8.encode('hello world') as List]), ); final stream = await runWithOverrides( - () => open.newApplication(path: 'test'), + () => open.newApplication(path: workingDirectory.path), ); expect(stream, emits(utf8.encode('hello world'))); + verify(() => process.start('open', ['-n', workingDirectory.path])); + verify( + () => process.start( + 'log', + ['stream', '--style=compact', '--process', 'test'], + ), + ).called(1); }); }); });