@@ -503,32 +503,39 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
503503 uninstallApp: boolArg ('uninstall' ),
504504 );
505505
506- final Uri ? nativeAssetsJson = _isIntegrationTest
507- ? null // Don't build for host when running integration tests.
508- : await nativeAssetsBuilder? .build (buildInfo);
506+ final (: Uri ? nativeAssetsManifest, : FlutterHookResult ? flutterHookResult) = _isIntegrationTest
507+ ? (
508+ nativeAssetsManifest: null ,
509+ flutterHookResult: null ,
510+ ) // Don't build for host when running integration tests.
511+ : (await nativeAssetsBuilder? .buildWithHookResult (buildInfo) ??
512+ (nativeAssetsManifest: null , flutterHookResult: null ));
509513 String ? testAssetPath;
510514 if (buildTestAssets) {
511515 await _buildTestAsset (
512516 flavor: buildInfo.flavor,
513517 impellerStatus: debuggingOptions.enableImpeller,
514518 buildMode: debuggingOptions.buildInfo.mode,
515519 packageConfigPath: buildInfo.packageConfigPath,
520+ flutterHookResult: flutterHookResult,
516521 );
517522 }
518- if (buildTestAssets || nativeAssetsJson != null ) {
523+ if (buildTestAssets || nativeAssetsManifest != null ) {
519524 testAssetPath = globals.fs.path.join (
520525 flutterProject.directory.path,
521526 'build' ,
522527 'unit_test_assets' ,
523528 );
524529 }
525- if (nativeAssetsJson != null ) {
530+ if (nativeAssetsManifest != null ) {
526531 final Directory testAssetDirectory = globals.fs.directory (testAssetPath);
527532 if (! testAssetDirectory.existsSync ()) {
528533 await testAssetDirectory.create (recursive: true );
529534 }
530- final File nativeAssetsManifest = testAssetDirectory.childFile ('NativeAssetsManifest.json' );
531- await globals.fs.file (nativeAssetsJson).copy (nativeAssetsManifest.path);
535+ final File copiedNativeAssetsManifest = testAssetDirectory.childFile (
536+ 'NativeAssetsManifest.json' ,
537+ );
538+ await globals.fs.file (nativeAssetsManifest).copy (copiedNativeAssetsManifest.path);
532539 }
533540
534541 final String ? concurrencyString = stringArg ('concurrency' );
@@ -802,9 +809,11 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
802809 required ImpellerStatus impellerStatus,
803810 required BuildMode buildMode,
804811 required String packageConfigPath,
812+ FlutterHookResult ? flutterHookResult,
805813 }) async {
806814 final AssetBundle assetBundle = AssetBundleFactory .instance.createBundle ();
807815 final int build = await assetBundle.build (
816+ flutterHookResult: flutterHookResult,
808817 packageConfigPath: packageConfigPath,
809818 flavor: flavor,
810819 includeAssetsFromDevDependencies: true ,
@@ -813,7 +822,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
813822 if (build != 0 ) {
814823 throwToolExit ('Error: Failed to build asset bundle' );
815824 }
816- if (_needsRebuild (assetBundle.entries, flavor)) {
825+ if (_needsRebuild (assetBundle.entries, flavor, flutterHookResult )) {
817826 await writeBundle (
818827 globals.fs.directory (
819828 globals.fs.path.join (getBuildDirectory (globals.config, globals.fs), 'unit_test_assets' ),
@@ -846,32 +855,46 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
846855 }
847856 }
848857
849- bool _needsRebuild (Map <String , AssetBundleEntry > entries, String ? flavor) {
858+ bool _needsRebuild (
859+ Map <String , AssetBundleEntry > entries,
860+ String ? flavor,
861+ FlutterHookResult ? flutterHookResult,
862+ ) {
850863 // TODO(andrewkolos): This logic might fail in the future if we change the
851864 // schema of the contents of the asset manifest file and the user does not
852865 // perform a `flutter clean` after upgrading.
853866 // See https://github.com/flutter/flutter/issues/128563.
867+ final String unitTestAssetsDir = globals.fs.path.join (
868+ getBuildDirectory (globals.config, globals.fs),
869+ 'unit_test_assets' ,
870+ );
854871 final File manifest = globals.fs.file (
855- globals.fs.path.join (
856- getBuildDirectory (globals.config, globals.fs),
857- 'unit_test_assets' ,
858- 'AssetManifest.bin' ,
859- ),
872+ globals.fs.path.join (unitTestAssetsDir, 'AssetManifest.bin' ),
860873 );
861874 if (! manifest.existsSync ()) {
862875 return true ;
863876 }
864877 final DateTime lastModified = manifest.lastModifiedSync ();
865878 final File pub = globals.fs.file ('pubspec.yaml' );
866- if (pub.lastModifiedSync ().isAfter (lastModified)) {
879+ if (pub.existsSync () && pub. lastModifiedSync ().isAfter (lastModified)) {
867880 return true ;
868881 }
869882
870- final Iterable <DevFSFileContent > files = entries.values
871- .map ((AssetBundleEntry asset) => asset.content)
872- .whereType <DevFSFileContent >();
873- for (final entry in files) {
874- if (entry.isModifiedAfter (lastModified)) {
883+ for (final MapEntry <String , AssetBundleEntry > entry in entries.entries) {
884+ final DevFSContent content = entry.value.content;
885+ if (content is DevFSFileContent ) {
886+ if (! globals.fs.file (globals.fs.path.join (unitTestAssetsDir, entry.key)).existsSync ()) {
887+ return true ;
888+ }
889+ if (content.isModifiedAfter (lastModified)) {
890+ return true ;
891+ }
892+ }
893+ }
894+
895+ for (final Uri dependency in flutterHookResult? .dependencies ?? const < Uri > []) {
896+ final File depFile = globals.fs.file (dependency);
897+ if (depFile.existsSync () && depFile.lastModifiedSync ().isAfter (lastModified)) {
875898 return true ;
876899 }
877900 }
0 commit comments