-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Flutter driver allows authoring test_driver/ scripts that are effectively plain Dart VM (main()) scripts.
flutter drive lib/main.dartFor example, in the following app structure:
lib
|- main.dart
test_driver
|- main_test.dartThe file test_driver/main_test.dart might look like this:
void main() async {
late final FlutterDriver flutterDriver;
late final NativeDriver nativeDriver;
setUpAll(() async {
flutterDriver = await FlutterDriver.connect();
});
// ...
}The way FlutterDriver.connect() works, it passes VM_SERVICE_URL as an environment variable, which is scraped and provided by the tool (i.e. the command flutter drive). But what if you want to pass your own environment variable, such as a server to connect to?
SERVER_URL=https://some-test.dev flutter drive lib/main.dartToday, this does not work - we (accidentally?) ignore and provide a blank parent environment:
| <String, String>{}, |
At least one unit test seems to imply we intended to provide user-authored environment variables:
flutter/packages/flutter_tools/test/general.shard/drive/drive_service_test.dart
Lines 125 to 160 in 864d4f5
| testWithoutContext('Connects to device VM Service and runs test application', () 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'], | |
| 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(vmServiceUri: Uri.parse('http://127.0.0.1:63426/1UasC_ihpXY=/')), | |
| ); | |
| await driverService.start( | |
| BuildInfo.profile, | |
| device, | |
| DebuggingOptions.enabled(BuildInfo.profile, ipv6: true), | |
| ); | |
| final int testResult = await driverService.startTest( | |
| 'foo.test', | |
| <String>['--enable-experiment=non-nullable'], | |
| <String, String>{'FOO': 'BAR'}, | |
| PackageConfig(<Package>[Package('test', Uri.base)]), | |
| ); | |
| expect(testResult, 23); | |
| }); |
I'd like to propose "fixing" this.