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 @@
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart';
import '../android/android_device.dart';
import '../application_package.dart';
......@@ -13,6 +14,7 @@ import '../base/common.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
import '../build_info.dart';
import '../dart/package_map.dart';
import '../device.dart';
import '../drive/drive_service.dart';
import '../globals.dart' as globals;
......@@ -178,7 +180,12 @@ class DriveCommand extends RunCommandBase {
logger: _logger,
processUtils: globals.processUtils,
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 BuildInfo buildInfo = getBuildInfo();
final DebuggingOptions debuggingOptions = createDebuggingOptions();
......@@ -220,6 +227,7 @@ class DriveCommand extends RunCommandBase {
testFile,
stringsArg('test-arguments'),
<String, String>{},
packageConfig,
chromeBinary: stringArg('chrome-binary'),
headless: boolArg('headless'),
browserDimension: stringArg('browser-dimension').split(','),
......
......@@ -5,6 +5,7 @@
import 'package:dds/dds.dart' as dds;
import 'package:file/file.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 '../application_package.dart';
......@@ -77,7 +78,8 @@ abstract class DriverService {
Future<int> startTest(
String testFile,
List<String> arguments,
Map<String, String> environment, {
Map<String, String> environment,
PackageConfig packageConfig, {
bool headless,
String chromeBinary,
String browserName,
......@@ -224,7 +226,8 @@ class FlutterDriverService extends DriverService {
Future<int> startTest(
String testFile,
List<String> arguments,
Map<String, String> environment, {
Map<String, String> environment,
PackageConfig packageConfig, {
bool headless,
String chromeBinary,
String browserName,
......@@ -232,14 +235,16 @@ class FlutterDriverService extends DriverService {
int driverPort,
List<String> browserDimension,
}) 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>[
_dartSdkPath,
'pub',
'run',
'test',
...arguments,
testFile,
'-rexpanded',
if (packageConfig['test'] != null)
...<String>['pub', 'run', 'test', ...arguments, testFile, '-rexpanded']
else
...<String>[...arguments, testFile, '-rexpanded'],
], environment: <String, String>{
'VM_SERVICE_URL': _vmServiceUri,
...environment,
......
......@@ -7,6 +7,7 @@ import 'dart:math' as math;
import 'package:file/file.dart';
import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
import 'package:webdriver/async_io.dart' as async_io;
import '../base/common.dart';
......@@ -82,7 +83,7 @@ class WebDriverService extends DriverService {
}
@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,
String chromeBinary,
String browserName,
......
......@@ -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/vmservice.dart';
import 'package:mockito/mockito.dart';
import 'package:package_config/package_config_types.dart';
import 'package:process/process.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
......@@ -168,11 +169,43 @@ void main() {
'foo.test',
<String>['--enable-experiment=non-nullable'],
<String, String>{'FOO': 'BAR'},
PackageConfig(<Package>[Package('test', Uri.base)]),
);
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 {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <FakeVmServiceRequest>[
getVM,
......@@ -196,6 +229,7 @@ void main() {
'foo.test',
<String>[],
<String, String>{},
PackageConfig(<Package>[Package('test', Uri.base)]),
);
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