Android e2e screenshot (#84472)
This commit is contained in:
@@ -48,6 +48,26 @@ class MatchesGoldenFile extends AsyncMatcher {
|
||||
|
||||
@override
|
||||
Future<String?> matchAsync(dynamic item) async {
|
||||
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
|
||||
|
||||
Uint8List? buffer;
|
||||
if (item is Future<List<int>>) {
|
||||
buffer = Uint8List.fromList(await item);
|
||||
} else if (item is List<int>) {
|
||||
buffer = Uint8List.fromList(item);
|
||||
}
|
||||
if (buffer != null) {
|
||||
if (autoUpdateGoldenFiles) {
|
||||
await goldenFileComparator.update(testNameUri, buffer);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final bool success = await goldenFileComparator.compare(buffer, testNameUri);
|
||||
return success ? null : 'does not match';
|
||||
} on TestFailure catch (ex) {
|
||||
return ex.message;
|
||||
}
|
||||
}
|
||||
Future<ui.Image?> imageFuture;
|
||||
if (item is Future<ui.Image?>) {
|
||||
imageFuture = item;
|
||||
@@ -62,11 +82,9 @@ class MatchesGoldenFile extends AsyncMatcher {
|
||||
}
|
||||
imageFuture = captureImage(elements.single);
|
||||
} else {
|
||||
throw 'must provide a Finder, Image, or Future<Image>';
|
||||
throw 'must provide a Finder, Image, Future<Image>, List<int>, or Future<List<int>>';
|
||||
}
|
||||
|
||||
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
|
||||
|
||||
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
|
||||
return binding.runAsync<String?>(() async {
|
||||
final ui.Image? image = await imageFuture;
|
||||
|
||||
@@ -352,7 +352,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('matches', () {
|
||||
|
||||
testWidgets('if comparator succeeds', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(boilerplate(const Text('hello')));
|
||||
final Finder finder = find.byType(Text);
|
||||
@@ -361,6 +360,20 @@ void main() {
|
||||
expect(comparator.imageBytes, hasLength(greaterThan(0)));
|
||||
expect(comparator.golden, Uri.parse('foo.png'));
|
||||
});
|
||||
|
||||
testWidgets('list of integers', (WidgetTester tester) async {
|
||||
await expectLater(<int>[1, 2], matchesGoldenFile('foo.png'));
|
||||
expect(comparator.invocation, _ComparatorInvocation.compare);
|
||||
expect(comparator.imageBytes, equals(<int>[1, 2]));
|
||||
expect(comparator.golden, Uri.parse('foo.png'));
|
||||
});
|
||||
|
||||
testWidgets('future list of integers', (WidgetTester tester) async {
|
||||
await expectLater(Future<List<int>>.value(<int>[1, 2]), matchesGoldenFile('foo.png'));
|
||||
expect(comparator.invocation, _ComparatorInvocation.compare);
|
||||
expect(comparator.imageBytes, equals(<int>[1, 2]));
|
||||
expect(comparator.golden, Uri.parse('foo.png'));
|
||||
});
|
||||
});
|
||||
|
||||
group('does not match', () {
|
||||
|
||||
Reference in New Issue
Block a user