Skip to content

Commit

Permalink
rebuild the asset bundle if a file has been modified between `flutter…
Browse files Browse the repository at this point in the history
… test` runs (#143569)

Fixes flutter/flutter#143513
Should be cherry-picked to beta.
  • Loading branch information
andrewkolos authored Feb 16, 2024
1 parent 1b8742b commit 9a6bda8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/flutter_tools/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
35 changes: 35 additions & 0 deletions packages/flutter_tools/test/commands.shard/hermetic/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9a6bda8

Please sign in to comment.