Unverified Commit ed5d8718 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] conditionally invoke pub run test for drive scripts based on...

[flutter_tools] conditionally invoke pub run test for drive scripts based on presence of dependency (#69246)

* [flutter_tools] conditionally invoke pub run test for drive scripts based on presence of dependency
parent d0cdfa41
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart';
import '../android/android_device.dart'; import '../android/android_device.dart';
import '../application_package.dart'; import '../application_package.dart';
...@@ -13,6 +14,7 @@ import '../base/common.dart'; ...@@ -13,6 +14,7 @@ import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../dart/package_map.dart';
import '../device.dart'; import '../device.dart';
import '../drive/drive_service.dart'; import '../drive/drive_service.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
...@@ -179,6 +181,11 @@ class DriveCommand extends RunCommandBase { ...@@ -179,6 +181,11 @@ class DriveCommand extends RunCommandBase {
processUtils: globals.processUtils, processUtils: globals.processUtils,
dartSdkPath: globals.artifacts.getArtifactPath(Artifact.engineDartBinary), dartSdkPath: globals.artifacts.getArtifactPath(Artifact.engineDartBinary),
); );
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file('.packages'),
logger: _logger,
throwOnError: false,
) ?? PackageConfig.empty;
final DriverService driverService = _flutterDriverFactory.createDriverService(web); final DriverService driverService = _flutterDriverFactory.createDriverService(web);
final BuildInfo buildInfo = getBuildInfo(); final BuildInfo buildInfo = getBuildInfo();
final DebuggingOptions debuggingOptions = createDebuggingOptions(); final DebuggingOptions debuggingOptions = createDebuggingOptions();
...@@ -220,6 +227,7 @@ class DriveCommand extends RunCommandBase { ...@@ -220,6 +227,7 @@ class DriveCommand extends RunCommandBase {
testFile, testFile,
stringsArg('test-arguments'), stringsArg('test-arguments'),
<String, String>{}, <String, String>{},
packageConfig,
chromeBinary: stringArg('chrome-binary'), chromeBinary: stringArg('chrome-binary'),
headless: boolArg('headless'), headless: boolArg('headless'),
browserDimension: stringArg('browser-dimension').split(','), browserDimension: stringArg('browser-dimension').split(','),
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'package:dds/dds.dart' as dds; import 'package:dds/dds.dart' as dds;
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart';
import 'package:vm_service/vm_service.dart' as vm_service; import 'package:vm_service/vm_service.dart' as vm_service;
import '../application_package.dart'; import '../application_package.dart';
...@@ -77,7 +78,8 @@ abstract class DriverService { ...@@ -77,7 +78,8 @@ abstract class DriverService {
Future<int> startTest( Future<int> startTest(
String testFile, String testFile,
List<String> arguments, List<String> arguments,
Map<String, String> environment, { Map<String, String> environment,
PackageConfig packageConfig, {
bool headless, bool headless,
String chromeBinary, String chromeBinary,
String browserName, String browserName,
...@@ -224,7 +226,8 @@ class FlutterDriverService extends DriverService { ...@@ -224,7 +226,8 @@ class FlutterDriverService extends DriverService {
Future<int> startTest( Future<int> startTest(
String testFile, String testFile,
List<String> arguments, List<String> arguments,
Map<String, String> environment, { Map<String, String> environment,
PackageConfig packageConfig, {
bool headless, bool headless,
String chromeBinary, String chromeBinary,
String browserName, String browserName,
...@@ -232,14 +235,16 @@ class FlutterDriverService extends DriverService { ...@@ -232,14 +235,16 @@ class FlutterDriverService extends DriverService {
int driverPort, int driverPort,
List<String> browserDimension, List<String> browserDimension,
}) async { }) async {
// Check if package:test is available. If not, fall back to invoking
// the test script directly. `pub run test` is strictly better because
// in the even that a socket or something similar is left open, the
// test runner will correctly shutdown the VM instead of hanging forever.
return _processUtils.stream(<String>[ return _processUtils.stream(<String>[
_dartSdkPath, _dartSdkPath,
'pub', if (packageConfig['test'] != null)
'run', ...<String>['pub', 'run', 'test', ...arguments, testFile, '-rexpanded']
'test', else
...arguments, ...<String>[...arguments, testFile, '-rexpanded'],
testFile,
'-rexpanded',
], environment: <String, String>{ ], environment: <String, String>{
'VM_SERVICE_URL': _vmServiceUri, 'VM_SERVICE_URL': _vmServiceUri,
...environment, ...environment,
......
...@@ -7,6 +7,7 @@ import 'dart:math' as math; ...@@ -7,6 +7,7 @@ import 'dart:math' as math;
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
import 'package:webdriver/async_io.dart' as async_io; import 'package:webdriver/async_io.dart' as async_io;
import '../base/common.dart'; import '../base/common.dart';
...@@ -82,7 +83,7 @@ class WebDriverService extends DriverService { ...@@ -82,7 +83,7 @@ class WebDriverService extends DriverService {
} }
@override @override
Future<int> startTest(String testFile, List<String> arguments, Map<String, String> environment, { Future<int> startTest(String testFile, List<String> arguments, Map<String, String> environment, PackageConfig packageConfig, {
bool headless, bool headless,
String chromeBinary, String chromeBinary,
String browserName, String browserName,
......
...@@ -14,6 +14,7 @@ import 'package:flutter_tools/src/device.dart'; ...@@ -14,6 +14,7 @@ import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/drive/drive_service.dart'; import 'package:flutter_tools/src/drive/drive_service.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:package_config/package_config_types.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'package:vm_service/vm_service.dart' as vm_service; import 'package:vm_service/vm_service.dart' as vm_service;
...@@ -168,11 +169,43 @@ void main() { ...@@ -168,11 +169,43 @@ void main() {
'foo.test', 'foo.test',
<String>['--enable-experiment=non-nullable'], <String>['--enable-experiment=non-nullable'],
<String, String>{'FOO': 'BAR'}, <String, String>{'FOO': 'BAR'},
PackageConfig(<Package>[Package('test', Uri.base)]),
); );
expect(testResult, 23); expect(testResult, 23);
}); });
testWithoutContext('Uses dart to execute the test if there is no package:test dependency', () async {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <FakeVmServiceRequest>[
getVM,
]);
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['dart', '--enable-experiment=non-nullable', 'foo.test', '-rexpanded'],
exitCode: 23,
environment: <String, String>{
'FOO': 'BAR',
'VM_SERVICE_URL': 'http://127.0.0.1:1234/' // dds forwarded URI
},
),
]);
final DriverService driverService = setUpDriverService(processManager: processManager, vmService: fakeVmServiceHost.vmService);
final Device device = FakeDevice(LaunchResult.succeeded(
observatoryUri: Uri.parse('http://127.0.0.1:63426/1UasC_ihpXY=/'),
));
await driverService.start(BuildInfo.profile, device, DebuggingOptions.enabled(BuildInfo.profile), true);
final int testResult = await driverService.startTest(
'foo.test',
<String>['--enable-experiment=non-nullable'],
<String, String>{'FOO': 'BAR'},
PackageConfig.empty,
);
expect(testResult, 23);
});
testWithoutContext('Connects to device VM Service and runs test application without dds', () async { testWithoutContext('Connects to device VM Service and runs test application without dds', () async {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <FakeVmServiceRequest>[ final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <FakeVmServiceRequest>[
getVM, getVM,
...@@ -196,6 +229,7 @@ void main() { ...@@ -196,6 +229,7 @@ void main() {
'foo.test', 'foo.test',
<String>[], <String>[],
<String, String>{}, <String, String>{},
PackageConfig(<Package>[Package('test', Uri.base)]),
); );
expect(testResult, 11); expect(testResult, 11);
......
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