mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Deflake wildcard asset test (#42597)
This commit is contained in:
parent
e7ffac2d67
commit
04e04ffa95
@ -91,12 +91,17 @@ class _ManifestAssetBundle implements AssetBundle {
|
||||
}
|
||||
|
||||
for (Directory directory in _wildcardDirectories.values) {
|
||||
final DateTime dateTime = directory.statSync().modified;
|
||||
if (dateTime == null) {
|
||||
continue;
|
||||
if (!directory.existsSync()) {
|
||||
return true; // directory was deleted.
|
||||
}
|
||||
if (dateTime.isAfter(_lastBuildTimestamp)) {
|
||||
return true;
|
||||
for (File file in directory.listSync()) {
|
||||
final DateTime dateTime = file.statSync().modified;
|
||||
if (dateTime == null) {
|
||||
continue;
|
||||
}
|
||||
if (dateTime.isAfter(_lastBuildTimestamp)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('wildcard directories are updated when filesystem changes', () async {
|
||||
fs.file('.packages').createSync();
|
||||
final File packageFile = fs.file('.packages')..createSync();
|
||||
fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
|
||||
fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
@ -80,11 +80,10 @@ flutter:
|
||||
expect(bundle.entries.length, 4);
|
||||
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
|
||||
|
||||
// Adding a file should update the stat of the directory, but instead
|
||||
// we need to fully recreate it.
|
||||
fs.directory(fs.path.join('assets', 'foo')).deleteSync(recursive: true);
|
||||
fs.file(fs.path.join('assets', 'foo', 'fizz.txt')).createSync(recursive: true);
|
||||
fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync();
|
||||
// Simulate modifying the files by updating the filestat time manually.
|
||||
fs.file(fs.path.join('assets', 'foo', 'fizz.txt'))
|
||||
..createSync(recursive: true)
|
||||
..setLastModifiedSync(packageFile.lastModifiedSync().add(const Duration(hours: 1)));
|
||||
|
||||
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), true);
|
||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||
@ -102,7 +101,7 @@ flutter:
|
||||
|
||||
testUsingContext('handle removal of wildcard directories', () async {
|
||||
fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
|
||||
fs.file('pubspec.yaml')
|
||||
final File pubspec = fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
@ -122,14 +121,17 @@ flutter:
|
||||
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
|
||||
|
||||
// Delete the wildcard directory and update pubspec file.
|
||||
final DateTime modifiedTime = pubspec.lastModifiedSync().add(const Duration(hours: 1));
|
||||
fs.directory(fs.path.join('assets', 'foo')).deleteSync(recursive: true);
|
||||
fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example''');
|
||||
name: example''')
|
||||
..setLastModifiedSync(modifiedTime);
|
||||
|
||||
// touch .packages to make sure its change time is after pubspec.yaml's
|
||||
fs.file('.packages').createSync();
|
||||
fs.file('.packages')
|
||||
..setLastModifiedSync(modifiedTime);
|
||||
|
||||
// Even though the previous file was removed, it is left in the
|
||||
// asset manifest and not updated. This is due to the devfs not
|
||||
@ -145,7 +147,7 @@ name: example''');
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => testFileSystem,
|
||||
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
|
||||
}, skip: true); // https://github.com/flutter/flutter/issues/34446
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user