diff --git a/packages/patrol/CHANGELOG.md b/packages/patrol/CHANGELOG.md index fc389fce1..41a1c067e 100644 --- a/packages/patrol/CHANGELOG.md +++ b/packages/patrol/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +- Fix test bundling not working on physical iOS devices (works only with `patrol +test --release`) (#1303) + ## 2.0.0-dev.1 - Backport changes from `master` (#1293) diff --git a/packages/patrol/ios/Classes/PatrolIntegrationTestRunner.h b/packages/patrol/ios/Classes/PatrolIntegrationTestRunner.h index a3f23ab64..b5a123da6 100644 --- a/packages/patrol/ios/Classes/PatrolIntegrationTestRunner.h +++ b/packages/patrol/ios/Classes/PatrolIntegrationTestRunner.h @@ -1,6 +1,3 @@ -@import Foundation; -@import ObjectiveC.runtime; - // This file is a one giant macro to make the setup as easy as possible for the developer. // To edit it: // 1. Remove the trailing backslashes: $ sed 's/\\$//' ios/Classes/PatrolIntegrationTestRunner.h diff --git a/packages/patrol_cli/lib/src/commands/doctor.dart b/packages/patrol_cli/lib/src/commands/doctor.dart index 5930d2ff3..577158473 100644 --- a/packages/patrol_cli/lib/src/commands/doctor.dart +++ b/packages/patrol_cli/lib/src/commands/doctor.dart @@ -52,7 +52,6 @@ class DoctorCommand extends PatrolCommand { void _printIosSpecifics() { _checkIfToolInstalled('xcodebuild'); _checkIfToolInstalled('ideviceinstaller', 'brew install ideviceinstaller'); - _checkIfToolInstalled('ios-deploy', 'brew install ios-deploy'); } void _checkIfToolInstalled(String tool, [String? hint]) { diff --git a/packages/patrol_cli/lib/src/ios/ios_deploy.dart b/packages/patrol_cli/lib/src/ios/ios_deploy.dart deleted file mode 100644 index e4c16d048..000000000 --- a/packages/patrol_cli/lib/src/ios/ios_deploy.dart +++ /dev/null @@ -1,84 +0,0 @@ -import 'dart:io'; - -import 'package:dispose_scope/dispose_scope.dart'; -import 'package:file/file.dart'; -import 'package:patrol_cli/src/base/logger.dart'; -import 'package:patrol_cli/src/base/process.dart'; -import 'package:process/process.dart'; - -class IOSDeploy { - IOSDeploy({ - required ProcessManager processManager, - required FileSystem fs, - required DisposeScope parentDisposeScope, - required Logger logger, - }) : _processManager = processManager, - _fs = fs, - _disposeScope = DisposeScope(), - _logger = logger { - _disposeScope.disposedBy(parentDisposeScope); - } - - final ProcessManager _processManager; - final FileSystem _fs; - final DisposeScope _disposeScope; - final Logger _logger; - - /// Installs and launches the app on physical iOS device with [deviceId]. - /// - /// To kill the app, send `kill` to the returned [Process]'s stdin. - Future installAndLaunch(String deviceId) async { - final process = await _processManager.start( - [ - 'ios-deploy', - ...['--id', deviceId], - ...[ - '--bundle', - '../build/ios_integ/Build/Products/Debug-iphoneos/Runner.app' - ], - // TODO: Enable deltas (https://github.com/leancodepl/patrol/issues/871) - // ...['--app_deltas', '../build/ios_integ/Runner-delta'], - '--debug', - '--no-wifi', - ...[ - '--args', - '--enable-dart-profiling --enable-checked-mode --verify-entry-points' - ], - ], - runInShell: true, - workingDirectory: _fs.currentDirectory.childDirectory('ios').path, - ) - ..disposedBy(_disposeScope); - - var launchSucceeded = false; - - process.listenStdOut((line) { - if (line == 'success') { - launchSucceeded = true; - } - }).disposedBy(_disposeScope); - - var totalTimeElapsed = Duration.zero; - while (!launchSucceeded) { - if (_disposeScope.disposed) { - _logger.detail( - 'Stopped waiting for ios-deploy becuase dispose scope was closed', - ); - break; - } - - const delta = Duration(milliseconds: 100); - await Future.delayed(delta); - totalTimeElapsed += delta; - - final millisecondsElapsed = totalTimeElapsed.inMilliseconds; - if (millisecondsElapsed > 1 && millisecondsElapsed % (30 * 1000) == 0) { - _logger.warn( - 'Waiting for ios-deploy to launch the app is taking unusually long time (${millisecondsElapsed / 1000}s)', - ); - } - } - _logger.detail('ios-deploy successfully launched the app'); - return process; - } -} diff --git a/packages/patrol_cli/lib/src/ios/ios_test_backend.dart b/packages/patrol_cli/lib/src/ios/ios_test_backend.dart index 9d71b304d..26252e915 100644 --- a/packages/patrol_cli/lib/src/ios/ios_test_backend.dart +++ b/packages/patrol_cli/lib/src/ios/ios_test_backend.dart @@ -10,7 +10,6 @@ import 'package:patrol_cli/src/base/logger.dart'; import 'package:patrol_cli/src/base/process.dart'; import 'package:patrol_cli/src/crossplatform/app_options.dart'; import 'package:patrol_cli/src/devices.dart'; -import 'package:patrol_cli/src/ios/ios_deploy.dart'; import 'package:process/process.dart'; enum BuildMode { @@ -48,12 +47,10 @@ class IOSTestBackend { IOSTestBackend({ required ProcessManager processManager, required FileSystem fs, - required IOSDeploy iosDeploy, required DisposeScope parentDisposeScope, required Logger logger, }) : _processManager = processManager, _fs = fs, - _iosDeploy = iosDeploy, _disposeScope = DisposeScope(), _logger = logger { _disposeScope.disposedBy(parentDisposeScope); @@ -63,7 +60,6 @@ class IOSTestBackend { final ProcessManager _processManager; final FileSystem _fs; - final IOSDeploy _iosDeploy; final DisposeScope _disposeScope; final Logger _logger; @@ -76,6 +72,14 @@ class IOSTestBackend { Process process; + final isRealDevice = !options.simulator; + final isReleaseMode = options.flutter.buildMode == BuildMode.release; + if (isRealDevice && !isReleaseMode) { + throwToolExit( + 'Running on physical iOS devices is possible only in release mode', + ); + } + // flutter build ios --config-only var flutterBuildKilled = false; @@ -140,12 +144,6 @@ class IOSTestBackend { final subject = '${options.description} on ${device.description}'; final task = _logger.task('Running $subject'); - Process? iosDeployProcess; - if (device.real) { - _logger.detail('Executing on physical iOS device using ios-deploy...'); - iosDeployProcess = await _iosDeploy.installAndLaunch(device.id); - } - final sdkVersion = await getSdkVersion(real: device.real); final process = await _processManager.start( options.testWithoutBuildingInvocation( @@ -164,9 +162,6 @@ class IOSTestBackend { process.listenStdErr((l) => _logger.err('\t$l')).disposedBy(scope); final exitCode = await process.exitCode; - // Tests have finished now, kill the app under test - iosDeployProcess?.stdin.writeln('kill'); - iosDeployProcess?.kill(); // kill it with fire if (exitCode == 0) { task.complete('Completed executing $subject'); diff --git a/packages/patrol_cli/lib/src/runner/patrol_command_runner.dart b/packages/patrol_cli/lib/src/runner/patrol_command_runner.dart index 2531fa6ec..9dc85514a 100644 --- a/packages/patrol_cli/lib/src/runner/patrol_command_runner.dart +++ b/packages/patrol_cli/lib/src/runner/patrol_command_runner.dart @@ -22,7 +22,6 @@ import 'package:patrol_cli/src/commands/update.dart'; import 'package:patrol_cli/src/crossplatform/flutter_tool.dart'; import 'package:patrol_cli/src/dart_defines_reader.dart'; import 'package:patrol_cli/src/devices.dart'; -import 'package:patrol_cli/src/ios/ios_deploy.dart'; import 'package:patrol_cli/src/ios/ios_test_backend.dart'; import 'package:patrol_cli/src/pubspec_reader.dart'; import 'package:patrol_cli/src/test_bundler.dart'; @@ -106,12 +105,6 @@ class PatrolCommandRunner extends CompletionCommandRunner { final iosTestBackend = IOSTestBackend( processManager: _processManager, fs: _fs, - iosDeploy: IOSDeploy( - processManager: _processManager, - parentDisposeScope: _disposeScope, - fs: _fs, - logger: _logger, - ), parentDisposeScope: _disposeScope, logger: _logger, ); diff --git a/packages/patrol_cli/test/ios/ios_test_backend_test.dart b/packages/patrol_cli/test/ios/ios_test_backend_test.dart index 47f0712f8..6e6642ba7 100644 --- a/packages/patrol_cli/test/ios/ios_test_backend_test.dart +++ b/packages/patrol_cli/test/ios/ios_test_backend_test.dart @@ -4,7 +4,6 @@ import 'package:file/memory.dart'; import 'package:meta/meta.dart'; import 'package:mocktail/mocktail.dart'; import 'package:patrol_cli/src/base/logger.dart'; -import 'package:patrol_cli/src/ios/ios_deploy.dart'; import 'package:patrol_cli/src/ios/ios_test_backend.dart'; import 'package:process/process.dart'; import 'package:test/test.dart'; @@ -56,7 +55,6 @@ void main() { iosTestBackend = IOSTestBackend( processManager: FakeProcessManager(), fs: fs, - iosDeploy: FakeIOSDeploy(), parentDisposeScope: DisposeScope(), logger: FakeLogger(), ); @@ -169,8 +167,6 @@ void main() { class FakeProcessManager extends Fake implements ProcessManager {} -class FakeIOSDeploy extends Fake implements IOSDeploy {} - class FakeLogger extends Fake implements Logger { @override void detail(String? message) {}