Skip to content

Commit 9a6bda8

Browse files
authored
rebuild the asset bundle if a file has been modified between flutter test runs (#143569)
Fixes flutter/flutter#143513 Should be cherry-picked to beta.
1 parent 1b8742b commit 9a6bda8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

packages/flutter_tools/lib/src/commands/test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
620620
return true;
621621
}
622622

623-
for (final DevFSFileContent entry in entries.values.whereType<DevFSFileContent>()) {
623+
final Iterable<DevFSFileContent> files = entries.values
624+
.map((AssetBundleEntry asset) => asset.content)
625+
.whereType<DevFSFileContent>();
626+
for (final DevFSFileContent entry in files) {
624627
// Calling isModified to access file stats first in order for isModifiedAfter
625628
// to work.
626629
if (entry.isModified && entry.isModifiedAfter(lastModified)) {

packages/flutter_tools/test/commands.shard/hermetic/test_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,41 @@ dev_dependencies:
955955
DeviceManager: () => _FakeDeviceManager(<Device>[]),
956956
});
957957

958+
testUsingContext('Rebuild the asset bundle if an asset file has changed since previous build', () async {
959+
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);
960+
fs.file('asset.txt').writeAsStringSync('1');
961+
fs.file('pubspec.yaml').writeAsStringSync('''
962+
flutter:
963+
assets:
964+
- asset.txt
965+
dev_dependencies:
966+
flutter_test:
967+
sdk: flutter
968+
integration_test:
969+
sdk: flutter''');
970+
final TestCommand testCommand = TestCommand(testRunner: testRunner);
971+
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
972+
973+
await commandRunner.run(const <String>[
974+
'test',
975+
'--no-pub',
976+
]);
977+
978+
fs.file('asset.txt').writeAsStringSync('2');
979+
980+
await commandRunner.run(const <String>[
981+
'test',
982+
'--no-pub',
983+
]);
984+
985+
final String fileContent = fs.file(globals.fs.path.join('build', 'unit_test_assets', 'asset.txt')).readAsStringSync();
986+
expect(fileContent, '2');
987+
}, overrides: <Type, Generator>{
988+
FileSystem: () => fs,
989+
ProcessManager: () => FakeProcessManager.empty(),
990+
DeviceManager: () => _FakeDeviceManager(<Device>[]),
991+
});
992+
958993
group('Fatal Logs', () {
959994
testUsingContext("doesn't fail when --fatal-warnings is set and no warning output", () async {
960995
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);

0 commit comments

Comments
 (0)