Unverified Commit 857bdc7a authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

Allow FlutterTester to be provided with the working directory for execution (#21119)

* Allow FlutterTester to be provided with the working directory for execution

Previously this test set fs.currentDirectory which prevents running tests concurrently. This allows setting the working directory for a FlutterTester in the cosntructor (optionally) and passes it through from the test (without setting fs.currentDirectory).

* Remove trailing whitespace
parent bae44b29
...@@ -41,8 +41,9 @@ class FlutterTesterApp extends ApplicationPackage { ...@@ -41,8 +41,9 @@ class FlutterTesterApp extends ApplicationPackage {
// TODO(scheglov): This device does not currently work with full restarts. // TODO(scheglov): This device does not currently work with full restarts.
class FlutterTesterDevice extends Device { class FlutterTesterDevice extends Device {
FlutterTesterDevice(String deviceId) : super(deviceId); FlutterTesterDevice(String deviceId, { this.workingDirectory }) : super(deviceId);
final String workingDirectory;
Process _process; Process _process;
final DevicePortForwarder _portForwarder = new _NoopPortForwarder(); final DevicePortForwarder _portForwarder = new _NoopPortForwarder();
...@@ -151,6 +152,7 @@ class FlutterTesterDevice extends Device { ...@@ -151,6 +152,7 @@ class FlutterTesterDevice extends Device {
environment: <String, String>{ environment: <String, String>{
'FLUTTER_TEST': 'true', 'FLUTTER_TEST': 'true',
}, },
workingDirectory: workingDirectory,
); );
// Setting a bool can't fail in the callback. // Setting a bool can't fail in the callback.
_process.exitCode.then((_) => _isRunning = false); // ignore: unawaited_futures _process.exitCode.then((_) => _isRunning = false); // ignore: unawaited_futures
......
...@@ -15,27 +15,20 @@ import '../src/context.dart'; ...@@ -15,27 +15,20 @@ import '../src/context.dart';
import 'test_utils.dart'; import 'test_utils.dart';
void main() { void main() {
group('FlutterTesterDevice', () {
Directory tempDir; Directory tempDir;
Directory oldCurrentDir; FlutterTesterDevice device;
setUp(() async { setUp(() async {
tempDir = fs.systemTempDirectory.createTempSync('flutter_tester_device_test.'); tempDir = fs.systemTempDirectory.createTempSync('flutter_tester_device_test.');
oldCurrentDir = fs.currentDirectory; device = new FlutterTesterDevice('flutter-tester', workingDirectory: tempDir.path);
fs.currentDirectory = tempDir;
}); });
tearDown(() { tearDown(() {
fs.currentDirectory = oldCurrentDir;
tryToDelete(tempDir); tryToDelete(tempDir);
}); });
group('FlutterTesterDevice', () {
FlutterTesterDevice device;
setUp(() {
device = new FlutterTesterDevice('flutter-tester');
});
Future<LaunchResult> start(String mainPath) async { Future<LaunchResult> start(String mainPath) async {
return await device.startApp( return await device.startApp(
null, null,
...@@ -50,7 +43,7 @@ void main() { ...@@ -50,7 +43,7 @@ void main() {
writePubspec(tempDir.path); writePubspec(tempDir.path);
writePackages(tempDir.path); writePackages(tempDir.path);
final String mainPath = fs.path.join('lib', 'main.dart'); final String mainPath = fs.path.join(tempDir.path, 'lib', 'main.dart');
writeFile(mainPath, r''' writeFile(mainPath, r'''
import 'dart:async'; import 'dart:async';
void main() { void main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment