diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index aa93bf01cb..ca38c2b980 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -13,6 +13,7 @@ import '../bundle.dart'; import '../cache.dart'; import '../codegen.dart'; import '../dart/pub.dart'; +import '../devfs.dart'; import '../globals.dart'; import '../project.dart'; import '../runner/flutter_command.dart'; @@ -239,7 +240,30 @@ class TestCommand extends FastFlutterCommand { if (build != 0) { throwToolExit('Error: Failed to build asset bundle'); } - await writeBundle(fs.directory(fs.path.join('build', 'unit_test_assets')), assetBundle.entries); + if (_needRebuild(assetBundle.entries)) { + await writeBundle(fs.directory(fs.path.join('build', 'unit_test_assets')), + assetBundle.entries); + } + } + bool _needRebuild(Map entries) { + final File manifest = fs.file(fs.path.join('build', 'unit_test_assets', 'AssetManifest.json')); + if (!manifest.existsSync()) { + return true; + } + final DateTime lastModified = manifest.lastModifiedSync(); + final File pub = fs.file('pubspec.yaml'); + if (pub.lastModifiedSync().isAfter(lastModified)) { + return true; + } + + for (DevFSFileContent entry in entries.values.whereType()) { + // Calling isModified to access file stats first in order for isModifiedAfter + // to work. + if (entry.isModified && entry.isModifiedAfter(lastModified)) { + return true; + } + } + return false; } }