From 9a6bda87d98ff0dbd6901dd53d7b04c728accec1 Mon Sep 17 00:00:00 2001 From: Andrew Kolos Date: Fri, 16 Feb 2024 14:21:08 -0800 Subject: [PATCH] rebuild the asset bundle if a file has been modified between `flutter test` runs (#143569) Fixes https://github.com/flutter/flutter/issues/143513 Should be cherry-picked to beta. --- .../flutter_tools/lib/src/commands/test.dart | 5 ++- .../commands.shard/hermetic/test_test.dart | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index 01e0a447ef84..056eed56aa10 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -620,7 +620,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { return true; } - for (final DevFSFileContent entry in entries.values.whereType()) { + final Iterable files = entries.values + .map((AssetBundleEntry asset) => asset.content) + .whereType(); + for (final DevFSFileContent entry in files) { // Calling isModified to access file stats first in order for isModifiedAfter // to work. if (entry.isModified && entry.isModifiedAfter(lastModified)) { diff --git a/packages/flutter_tools/test/commands.shard/hermetic/test_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/test_test.dart index 212f051b3a05..b5cd1a41b7bc 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/test_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/test_test.dart @@ -955,6 +955,41 @@ dev_dependencies: DeviceManager: () => _FakeDeviceManager([]), }); + testUsingContext('Rebuild the asset bundle if an asset file has changed since previous build', () async { + final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0); + fs.file('asset.txt').writeAsStringSync('1'); + fs.file('pubspec.yaml').writeAsStringSync(''' +flutter: + assets: + - asset.txt +dev_dependencies: + flutter_test: + sdk: flutter + integration_test: + sdk: flutter'''); + final TestCommand testCommand = TestCommand(testRunner: testRunner); + final CommandRunner commandRunner = createTestCommandRunner(testCommand); + + await commandRunner.run(const [ + 'test', + '--no-pub', + ]); + + fs.file('asset.txt').writeAsStringSync('2'); + + await commandRunner.run(const [ + 'test', + '--no-pub', + ]); + + final String fileContent = fs.file(globals.fs.path.join('build', 'unit_test_assets', 'asset.txt')).readAsStringSync(); + expect(fileContent, '2'); + }, overrides: { + FileSystem: () => fs, + ProcessManager: () => FakeProcessManager.empty(), + DeviceManager: () => _FakeDeviceManager([]), + }); + group('Fatal Logs', () { testUsingContext("doesn't fail when --fatal-warnings is set and no warning output", () async { final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);