Unverified Commit 04e04ffa authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Deflake wildcard asset test (#42597)

parent e7ffac2d
...@@ -91,12 +91,17 @@ class _ManifestAssetBundle implements AssetBundle { ...@@ -91,12 +91,17 @@ class _ManifestAssetBundle implements AssetBundle {
} }
for (Directory directory in _wildcardDirectories.values) { for (Directory directory in _wildcardDirectories.values) {
final DateTime dateTime = directory.statSync().modified; if (!directory.existsSync()) {
if (dateTime == null) { return true; // directory was deleted.
continue;
} }
if (dateTime.isAfter(_lastBuildTimestamp)) { for (File file in directory.listSync()) {
return true; final DateTime dateTime = file.statSync().modified;
if (dateTime == null) {
continue;
}
if (dateTime.isAfter(_lastBuildTimestamp)) {
return true;
}
} }
} }
......
...@@ -60,7 +60,7 @@ void main() { ...@@ -60,7 +60,7 @@ void main() {
}); });
testUsingContext('wildcard directories are updated when filesystem changes', () async { 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(fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
fs.file('pubspec.yaml') fs.file('pubspec.yaml')
..createSync() ..createSync()
...@@ -80,11 +80,10 @@ flutter: ...@@ -80,11 +80,10 @@ flutter:
expect(bundle.entries.length, 4); expect(bundle.entries.length, 4);
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false); expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
// Adding a file should update the stat of the directory, but instead // Simulate modifying the files by updating the filestat time manually.
// we need to fully recreate it. fs.file(fs.path.join('assets', 'foo', 'fizz.txt'))
fs.directory(fs.path.join('assets', 'foo')).deleteSync(recursive: true); ..createSync(recursive: true)
fs.file(fs.path.join('assets', 'foo', 'fizz.txt')).createSync(recursive: true); ..setLastModifiedSync(packageFile.lastModifiedSync().add(const Duration(hours: 1)));
fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync();
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), true); expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), true);
await bundle.build(manifestPath: 'pubspec.yaml'); await bundle.build(manifestPath: 'pubspec.yaml');
...@@ -102,7 +101,7 @@ flutter: ...@@ -102,7 +101,7 @@ flutter:
testUsingContext('handle removal of wildcard directories', () async { testUsingContext('handle removal of wildcard directories', () async {
fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true); fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
fs.file('pubspec.yaml') final File pubspec = fs.file('pubspec.yaml')
..createSync() ..createSync()
..writeAsStringSync(r''' ..writeAsStringSync(r'''
name: example name: example
...@@ -122,14 +121,17 @@ flutter: ...@@ -122,14 +121,17 @@ flutter:
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false); expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
// Delete the wildcard directory and update pubspec file. // 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.directory(fs.path.join('assets', 'foo')).deleteSync(recursive: true);
fs.file('pubspec.yaml') fs.file('pubspec.yaml')
..createSync() ..createSync()
..writeAsStringSync(r''' ..writeAsStringSync(r'''
name: example'''); name: example''')
..setLastModifiedSync(modifiedTime);
// touch .packages to make sure its change time is after pubspec.yaml's // 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 // Even though the previous file was removed, it is left in the
// asset manifest and not updated. This is due to the devfs not // asset manifest and not updated. This is due to the devfs not
...@@ -145,7 +147,7 @@ name: example'''); ...@@ -145,7 +147,7 @@ name: example''');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => testFileSystem, FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager(<FakeCommand>[]), ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
}, skip: true); // https://github.com/flutter/flutter/issues/34446 });
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment