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

Deflake wildcard asset test (#42597)

parent e7ffac2d
......@@ -91,7 +91,11 @@ class _ManifestAssetBundle implements AssetBundle {
}
for (Directory directory in _wildcardDirectories.values) {
final DateTime dateTime = directory.statSync().modified;
if (!directory.existsSync()) {
return true; // directory was deleted.
}
for (File file in directory.listSync()) {
final DateTime dateTime = file.statSync().modified;
if (dateTime == null) {
continue;
}
......@@ -99,6 +103,7 @@ class _ManifestAssetBundle implements AssetBundle {
return true;
}
}
}
return stat.modified.isAfter(_lastBuildTimestamp);
}
......
......@@ -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
});
});
}
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