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.
This commit is contained in:
Andrew Kolos 2024-02-16 14:21:08 -08:00 committed by GitHub
parent 1b8742b9dc
commit 9a6bda87d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View file

@ -620,7 +620,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
return true;
}
for (final DevFSFileContent entry in entries.values.whereType<DevFSFileContent>()) {
final Iterable<DevFSFileContent> files = entries.values
.map((AssetBundleEntry asset) => asset.content)
.whereType<DevFSFileContent>();
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)) {

View file

@ -955,6 +955,41 @@ dev_dependencies:
DeviceManager: () => _FakeDeviceManager(<Device>[]),
});
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<void> commandRunner = createTestCommandRunner(testCommand);
await commandRunner.run(const <String>[
'test',
'--no-pub',
]);
fs.file('asset.txt').writeAsStringSync('2');
await commandRunner.run(const <String>[
'test',
'--no-pub',
]);
final String fileContent = fs.file(globals.fs.path.join('build', 'unit_test_assets', 'asset.txt')).readAsStringSync();
expect(fileContent, '2');
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.empty(),
DeviceManager: () => _FakeDeviceManager(<Device>[]),
});
group('Fatal Logs', () {
testUsingContext("doesn't fail when --fatal-warnings is set and no warning output", () async {
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);