Skip to content

Environment is not propagated with FOO=1 flutter drive lib/main.dart #161449

@matanlurey

Description

@matanlurey

Flutter driver allows authoring test_driver/ scripts that are effectively plain Dart VM (main()) scripts.

flutter drive lib/main.dart

For example, in the following app structure:

lib
 |- main.dart
test_driver
 |- main_test.dart

The 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.dart

Today, this does not work - we (accidentally?) ignore and provide a blank parent environment:

At least one unit test seems to imply we intended to provide user-authored environment variables:

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.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testst: flutter driver"flutter driver", flutter_drive, or a driver testteam-toolOwned by Flutter Tool team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions