add missing test case and handle wildcard removal (#30205)

This commit is contained in:
Jonah Williams 2019-03-29 14:26:56 -07:00 committed by GitHub
parent 6b2e939480
commit 8220f8f4e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 1 deletions

View file

@ -88,7 +88,11 @@ class _ManifestAssetBundle implements AssetBundle {
return true;
for (Directory directory in _wildcardDirectories.values) {
if (directory.statSync().modified.isAfter(_lastBuildTimestamp)) {
final DateTime dateTime = directory.statSync().modified;
if (dateTime == null) {
continue;
}
if (dateTime.isAfter(_lastBuildTimestamp)) {
return true;
}
}

View file

@ -96,6 +96,49 @@ flutter:
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
testUsingContext('handle removal of wildcard directories', () async {
fs.file('.packages').createSync();
fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example
flutter:
assets:
- assets/foo/
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
// Expected assets:
// - asset manifest
// - font manifest
// - license file
// - assets/foo/bar.txt
expect(bundle.entries.length, 4);
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
// Delete the wildcard directory and update pubspec file.
fs.directory(fs.path.join('assets', 'foo')).deleteSync(recursive: true);
fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example''');
// Even though the previous file was removed, it is left in the
// asset manifest and not updated. This is due to the devfs not
// supporting file deletion.
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), true);
await bundle.build(manifestPath: 'pubspec.yaml');
// Expected assets:
// - asset manifest
// - font manifest
// - license file
// - assets/foo/bar.txt
expect(bundle.entries.length, 4);
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
});
}