fix 31511: Test performance has regressed (#31582)
This commit is contained in:
@@ -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<String, DevFSContent> 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<DevFSFileContent>()) {
|
||||
// Calling isModified to access file stats first in order for isModifiedAfter
|
||||
// to work.
|
||||
if (entry.isModified && entry.isModifiedAfter(lastModified)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user