[flutter_markdown] add AssetManifest.bin to TestAssetBundle (#3422)

[flutter_markdown] add AssetManifest.bin to TestAssetBundle
This commit is contained in:
Andrew Kolos
2023-03-08 20:54:02 +00:00
committed by GitHub
parent 46c6333281
commit 4b0386645f
2 changed files with 6 additions and 2 deletions

View File

@ -21,3 +21,4 @@ dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
mockito: ^5.0.0 mockito: ^5.0.0
standard_message_codec: ^0.0.1+3

View File

@ -179,14 +179,17 @@ Widget boilerplate(Widget child) {
} }
class TestAssetBundle extends CachingAssetBundle { class TestAssetBundle extends CachingAssetBundle {
static const String manifest = r'{"assets/logo.png":["assets/logo.png"]}';
@override @override
Future<ByteData> load(String key) async { Future<ByteData> load(String key) async {
if (key == 'AssetManifest.json') { if (key == 'AssetManifest.json') {
const String manifest = r'{"assets/logo.png":["assets/logo.png"]}';
final ByteData asset = final ByteData asset =
ByteData.view(utf8.encoder.convert(manifest).buffer); ByteData.view(utf8.encoder.convert(manifest).buffer);
return Future<ByteData>.value(asset); return Future<ByteData>.value(asset);
} else if (key == 'AssetManifest.bin') {
final ByteData manifest = const StandardMessageCodec().encodeMessage(
<String, List<Object>>{'assets/logo.png': <Object>[]})!;
return Future<ByteData>.value(manifest);
} else if (key == 'assets/logo.png') { } else if (key == 'assets/logo.png') {
// The root directory tests are run from is different for 'flutter test' // The root directory tests are run from is different for 'flutter test'
// verses 'flutter test test/*_test.dart'. Adjust the root directory // verses 'flutter test test/*_test.dart'. Adjust the root directory