Unverified Commit 8c11aa03 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

add flavor-conditional asset bundling support to `flutter test` (#140944)

Fixes https://github.com/flutter/flutter/issues/140932
parent 1a8de105
......@@ -347,7 +347,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
String? testAssetDirectory;
if (buildTestAssets) {
await _buildTestAsset();
await _buildTestAsset(flavor: buildInfo.flavor);
testAssetDirectory = globals.fs.path.
join(flutterProject.directory.path, 'build', 'unit_test_assets');
}
......@@ -563,9 +563,14 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
.replace(query: queryPart.isEmpty ? null : queryPart);
}
Future<void> _buildTestAsset() async {
Future<void> _buildTestAsset({
required String? flavor,
}) async {
final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle();
final int build = await assetBundle.build(packagesPath: '.packages');
final int build = await assetBundle.build(
packagesPath: '.packages',
flavor: flavor,
);
if (build != 0) {
throwToolExit('Error: Failed to build asset bundle');
}
......
......@@ -888,6 +888,45 @@ dev_dependencies:
DeviceManager: () => _FakeDeviceManager(<Device>[]),
});
testUsingContext('builds asset bundle using --flavor', () async {
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);
fs.file('vanilla.txt').writeAsStringSync('vanilla');
fs.file('orange.txt').writeAsStringSync('orange');
fs.file('pubspec.yaml').writeAsStringSync('''
flutter:
assets:
- path: vanilla.txt
flavors:
- vanilla
- path: orange.txt
flavors:
- orange
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter''');
final TestCommand testCommand = TestCommand(testRunner: testRunner);
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
await commandRunner.run(const <String>[
'test',
'--no-pub',
'--flavor',
'vanilla',
]);
final bool vanillaExists = await fs.isFile(globals.fs.path.join('build', 'unit_test_assets', 'vanilla.txt'));
expect(vanillaExists, true, reason: 'vanilla.txt should be bundled');
final bool orangeExists = await fs.isFile(globals.fs.path.join('build', 'unit_test_assets', 'orange.txt'));
expect(orangeExists, false, reason: 'orange.txt should not be bundled');
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
DeviceManager: () => _FakeDeviceManager(<Device>[]),
});
testUsingContext("Don't build the asset manifest if --no-test-assets if informed", () async {
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);
......
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