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

Fixes https://github.com/flutter/flutter/issues/140932
This commit is contained in:
Andrew Kolos
2024-01-05 13:47:55 -08:00
committed by GitHub
parent 1a8de105cf
commit 8c11aa030d
2 changed files with 47 additions and 3 deletions

View File

@@ -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');
}