-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
ManifestAssetBundle accepts dependencies via its constructor to allow for hermetic testing of its behavior:
flutter/packages/flutter_tools/lib/src/asset.dart
Lines 134 to 139 in 0833929
| ManifestAssetBundle({ | |
| required Logger logger, | |
| required FileSystem fileSystem, | |
| required Platform platform, | |
| bool splitDeferredAssets = false, | |
| }) : _logger = logger, |
However, we refer to the global Cache.flutterRoot in a couple places throughout the code:
| Cache.flutterRoot!, |
flutter/packages/flutter_tools/lib/src/asset.dart
Lines 576 to 579 in 0833929
| final String shaderPath = _fileSystem.path.join( | |
| Cache.flutterRoot!, | |
| 'packages', 'flutter', 'lib', 'src', 'material', 'shaders', | |
| ); |
This means that tools test using testWithoutContext have to remember to manually set this global. Example:
flutter/packages/flutter_tools/test/general.shard/asset_bundle_test.dart
Lines 382 to 389 in 0833929
| late String? previousCacheFlutterRootValue; | |
| setUp(() { | |
| previousCacheFlutterRootValue = Cache.flutterRoot; | |
| Cache.flutterRoot = Cache.defaultFlutterRoot(platform: platform, fileSystem: testFileSystem, userMessages: UserMessages()); | |
| }); | |
| tearDown(() => Cache.flutterRoot = previousCacheFlutterRootValue); |
If nothing worse, this is noisy. Let's consider having ManifestAssetBundle accept the flutter root as a constructor parameter.